Maven 私服 centos7 安装nexus,手动导入索引,以及私服配置(多图,图解)
nexus 简单理解就是管理maven的一个jar包,依赖管理的一个私服仓库软件;其他功能再次不多做介绍,自己可以度娘,上车
小编今天安装的Nexus版本: nexus-2.12.0-01-bundle.tar.gz
一:nexus 安装环境
1、 Nexus安装环境CentOS 7
Centos7的下载安装配置请参考: https://blog.****.net/taoziBug/article/details/80262652
2、 Nexus 依赖与jdk,推荐使用jdk1.8;
关于jdk1.8的下载安装参考 : https://blog.****.net/taoziBug/article/details/80264874
3、 Nexus 官方下载 : https://www.sonatype.com/download-oss-sonatype
之前小编在服务器端安装时,OSS 3.X 服务器1G内存会报错,大概意思就是内存不足,小编保守估计需要2G内存以上的服务器 1G内存的安装 OSS 2.X 版本的就没有问题
所以小编在安装是 选用 nexus-2.12.0-01-bundle.tar.gz,服务器硬件条件满足的可以尝试一下
二:安装Nexus
安装目录在 /usr/local/nexus/ ;
1.在 /usr/local/ 创建nexus文件夹
mkdir nexus;
2.进入 /usr/local/nexus/文件夹下
cd /usr/local/nexus/
3.利用xftp5,将安装包 nexus-2.12.0-01-bundle.tar.gz 传入到 /usr/local/nexus/目录下
4. 解压nexus-2.12.0-01-bundle.tar.gz到/usr/local/nexus
tar -axvf nexus-2.12.0-01-bundle.tar.gz
解压后会产生两个文件夹 sonatype-work、nexus-2.14.8-01(主程序),
两个文件夹必须在同一个目录下(xftp5查看效果)
5.1进入到 /usr/local/nexus/nexus-2.14.8-01/bin 目录下
cd /usr/local/nexus/nexus-2.14.8-01/bin
5.2.编辑文件,nexus, 修改RUN-AS-USER=root,保存退出 (i esc shift+: wq 回车)
vim nexus
修改RUN-AS-USER=root,保存退出 (i esc shift+: wq 回车)
6. 运行/usr/local/nexus/nexus-2.12.0-01/bin/nexus;
进入bin目录,执行命令 ./nexus start
如果报一下错误:是因为没有配置环境变量
解决方法:
A.临时生效
export RUN_AS_USER=root,然后重新卡其 nexus,ok,完美运行
B.加入系统变量,编辑配置文件 profile
vi /etc/profile 加入export RUN_AS_USER=root
立即生效配置文件:
source /etc/profile,重新开启nexus,完美运行
7. 本机计算机 浏览器打开http://{IP}:8081/nexus/;
默认用户名/密码:admin/admin123
如果报以下错误,可能是服务器端防火墙没有关闭,或者没有打开8081端口权限
解决方案
查看防火墙运行状态
firewall-cmd --state
1.打开防火墙8081端口权限 (感兴趣的同学可以去查询在系统文件中设置多个端口的开放)
1.1临时开放
firewall-cmd --remove-service=ftp --permanent
1.2永久开放
firewall-cmd --add-port=80/tcp --permanent
2.直接关闭防火墙(小编推荐)
systemctl stop firewalld.service
3. 禁止开机启动启动防火墙
systemctl disable firewalld.service
重新在浏览器运行 http://{IP}:8081/nexus/完美,安装成功,点击右上角 log In,进行登陆,账户:admin 密码:admin123 点击logIn 按钮登陆
三: 手动更新索引
1.删除/usr/local/nexus/sonatype-work/nexus/indexer/central-ctx下的文件
cd /usr/local/nexus/sonatype-work/nexus/indexer/central-ctx
ll 查看此文件夹中的文件
rm -rf 文件名 删除central-ctx下的所有文件
2.利用 xftp5 将indexer-cli-5.1.0.jar、nexus-maven-repository-index.gz、nexus-maven-repository-index.properties三个文件考到central-ctx目录下,
2.执行命令java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz;(过程很慢大概需要几分钟)
3.执行完毕后,此文件夹目录下会产生许多文件;
4.重新启动nexus,然后重新访问nexus页面,查看Browse Index中已经存在了jar依赖包,完美收官
cd /usr/local/nexus/nexus-2.12.0-01/bin
./nexus stop 关闭nexus
./nexus start 开启nexus
再次在页面访问:查看Browse Index树形目录
四:页面 ,Nexus程序自动导入索引、开启远程索引
新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123。
点击左边Administration菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。如下图
然后在Apache Snapshots,Codehaus Snapshots和Maven Central这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。
可以进入Scheduled Tasks查看任务的执行情况,当执行完成时,远程仓库的索引就已经建立完毕了。
这样设置以后, Nexus会自动从远程中央仓库下载索引文件, 为了检验索引文件自动下载是否生效,可以却换到Browse Index
在左边菜单栏里面有个Artifact Search, 在输入框里面输入你想要搜索的构件名字,比如:maven, 那么查询结果如下:
五、创建Nexus代理仓库
点击菜单栏上的Add按钮后选择Proxy Repository,看到如下所示配置界面:
六:settings.xml的配置
<?xml version="1.0" encoding="UTF-8"?><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>E:\DMAVEN_REPOSITORY</localRepository> <servers> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> <server> <id>tomcat</id> <username>admin</username> <password>admin</password> </server> </servers> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <name>Local Repository</name> <url>http://ip:8081/nexus/content/groups/public/</url> </mirror> </mirrors> <profiles> <profile> <id>central</id> <repositories> <repository> <id>central</id> <name>central</name> <url>http://ip:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://ip:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>central</activeProfile> </activeProfiles></settings>
七:Maven项目pom.xml
- <distributionManagement>
- <!-- 两个ID必须与 setting.xml中的<server><id>nexus-releases</id></server>保持一致-->
- <repository>
- <id>nexus-releases</id>
- <name>Nexus Release Repository</name>
- <url>http://ip/nexus/content/repositories/releases</url>
- </repository>
- <snapshotRepository>
- <id>nexus-snapshots</id>
- <name>Nexus Snapshot Repository</name>
- <url>http://ip/nexus/content/repositories/snapshots</url>
- </snapshotRepository>
- </distributionManagement></pre><pre class="html" name="code"> </pre><pre class="html" name="code">
- </span>