天天看點

[代碼上線]-Nexus私有倉庫

第1章 安裝Nexus私服

以下操作在Nexus伺服器進行:

1.安裝JDK和Nexus

Nexus下載下傳位址:

https://www.sonatype.com/download-oss-sonatype
      

安裝指令:

yum install java -y
tar zxf nexus-3.23.0-03-unix.tar.gz -C /opt/
cd /opt/
ln -s nexus-3.23.0-03 nexus
      

2.建立普通使用者并更改權限

useradd nexus -s /sbin/nologin
chown -R nexus:nexus /opt/
      

3.建立systemd啟動服務

cat >/usr/lib/systemd/system/nexus.service<<EOF
[Unit]
Description=nexus

[Service]
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
Type=forking
User=nexus
Group=nexus

[Install]
WantedBy=multi-user.target
EOF
      

4.修改jvm記憶體使用大小

預設2G記憶體,我們修改為1G

vim /opt/nexus/bin/nexus.vmoptions
-Xms1024m
-Xmx1024m
-XX:MaxDirectMemorySize=1024m
      

5.啟動并檢查

systemctl daemon-reload 
systemctl start nexus
netstat -lntup|grep 8081
ps -ef|grep java
      

6.配置賬戶密碼

打開浏覽器并登陸

http://10.0.0.202:8081/
      

預設賬号為admin,初始密碼儲存在檔案裡:

cat /opt/sonatype-work/nexus3/admin.password
      
[代碼上線]-Nexus私有倉庫
[代碼上線]-Nexus私有倉庫

7.初始化操作

登入後需要我們修改密碼:

[代碼上線]-Nexus私有倉庫

然後禁用匿名使用者通路:

[代碼上線]-Nexus私有倉庫

8.啟動排錯

報錯1:提示找不到配置

[代碼上線]-Nexus私有倉庫

解決方法:

删除 /opt/sonatype-work/nexus3目錄即可,重新啟動就會重新生成,這個目錄是壓縮包裡自帶的

rm -rf /opt/sonatype-work/nexus3/
      

報錯2:提示無法鎖定

[代碼上線]-Nexus私有倉庫

使用普通使用者登入後會在啟動使用者的家目錄下建立.java的隐藏檔案,如果普通使用者沒有家目錄就會報錯

解決方法是建立啟動使用者的家目錄,但是禁止登陸

mkdir /home/nexus
chown -R nexus:nexus /home/nexus
      

錯誤3: 提示逾時

[代碼上線]-Nexus私有倉庫

系統設定裡disable服務

[代碼上線]-Nexus私有倉庫

第2章 配置Nexus倉庫代理位址為國内源

1.預設倉庫說明

maven-central:maven中央庫,預設從https://repo1.maven.org/maven2/拉取jar
maven-releases:私庫發行版jar,初次安裝請将Deployment policy設定為Allow redeploy
maven-snapshots:私庫快照(調試版本)jar
maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配置settings.xml或項目pom.xml中使用
      

2.倉庫類型

Group:這是一個倉庫聚合的概念,使用者倉庫位址選擇Group的位址,即可通路Group中配置的,用于友善開發人員自己設定的倉庫。maven-public就是一個Group類型的倉庫,内部設定了多個倉庫,通路順序取決于配置順序,3.x預設Releases,Snapshots,Central,當然你也可以自己設定。 
Hosted:私有倉庫,内部項目的釋出倉庫,專門用來存儲我們自己生成的jar檔案
3rd party:未釋出到公網的第三方jar (3.x去除了)
Snapshots:本地項目的快照倉庫
Releases: 本地項目釋出的正式版本
Proxy:代理類型,從遠端中央倉庫中尋找資料的倉庫(可以點選對應的倉庫的Configuration頁簽下Remote Storage屬性的值即被代理的遠端倉庫的路徑),如可配置阿裡雲maven倉庫
Central:中央倉庫
Apache Snapshots:Apache專用快照倉庫(3.x去除了)
      

3.修改maven倉庫位址

[代碼上線]-Nexus私有倉庫
[代碼上線]-Nexus私有倉庫

将代理位址修改為阿裡源:

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

4.複制maven-public位址

[代碼上線]-Nexus私有倉庫

第3章 配置Maven使用Nexus倉庫

1.修改Maven配置檔案

<?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">
  <pluginGroups>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
    <server>   
      <id>snapshots</id>   
      <username>admin</username>   
      <password>123456</password>   
    </server>   
    <server>   
      <id>releases</id>   
      <username>admin</username>   
      <password>123456</password>   
    </server>   
    <server>   
      <id>public</id>   
      <username>admin</username>   
      <password>123456</password>   
    </server>   
  </servers>

  <mirrors>
    <mirror>
      <id>public</id>
      <mirrorOf>*</mirrorOf>
      <url>http://10.0.0.202:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>public</id>
      <repositories>
        <repository>
          <id>public</id>
          <url>http://10.0.0.202:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>public</id>
          <url>http://10.0.0.202:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>public</activeProfile>
  </activeProfiles>

</settings>
      

2.測試重新建構

3.檢查結果

[代碼上線]-Nexus私有倉庫