【nexus】centos7 nexus3 搭建私服

1.安装jdk

Centos7中安装jdk1.8_希若的个人博客-优快云博客

 

2.下载安装 nexus-3.11.0-01-unix.tar.gz

[root@MiWiFi-R3-srv ~]# tar -zxvf nexus-3.11.0-01-unix.tar.gz -C /usr/local/

 

3.修改nexus3的运行用户为root

[root@MiWiFi-R3-srv bin]# vim nexus.rc
run_as_user="root"

 

4.修改nexus3启动时要使用的jdk版本

[root@MiWiFi-R3-srv bin]# vim nexus

第14行:

INSTALL4J_JAVA_HOME_OVERRIDE=/usr/local/java/jdk1.8.0_144

 

5.修改nexus3默认端口(可选)

[root@MiWiFi-R3-srv etc]# cd /usr/local/nexus-3.11.0-01/etc/
[root@MiWiFi-R3-srv etc]# vim nexus-default.properties 

默认端口:8081

application-port=8081

 

6.修改nexus3数据以及相关日志的存储位置(可选):

[root@MiWiFi-R3-srv bin]# cd /usr/local/nexus-3.11.0-01/bin/
[root@MiWiFi-R3-srv bin]# vim nexus.vmoptions 
-XX:LogFile=./sonatype-work/nexus3/log/jvm.log
-Dkaraf.data=./sonatype-work/nexus3
-Djava.io.tmpdir=./sonatype-work/nexus3/tmp

7.启动nexus3

[root@MiWiFi-R3-srv ~]# cd /usr/local/nexus-3.11.0-01/bin
[root@MiWiFi-R3-srv ~]# ./nexus run &

稍等一会(首次启动会比较慢),当出现以下日志的时候表示启动成功!

-------------------------------------------------

Started Sonatype Nexus OSS 3.11.0-01

-------------------------------------------------

 

8.开启远程访问端口

[root@MiWiFi-R3-srv bin]# firewall-cmd --zone=public --add-port=8081/tcp --permanent
[root@MiWiFi-R3-srv bin]# firewall-cmd --reload

 

9.测试

nexus3默认端口是:8081
nexus3默认账号是:admin
nexus3默认密码是:admin123(登录的时候会提示密码在哪)

 

10.设置开机自启动(systemctl方式)

创建一个服务

[root@MiWiFi-R3-srv ~]# vim /usr/lib/systemd/system/nexus.service

填入相关内容

[Unit]
Description=nexus service

[Service]
Type=forking
LimitNOFILE=65536 #警告处理
ExecStart=/usr/local/nexus/nexus-3.11.0-01/bin/nexus start
ExecReload=/usr/local/nexus/nexus-3.11.0-01/bin/nexus restart
ExecStop=/usr/local/nexus/nexus-3.11.0-01/bin/nexus stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

将服务加入开机启动

[root@MiWiFi-R3-srv ~]# systemctl enable nexus.service

重新加载配置文件

[root@MiWiFi-R3-srv ~]# systemctl daemon-reload

 

11.配置本地maven的setting.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>F:\hzl_maven_repository</localRepository>
  
  <pluginGroups>
   
  </pluginGroups>

  
  <proxies>
   
  </proxies>

 
  <servers>
<!--第一个nexus-repo要和下面的mirror或profiles中的id一致,代表拉取是也需要进行身份校验-->
        <server>  
            <id>nexus-repo</id>  
            <username>admin</username>  
            <password>admin123</password>  
		</server>  
<!--这两个是jar上传时候进行的验证,id对应的是pom中id属性的值-->
		<server>  
            <id>maven-releases</id>  
            <username>admin</username>  
            <password>admin123</password>  
		</server>  
		<server>  
			<id>maven-snapshots</id>  
			<username>admin</username>  
			<password>admin123</password>  
		</server>  
  </servers>

  <mirrors>
    <!-- 这里配置策略是:优先从阿里云下载,下载不到时再从nexus下载 -->
    <mirror>  
      <id>alimaven</id>  
      <name>aliyun maven</name>  
      <url>https://maven.aliyun.com/repository/public/</url>  
      <mirrorOf>central</mirrorOf>          
    </mirror>

    <!--
	<mirror>
      <id>nexus</id>
      <name>nexus maven</name> 
      <url>http://192.168.1.169:8081/repository/maven-public/</url>
      <mirrorOf>nexus</mirrorOf>
    </mirror>
    -->

  </mirrors>

  <profiles>
	<profile>
		<id>nexus-repo</id>
		<repositories>
            <!-- 阿里远程仓库 -->
			<repository>
				<id>central</id>
				<url>https://maven.aliyun.com/repository/public/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>false</enabled></snapshots>
			</repository>

            <!-- nexus仓库 -->
			<repository>
				<id>HzlNexus</id>
				<url>http://192.168.1.169:8081/repository/maven-public/</url>
				<releases>
                    <enabled>true</enabled><updatePolicy>always</updatePolicy>
                </releases>
				<snapshots>
                    <enabled>true</enabled><updatePolicy>always</updatePolicy>          
                </snapshots>
			</repository>

		</repositories>

		<pluginRepositories>
            <!-- 阿里远程仓库 -->
			<pluginRepository>
				<id>central</id>
				<url>https://maven.aliyun.com/repository/public/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>false</enabled></snapshots>
			</pluginRepository>

            <!-- nexus仓库 -->
			<pluginRepository>
				<id>HzlNexus</id>
				<url>http://192.168.1.169:8081/repository/maven-public/</url>
				<releases>
                    <enabled>true</enabled><updatePolicy>always</updatePolicy>
                </releases>
				<snapshots>
                   <enabled>true</enabled><updatePolicy>always</updatePolicy>
                </snapshots>
			</pluginRepository>
		</pluginRepositories>

	</profile>
  </profiles>

  <activeProfiles>
	  <activeProfile>nexus-repo</activeProfile>
  </activeProfiles>
</settings>

项目中的pom.xml文件设置

<!-- 配置jar向私服推送的仓库地址,推送时会根据版本不同推送到不同的仓库中  -->
<distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.1.169:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>maven-snapshots</id><!--对应maven settings.xml中server的id-->
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.1.169:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

 

12.添加阿里云或其他仓库

aliyun:http://maven.aliyun.com/nexus/content/groups/public/

13.出现警告“System Requirement: max file descriptors [4096] likely too low, increase to at least [65536].”

最后的解决方法是在/etc/security/limits.conf 中,注释掉原来的nexus - nofile 65536 这一行,并增加以下两行:

nexus          soft    nofile  65536
nexus          hard    nofile  65536

或设置任意用户的nofile为65536:

* soft nofile 65536
* hard nofile 65536

保存修改后重启Nexus,就没有上面的警告了。

 

14.nexus账户权限控制

 nexus自带两个角色,一个事nx-admin:管理员角色,nx-anonymous:匿名角色

 新建一个角色,然后赋予角色相应的访问权限,如图所示:

 再新建一个用户,赋予相应角色,如图所示:

 完成上述步骤后,可以结合本章第11条进行配置即可。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值