1.工作环境无法访问外网,需要一台有外网访问的机器搭建nexus,供其它机器访问maven中央仓库。
2.多人协作的情况下,方便开发人员之间模块的依赖引用,否则就要拷贝所有的模块到每个人的电脑上面。
3.减少直接从中央仓库下载文件的情况,从私服上下载速度会比较快。
wget --no-check-certificate http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz
tar zxf nexus-2.11.2-06-bundle.tar.gz mv nexus-2.11.2-06 /alidata/ mv sonatype-work /alidata/
cd /alidata/nexus-2.11.2-06 cp bin/nexus /etc/init.d/ vim /etc/init.d/nexus #修改NEXUS_HOME的值为绝对路径如:/alidata/nexus-2.11.2-06 #取消RUN_AS_USER=的注释,并修改为RUN_AS_USER="root" #取消PIDDIR="."的注释,并修改为PIDDIR="/var/run" cd /etc/init.d chkconfig --add nexus chkconfig --levels 345 nexus on
service nexus start
显示如下内容则表示启动成功:
**************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** Starting Nexus OSS... Started Nexus OSS.
默认访问端口是8081,可通过修改文件nexus-2.11.2-06/conf/nexus.properties中的application-port=端口进行更改。
service nexus stop #先停止nexus cd /alidata/nexus-2.11.2-06 vim conf/nexus.properties #修改nexus-webapp-context-path=/nexus为nexus-webapp-context-path=/
添加nginx的配置,例子如下
server { listen 80; server_name nexus.example.org; proxy_send_timeout 120; proxy_read_timeout 300; proxy_buffering off; keepalive_timeout 5; tcp_nodelay on; location / { proxy_pass http://127.0.0.1:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
然后启动nexus和nginx
service nexus start service nginx reload
访问浏览器:http://nexus.xxx.xx 则就可以打开刚配置的nexus管理页面,默认用户名密码admin/admin123。
具体页面的配置方式看下篇。