前置条件:
1.安装jdk,可参考 http://www.cnblogs.com/grey-wolf/p/6480489.html
本人虚拟机安装的是centos7 自带1.7.0,先卸载在装1.8.0
可参考https://blog.csdn.net/learn_tech/article/details/80770710
2.nexus仓库管理器,分为两个版本,Nexus Repository Manager OSS 和 Nexus Repository Manager Pro。前者可以免费使用,相比后者,功能缺少一些,但是不影响我们搭建maven私服。
所以就选择OSS版本。
下载地址:https://www.sonatype.com/download-oss-sonatype,下载不下来可以去这里 http://download.csdn.net/detail/cctvckl/9766638
安装和配置
安装nexus服务器
1.上传tar.gz包到指定目录(我这边假定是/home/xuxiang/upload)
因为官网下载很慢,我选择的网友百度云的包,在windows上下载下来再通过xshell上传到服务器上
百度云链接:https://pan.baidu.com/s/1lyZV4Vkf9QLmQCLyV8NueA
提取码:140b
2.解压到/opt/nexus
unzip /home/xuxiang/upload/nexus.zip
mv nexus /opt
3. 配置
cd ~ 回到当前用户目录
vi .bashrc
编辑.bashrc文件
#set nexus
NEXUS_HOME="/opt/nexus"
使当前用户配置生效
source ./.bashrc
- 编辑nexus.properties,修改nexus对外端口以及对外主机地址。
vi /opt/nexus/conf/nexus.properties
application-port = 8081
application-host = 192.168.0.106
- 编辑nexus文件,修改NEXUS_HOME为自己的安装地址,修改运行使用用户名称。
vi /opt/nexus/bin/nexus
#Set this to the root of the Nexus installation
NEXUS_HOME = "/opt/nexus"
RUN AS USER = root
6.这样,nexus的安装配置就算完成了,启动nexus。
nexus start
nexus status
nexus console
nexus stop
7.运行启动命令之后,并不代表nexus就启动成功了,查看nexus的日志记录,看是否有警告等。若出现org.sonatype.nexus.bootstrap.jetty.JettyServer - Started,则代表nexus启动成功。
cat /opt/nexus/logs/wrapper.log
8.访问
这个时候访问对应的网站:192.168.0.106:8081/nexus,也许你并不能访问成功。其原因可能是没有打开linux防火墙所对应的端口访问
9.对防火墙进行修改后,再次访问,访问成功。
默认账户和密码admin/admin123
防火墙配置篇:
开启端口
[root@centos7 ~]# firewall-cmd --zone=public --add-port=8081/tcp --permanent
查询端口号80 是否开启:
[root@centos7 ~]# firewall-cmd --query-port=8081/tcp
重启防火墙:
[root@centos7 ~]# firewall-cmd --reload
查询有哪些端口是开启的:
[root@centos7 ~]# firewall-cmd --list-port
命令含义:
–zone #作用域
–add-port=8081/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
maven连接nexus的配置
1、在要发布到nexus的项目pom中,添加
<distributionManagement>
<repository>
<id>releases</id><!--这个ID需要与你的release仓库的Repository ID一致-->
<url>http://192.168.0.106:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id><!--这个ID需要与你的snapshots仓库的Repository ID一致-->
<url>http://192.168.0.106:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
2、在maven的配置文件settings.xml中,添加
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.0.106:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
复制代码
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password><!--这个密码就是你设置的密码-->
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password><!--这个密码就是你设置的密码-->
</server>
</servers>
3、测试一下
在idea中的maven projects中,点击deploy发布: