一、下载nexus ,使用版本nexus-3.13.0-01-unix.tar.gz,下载地址java
https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.13.0-01-unix.tar.gz
二、解压后移动到安装目录(/opt/nexus)apache
建立安装目录vim
[root@ou Downloads]# mkdir /opt/nexus/
解压安装包到安装目录:服务器
[root@ou Downloads]# tar -zxvf nexus-3.13.0-01-unix.tar.gz -C /opt/nexus/
切换到安装目录:maven
[root@ou Downloads]# cd /opt/nexus
查看目录详情:this
[root@ou nexus]# ls nexus-3.13.0-01 sonatype-work
解压缩后能够看到有两个文件夹,第一个是nexus服务,第二个是它的私有仓库目录。 这时已经能够启动 nexusurl
进入位置:NEXUS_HOME/bin
本示例位置:.net
/opt/nexus/nexus-3.13.0-01/bin
进入bin目录:unix
[root@ou nexus]# cd nexus-3.13.0-01/bin [root@ou bin]# ./nexus start **************************************** WARNING - NOT RECOMMENDED TO RUN AS ROOT **************************************** If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
当用root权限运行时会弹出提示,解决方式是code
[root@ou bin]# vim nexus 在配置文件上部找到 #RUN_AS_USER= 在下一行添加 RUN_AS_USER=root 具体示例: # the JVM and is not useful in situations where a privileged resource or # port needs to be allocated prior to the user being changed. #RUN_AS_USER= RUN_AS_USER=root
三、设置系统服务
3.一、添加 NEXUS_HOME 环境变量
vim /etc/profile
在后面添加
export NEXUS_HOME=/opt/nexus/nexus-3.13.0-01
使新加入的内容生效
source /etc/profile
3.二、添加本地jdk
vim /opt/nexus/nexus-3.13.0-01/bin/nexus
在文件中找到 INSTALL4J_JAVA_HOME_OVERRIDE 这一行(这一行默认被注释),添加上本身的JDK路径
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/java/jdk1.8.0_181-amd64
3.三、配置以 nexus 用户启动应用
nexus 官网建议不要使用 root 账户启动应用,因此建立一个 nexus 用户
useradd nexus
修改 nexus 配置,使用 nexus 做为应用启动的账户
gedit /opt/nexus/nexus-3.13.0-01/bin/nexus.rc
将内容修改成
run_as_user=”nexus”
修改 nexus 的目录权限
chown nexus nexus
3.四、设置系统服务(systemd)
vi /usr/lib/systemd/system/nexus.service
[Unit] Description=nexus After=network.target [Service] Type=forking ExecStart=/opt/nexus/nexus-3.13.0-01/bin/nexus start ExecReload=/opt/nexus/nexus-3.13.0-01/bin/nexus stop ExecStop=/opt/nexus/nexus-3.13.0-01/bin/nexus stop PrivateTmp=true [Install] WantedBy=multi-user.target
而后执行 systemctl daemon-reload,从新加载服务 再执行 systemctl enable nexus,使该服务能够开机自启。 启动服务 systemctl start nexus
四、登录管理界面
默认管理地址为:http://localhost:8081/nexus/ 使用界面右上角log in进行默认用户的登录, 默认用户为:admin,密码为:admin123。
五、点击左侧的users查看当前系统的用户。
能够看到一共三个用户,admin,deployment和anonymous。 admin:该用户拥有Nexus的所有权限,默认密码为admin123。 deployment:该用户可以访问Nexus,浏览仓库内容、搜索、上传部署构件,可是不能对Nexus进行任何配置,默认密码为deployment123。 anonymous:该用户对应了全部未登陆的匿名用户,它们能够浏览仓库并进行搜索
六、集成Maven 打开本地 %M2_HOME%\conf\settings.xml 文件 6.一、设置本地仓库位置
<localRepository>/opt/apache-maven-3.5.4/repository</localRepository>
6.二、设置 Server
<server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server>
6.三、设置 Nexus 镜像(localhost 修改成安装 Nexus 的服务器地址)
<mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/repository/maven-public/</url> </mirror>
6.四、设置 Profile(localhost 修改成安装 Nexus 的服务器地址)
<profile> <id>nexus-resp</id> <repositories> <repository> <id>nexus-releases</id> <url>http://localhost:8081/repository/maven-releases/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </repository> <repository> <id>nexus-snapshots</id> <url>http://localhost:8081/repository/maven-snapshots/</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus-plugin</id> <url>http://localhost:8081/repository/maven-public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile>
6.五、设置默认激活的 profile
<activeProfiles> <activeProfile>nexus-resp</activeProfile> </activeProfiles>
6.六、修改工程pom文件
<distributionManagement> <repository> <id>nexus-releases</id> <name>Team Nexus Release Repository</name> <url>http://localhost:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Team Nexus Snapshot Repository</name> <url>http://localhost:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> <repositories> <repository> <id>nexus-public</id> <name>Nexus public Repository</name> <url>http://localhost:8081/repository/maven-public</url> </repository> </repositories>
操做完成,执行 mvn deploy,应该就能够 Nexus 上查找到你当前项目了。