1. 程式人生 > >Nexus Repository安裝和maven,npm配置(Linux)

Nexus Repository安裝和maven,npm配置(Linux)

Nexus Repository下載

根據作業系統選擇指定版本,本文針對Linux安裝,其他的安裝過程可能有所差異。

https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3

安裝

建議先建立一個nexus使用者,將檔案拷貝到/home/nexus


# 按具體下載檔名
tar -zxvf nexus-3.14.0-04-unix.tar.gz

# 按具體解壓目錄
cd nexus-3.14.0-04/bin


## 啟動
./nexus start
# ./nexus stop #停止
# ./nexus status # 檢視狀態

配置修改

NexusRepository 預設佔用8081埠,如果與其他服務有衝突,需要在etc目錄下建立一個nexus.properties,具體配置參考nexus-default.properties

## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

Nexus不建議在root使用者下執行,需要建立使用者nexus使用者,修改bin/nexus.rc檔案

run_as_user="nexus"

開機自啟動

開啟自啟動有init.d和systemd兩種方式。

init.d

1.建立一個nexus使用者

2.拷貝nexus的軟連結到init.d目錄
注意:最好再root做自啟動配置,省的沒許可權

# 原檔案路徑按實際
ln -s /home/nexus/nexus-3.14.0-04/bin/nexus /etc/init.d/nexus

4.1 chkconfig 寫法(和4.2二選一)

cd /etc/init.d
chkconfig --add nexus
chkconfig --levels 345 nexus on

4.2 update-rc.d寫法(和4.1 二選一)

cd /etc/init.d
sudo update-rc.d nexus defaults
sudo service nexus start

5.切換到nexus使用者視窗,啟動服務

su nexus

service nexus start

systemd

前提是伺服器有安裝systemd工具,一般cenos7預設安裝。

建立一個nexus使用者

在/etc/systemd/system/ 目錄新增如下檔案

nexus.service

[Unit]
Description=nexus service
After=network.target
  
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
  
[Install]
WantedBy=multi-user.target
Activate the service with the following commands:

啟動服務命令

sudo systemctl daemon-reload
sudo systemctl enable nexus.service
sudo systemctl start nexus.service

檢視服務執行日誌

tail -f /opt/sonatype-work/nexus3/log/nexus.log