下载安装nexus
首先,下载安装包:https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.20.1-01-unix.tar.gz
wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.20.1-01-unix.tar.gz
解压nexus包到/usr/local
tar zxf nexus-3.20.1-01-unix.tar.gz -C /usr/local/
修改nexus的配置文件,指定jdk的路径
cd /usr/local/nexus-3.20.1-01
vim ./bin/nexus
配置说明:
#修改环境变量
vim /etc/profile
export NEXUS_HOME=/usr/local/nexus-3.20.1-01
export PATH=$PATH:$NEXUS_HOME/bin
source /etc/profile
#修改启动用户
vim /usr/local/nexus-3.20.1-01/bin/nexus.rc
#run_as_user="" #内容就这一行,放开注释,填写用户即可
#修改端口
vim /usr/local/nexus-3.20.1-01/etc/nexus-default.properties #默认是8081
#最后启动nexus
cd /usr/local/nexus-3.20.1-01/bin
./nexus start
./nexus stop
./nexus status
#访问http://ip:8081,登陆用户admin 密码存放在:/usr/local/nexus-3.20.1-01/sonatype-work/nexus3/admin.password 目录
#开机自启动
vim /etc/rc.d/rc.local
/usr/local/nexus-3.20.1-01/bin/nexus start #添加这一行内容
chmod 755 /etc/rc.d/rc.local
启动nexus
启动成功!另外需要注意的是:nexus默认端口为8081,所以要确认云服务已经开启了8081端口,且在防火墙的放行列表中。
将nexus启动命令设置为systemctl命令启动
设置软链接
ln -s /usr/local/nexus-3.20.1-01/bin/nexus /etc/init.d/
cd /etc/init.d/
chkconfig --add nexus
然后通过浏览器输入:服务器IP:8081,如:http://192.168.1.100:8081/
点击右上的:sign in 进行登录,默认账号:admin 默认密码:admin123
登录后可以点击:
输入当前密码,然后点击右下边的按钮,弹出
输入新的账号密码即可。
设置开机自启动
[root@VM_0_11_centos bin]# ln -s /root/nexus-3.9.0/nexus-3.9.0-01/bin/nexus /etc/init.d/nexus3
[root@VM_0_11_centos bin]# chkconfig --add nexus3
[root@VM_0_11_centos bin]# chkconfig nexus3 on
[root@VM_0_11_centos bin]#vim nexus.rc
run_as_user="root"
修改nexus3启动时要使用的jdk版本
[root@VM_0_11_centos bin]# vim nexus
第14行改为:注后面为自己的JDK安装路径。
INSTALL4J_JAVA_HOME_OVERRIDE=/home/java/jdk1.8/jdk1.8.0_161
修改nexus3默认端口(可选)
[root@VM_0_11_centos bin]# cd /root/nexus-3.9.0/nexus-3.9.0-01/etc/
[root@VM_0_11_centos etc]# vi nexus-default.properties
修改 nexus3 数据以及相关日志的存储位置 (可选):
[root@VM_0_11_centos etc]# cd ../bin/
[root@VM_0_11_centos bin]# vi nexus.vmoptions (采取默认即可)
至此, nexus3_maven 的私服就搭建完成了!!!
可以点击上面的 “设置” 图标,在 “设置” 里可以添加用户、角色,对接 LDAP 等的设置,如下:
可以在 “管理” 里查看 nexus 的系统信息
Nexus 的 web 界面功能介绍
1.Browse Server Content
1.1 Search
这个就是类似 Maven 仓库上的搜索功能,就是从私服上查找是否有哪些包。
1)在 Search 这级是支持模糊搜索的,如图所示:
2)如果进入具体的目录,不支持模糊搜索,如图所示:
1.2 Browse
1)Assets
这是能看到所有的资源,包含 Jar,已经对 Jar 的一些描述信息。
2)Components
这里只能看到 Jar 包。
2.Server Adminstration And configuration
看到这个选项的前提是要进行登录的,如上面已经介绍登陆方法,右上角点击 “Sign In” 的登录按钮,输入 admin/admin123, 登录成功之后,即可看到此功能,如图所示:
2.1 Blob Stores
文件存储的地方,创建一个目录的话,对应文件系统的一个目录,如图所示:
2.2 Repositories
1)Proxy
这里就是代理的意思,代理中央 Maven 仓库,当 PC 访问中央库的时候,先通过 Proxy 下载到 Nexus 仓库,然后再从 Nexus 仓库下载到 PC 本地。
这样的优势只要其中一个人从中央库下来了,以后大家都是从 Nexus 私服上进行下来,私服一般部署在内网,这样大大节约的宽带。
创建 Proxy 的具体步骤
1 点击 “Create Repositories” 按钮
2 选择要创建的类型
3 填写详细信息
Name:就是为代理起个名字
Remote Storage: 代理的地址,Maven 的地址为: repo1.maven.org/maven2/
Blob Store: 选择代理下载包的存放路径
2)Hosted
Hosted 是宿主机的意思,就是怎么把第三方的 Jar 放到私服上。
Hosted 有三种方式,Releases、SNAPSHOT、Mixed
Releases: 一般是已经发布的 Jar 包
Snapshot: 未发布的版本
Mixed:混合的
Hosted 的创建和 Proxy 是一致的,具体步骤和上面基本一致。如下:
注意事项:
Deployment Pollcy: 需要把策略改成 “Allow redeploy”。
3)Group
能把两个仓库合成一个仓库来使用,目前没使用过,所以没做详细的研究。
2.3 Security
这里主要是用户、角色、权限的配置(上面已经提到了在这里添加用户和角色等)
2.4 Support
包含日志及数据分析。
私服工作原理:
参考文档:
http://blog.csdn.net/xiaoyu19910321/article/details/78559301
https://baijiahao.baidu.com/s?id=1581440863823080699&wfr=spider&for=pc