CentOS7下安裝Nexus私服及基礎配置

環境準備

  • VMware上安裝CentOS7
  • XShell/Xftp
  • NexusOSS-3.10
  • jdk1.8html

    安裝

    使用root用戶登陸,將安裝包均放置在/usr/local文件夾下
  • 使用Xshell、Xftp、FileZilla或MobaXterm將上述jdk及nexus安裝包上傳至/usr/local
  • tar -zxvf jdk-8u211-linux-x64.tar.gz
  • tar -zxvf nexus-3.10.0-04-unix.tar.gz
    此時安裝就已經完成了,其實已經能夠直接使用root用戶啓動了,可是爲了方便之後管理,我這裏添加了一些配置。參考設置小節。linux

    設置

日誌存放

nexus啓動時,會產生日誌和臨時文件等,默認狀況下會放在與Nexus安裝目錄同級文件夾sonatype-work中(第一次啓動會自動生成),現將其默認位置修改成Nexus的根目錄下vim /usr/local/nexus-3.10.0-04/bin/nexus.vmoptions
在這裏插入圖片描述shell

防火牆

基本參考
高級參考
firewall-cmd --zone=public --add-port=8081/tcp --permanentvim

HTTPS

端口

Nexus默認端口是8081,它的配置文件在/usr/local/nexus-3.10.0-04/etc/nexus-default.properties中,能夠經過cat命令查看:app

## 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

添加https訪問的形式涉及到端口設置,假如準備設置8443爲https端口,那麼須要修改兩個地方:tcp

  1. 新增application-port-ssl=8443
  2. nexus-args屬性上追加,${jetty.etc}/jetty-https.xml在這裏插入圖片描述ide

    注:若是須要將http導向https訪問,則追加jetty-http-redirect-to-https.xmlnexus-args,這裏我沒有強制。
    此時也別忘記開防火牆:firewall-cmd --zone=public --add-port=8443/tcp --permanent工具

    keystore
    若是此時啓動確定會報錯1,由於還缺keystore.jks的配置,咱們使用腳本生成,其中涉及keytool工具使用,所以先保證keytool能夠正常使用:
  • 添加JAVA_HOME環境變量
    • vim /etc/profile並在合適位置加入
      shell export JAVA_HOME=/usr/local/jdk1.8.0_211 export PATH=$JAVA_HOME/bin:$PATH
    • 刷新環境變量使其馬上生效:resource /etc/profile
    • vim /usr/local/nexus-3.10.0-04/nexus-ssl-generate-keystore.sh
      ```shell
      NEXUS_DOMAIN='Nexus'
      if [[ -z $1 ]]; then
      echo 'please input your ip_address!'
      exit
      fi
      NEXUS_IP_ADDRESS=$1
      PASSWORD='password'
      keytool -genkeypair -keystore keystore.jks -storepass ${PASSWORD} -keypass \({PASSWORD} -alias nexus -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=\){NEXUS_DOMAIN}, OU=Nexus, O=Nexus, L=Beijing, ST=Beijing, C=CN" -ext "SAN=IP:${NEXUS_IP_ADDRESS}" -ext "BC=ca:true"spa

      mv keystore.jks etc/ssl/
      #keytool -export -alias nexus -keystore keystore.jks -file keystore.cer -storepass ${PASSWORD}
      #mv keystore.cer etc/ssl/.net

      ```
    • 生成keystore/usr/local/nexus-3.10.0-04/nexus-ssl-generate-keystore.sh 192.168.197.198,這裏192.168.197.198是本機IP。

開機啓動

參考
vim /usr/lib/systemd/system/nexus3.service

[Unit]
Description=nexus3 - private repository
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nexus-3.10.0-04/bin/nexus start
ExecReload=/usr/local/nexus-3.10.0-04/bin/nexus restart
ExecStop=/usr/local/nexus-3.10.0-04/bin/nexus stop

[Install]
WantedBy=multi-user.target

此時使用systemctl enable nexus3使配置生效便可。

使用說明
OPTION COMMAND
啓動 systemctl start nexus3
中止 systemctl stop nexus3
重啓 systemctl restart nexus3

用戶

通常不能直接使用root用戶,所以須要爲nexus添加用戶專門運行:
添加用戶:adduser nexus
設置密碼:passwd nexus
將擁有者設置爲nexuschown nexus:nexus -R /usr/local/nexus-3.10.0-04
nexus添加至sudoers:

  • visudo
  • 添加nexus ALL=(ALL) ALL
  • su nexus

    啓動

    sudo systemctl start nexus3


  1. /usr/local/nexus-3.10.0-04/etc/jetty/jetty-https.xml中會涉及讀取keystore.jks

相關文章
相關標籤/搜索