[代碼上線]-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

7.初始化操作

登錄后需要我們修改密碼:

然后禁用匿名用戶訪問:

8.啟動排錯

報錯1:提示找不到配置

解決方法:

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

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

報錯2:提示無法鎖定

解決方法:

使用普通用戶登錄后會在啟動用戶的家目錄下創建.java的隱藏文件,如果普通用戶沒有家目錄就會報錯

解決方法是創建啟動用戶的家目錄,但是禁止登陸

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

錯誤3: 提示超時

解決方法:

系統設置里disable服務

第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倉庫地址

將代理地址修改為阿里源:

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

4.復制maven-public地址

第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.檢查結果


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM