准备工作:
环境: Linux
系统: centos6.4-x86-x64
安装工具: nexus-3.14
软件下载: nexus-3.14
官网下载地址: 点击打开链接
将下载的压缩包通过 xft5 上传至 / opt 目录下, 解压至 nexus 目录下, 删除压缩包
- # 将压缩包解压至指定目录下
- tar -zxvf nexus-3.14.0-04-bundle.tar.gz -C /opt/nexus
- rm -rf nexus-3.14.0-04-bundle.tar.gz
备注:
解压后有两个文件夹
nexus-3.14.0-04: 是 nexus 的核心文件
sonatype-work :maven 下载 jar 存放地址
修改配置文件 (修改端口号和 work 目录信息)
- cd /opt/nexus/nexus-3.14.0-04/conf
- vi nexus.properties
- #Jetty section
- application-port=18888
- application-host=0.0.0.0
- nexus-webapp=${
- bundleBasedir
- }/nexus
- nexus-webapp-context-path=/nexus
- # Nexus section
- nexus-work=${
- bundleBasedir
- }/../sonatype-work/nexus
- runtime=${
- bundleBasedir
- }/nexus/Web-INF
启动 nexus(命令方式)
/opt/nexus/nexus-2.14.8-01/bin/nexus start
报: If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
解决方法:
首先到 nexus 安装目录的 bin 下用户修改为 root, 然后 / etc/profile 中添加环境变量
- cd /opt/nexus/nexus-3.14.0-04/bin
- vi /nexus
- RUN_AS_USER=root
- vi /etc/profile
- export RUN_AS_USER=root
使环境变量设置立即生效, 否则重新启动环境后失效
source /etc/profile
重新启动 nexus
/opt/nexus/nexus-3.14.0-04/bin/nexus start
以上该截图表示 nexus 启动成功
配置 nexus 自启动 (可根据需要配置)
- touch /etc/init.d/nexus
- VIM nexus
输入如下内容:
- #!/bin/bash
- #chkconfig:2345 20 90
- #description:nexus
- #processname:nexus
- export JAVA_HOME=/opt/jdk/jdk1.7.0_79
- case $1 in
- start) su root /opt/nexus/nexus-2.14.8-01/bin/nexus start;;
- stop) su root /opt/nexus/nexus-2.14.8-01/bin/nexus stop;;
- status) su root /opt/nexus/nexus-2.14.8-01/bin/nexus status;;
- restart) su root /opt/nexus/nexus-2.14.8-01/bin/nexus restart;;
- dump) su root /opt/nexus/nexus-2.14.8-01/bin/nexus dump ;;
- console) su root /opt/nexus/nexus-2.14.8-01/bin/nexus console ;;
- *) echo "require console | start | stop | restart | status | dump" ;;
- esac
将创建的 / etc/init.d/nexus 文件添加权限, 设置自启动
- # 增加 nexus 服务控制脚本执行权限
- chmod +x /etc/init.d/nexus
- # 通过 chkconfig 命令将 nexus 服务加入到自启动服务中
- chkconfig --add nexus
- # 开启自启动服务
- chkconfig nexus on
- # 查看是否添加成功
- chkconfig --list nexus
注意: java_home 替换成自己的 jdk 安装目录,/opt/nexus/nexus-2.14.8-01 替换成自己 nexus 安装目录
若配置了 nexus 自启动方式则可以使用服务方式启动 nexus
- # 启动 nexus
- service nexus start
- # 停止 nexus
- service nexus stop
- # 重新启动 nexus
- service nexus restart
- # 查看 nexus 状态
- service nexus status
测试客户端是否登录成功
浏览器输入 http://192.168.174.128:18888/nexus
发现登录失败则是因为未设置防火墙对外开放端口
查看是否开启 18888 端口号
netstat -an|grep 18888
配置防火墙开启 nexus18888 端口
方法一: 命令方式
- # 开启防火墙
- chkconnfig iptables on
- # 开启 nexus18888 端口
- iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 18888 -j ACCEPT
- # 保存开启的端口号
- service iptables save
- # 重新启动防火墙
- service iptables restart
方法二: 配置文件方式
- VIM /etc/sysconfig/iptables
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 18888 -j ACCEPT
- # 重新启动防火墙
- service iptables restart
防火墙设置成功后重新启动访问 nexus, 如下截图表示访问 nexus 成功. nexus 默认登录账号: admin/admin123
如何将第三方的 jar 上传至本地私服:
在 Repository 列表中, 选中 3rd party, 选中 artifact upload,
选择 GAV Defini3ion: GAV Parameters,Auto Guess 打钩.
在下方输入 JAR 包对应的 Group,Artifact,Version,Packaging 选择 JAR 格式.
点击 select Artifact(s) to upload 按钮, 选择要上传的 JAR 包.
查看已经上传的 jar 包: 在左侧 "Artifact Search" 输入 "aliyun" 则出现如下截图, 则表示上传成功
配置本地项目引用私服
maven 调用本地私服: 在 pom.xml 中
- nexus
- local private nexus
- http://192.168.174.128:18888/nexus/content/groups/public/
- true
- always
- true
- always
本地 maven 服务器的 setting.xml 中
- releases
- admin
- admin123
- snapshots
- admin
- admin123
补充:
maven 私服 nexus 用户介绍
admin: 该用户拥有 Nexus 的全部权限, 默认密码为 admin123. 则账号: admin/admin123
deployment: 该用户能够访问 Nexus, 浏览仓库内容, 搜索, 上传部署构件, 但是不能对 Nexus 进行任何配置, 默认密码为 deployment123. 则账号: deployment/deployment123
anonymous: 该用户对应了所有未登录的匿名用户, 它们可以浏览仓库并进行搜索.
添加第三方 jar 默认情况下 Nexus 为我们创建了以下主要的 Repository:
1,Public Repositories: 这是一个 Repository Group, 该 Repository Group 包含了多个 Repository, 其中包含了 Releases,Snapshots,ThirdParty 和 Central.
2,3rd party: 该 Repository 即是存放你公司所购买的第三方软件库的地方, 它是一个由 Nexus 自己维护的一个 Repository.
3,Apache Snapshots: 看名字你就应该知道这是个什么样的 Repository, 这是一个代理 Repository, 即最终的依赖还是得在 Apache 官网上去下载, 然后缓存在 Nexus 中.
4,Central: 这就是代理 Maven Central Repository 的 Repository.
5,Releases: 你自己的项目要发布时, 就应该发布在这个 Repository, 他也是 Nexus 自己维护的 Repository, 而不是代理.
6,Snapshots: 你自己项目 Snapshot 的 Repository.
---------------------
来源: http://www.bubuko.com/infodetail-2884902.html