第 27 篇 : 搭建maven私服nexus

官网文档

1. 下载应该很慢, 最好是能翻墙

nexus-3.69.0-02-java8-unix.tar.gz

2. 上传到/usr/local/src, 解压及重命名

tar -zxvf nexus-3.69.0-02-java8-unix.tar.gz
rm -rf nexus-3.69.0-02-java8-unix.tar.gz
mv nexus-3.69.0-02 nexus
ls

3. 修改配置

cd /usr/local/src/nexus/etc
vi nexus-default.properties

修改端口为8085

application-port=8085

开放8085端口

firewall-cmd --zone=public --add-port=8085/tcp --permanent
firewall-cmd --reload

4 启动

4.1 创建nexus用户(root不能运行nexus)

密码需大于8个字符, 规则: 数字+英文大小写+特殊字符

useradd -m nexus
passwd nexus
chmod -R 755 /usr/local/src/nexus
chown -R nexus:nexus /usr/local/src/nexus
chmod -R 755 /usr/local/src/sonatype-work
chown -R nexus:nexus /usr/local/src/sonatype-work
vi /etc/security/limits.conf

在第 60 行添加如下内容

nexus - nofile 65536

如果觉得密码不好, 可以删除用户后重新添加

userdel -r nexus

4.2 启动nexus

su nexus
cd /usr/local/src/nexus/bin
nohup nexus run &

5. 登录

登录界面

5.1 初始密码获取

cat /usr/local/src/sonatype-work/nexus3/admin.password

5.2 安装4步

第1步
第2步
UAT 一般是允许的, PRD禁止
第3步
第4步直接Finish。可以看到nexus支持的类型还是挺多的, apt、conda、docker、go、maven、npm、nuget、papi、yum等

5.3 maven仓库类型: hosted、proxy、group

hosted:管理本公司的jar包,系统还默认分了snapshots和release版本
proxy:代理仓库,默认是maven的, 可以修改成阿里云的
group:一般是hosted和proxy的组合

6. 重新配置maven的setting

6.1 mave的配置

cd /usr/local/src/maven/conf
vi settings.xml

settings.xml示例(所有用不到的标签以及注释全部删除), 注意mirror标签里的name要和server中的id保持一致

<?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>/usr/local/src/javaDevelop</localRepository>
  
  <servers>
    <server>
      <id>hahashou-nexus</id>
      <username>admin</username>
      <password>登录密码</password>
    </server>
  </servers>

  <mirrors>
  	<mirror>
		<id>aliyun</id>
		<name>Nexus aliyun</name>
		<mirrorOf>central</mirrorOf>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
	</mirror>
	<mirror>
		<id>hahashou-nexus</id>
		<name>Nexus hahashou</name>
		<mirrorOf>*</mirrorOf>
		<url>http://127.0.0.1:8085/repository/maven-public/</url>
	</mirror>
  </mirrors>

  <profiles>
  	<profile>
		<id>jdk-1.8</id>
		<activation>
		<activeByDefault>true</activeByDefault>
		<jdk>1.8</jdk>
		</activation>
		<properties>
		 <maven.compiler.source>1.8</maven.compiler.source>
		 <maven.compiler.target>1.8</maven.compiler.target>
		 <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
		</properties>
    </profile>
    <profile>
         <id>nexus</id>
         <repositories>
          <repository>
            <id>aliyun</id>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
          </repository>
          <repository>
            <id>hahashou</id>
            <url>http://127.0.0.1:8085/repository/maven-public/</url>
          </repository>
        </repositories>
    </profile>  
  </profiles>

  <activeProfiles>
  	<activeProfile>jdk-1.8</activeProfile>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

6.2 项目中pom.xml的配置

在最下面增加一个大标签, 如下内容, 把IP换一下, 注意: 正常来说, maven-releases是不允许再次deploy的, 但是一般像公共的经常改的, 不能改一点东西就设置一个新的版本号, 所以最好将maven-releases的DeployMent policy设置成允许再次deploy, 当公共的依赖稳定之后, 再次迭代时换新的版本号即可
允许再次发布

<distributionManagement>
    <repository>
        <id>hahashou-nexus</id>
        <name>release</name>
        <url>http://IP:8085/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>hahashou-nexus</id>
        <name>snapshot</name>
        <url>http://IP:8085/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哈哈兽0026

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值