CentOS 7 下 Nexus 安装 && 迁移
JDK 安装
安装包准备
[root@docker ~]# ll | grep jdk
-rw-r--r--. 1 root root 127431820 Oct 9 11:22 jdk-8u261-linux-x64.rpm
安装
[root@docker ~]# rpm -ivh jdk-8u261-linux-x64.rpm
warning: jdk-8u261-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:jdk1.8-2000:1.8.0_261-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
环境变量配置
[root@docker ~]# tail -5 /etc/profile
#set java environment
export JAVA_HOME=/usr/java/jdk1.8.0_261-amd64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
Install Nexus
Add User
[root@docker ~]# useradd nexus -M -s /bin/bash
Visudo For User
[root@docker ~]# echo "nexus ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nexus
Get Nexus
[root@docker ~]# wget https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.2-02-unix.tar.gz
Tar Package
[root@docker ~]# mkdir /usr/local/nexus && tar zxf nexus-3.29.2-02-unix.tar.gz -C /usr/local/nexus --strip-components=1
Chown Dir
[root@docker ~]# chown -R nexus:nexus /usr/local/nexus
Config Nexus
# 更改前
[root@docker ~]# cat /usr/local/nexus/bin/nexus.vmoptions | grep -v ^$ | grep -v ^#
-Xms2703m
-Xmx2703m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
-Djava.endorsed.dirs=lib/endorsed
# 更改后
[root@docker ~]# cat /usr/local/nexus/bin/nexus.vmoptions | grep -v ^$ | grep -v ^#
-Xms2703m
-Xmx2703m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=./sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=./sonatype-work/nexus3
-Dkaraf.log=./sonatype-work/nexus3/log
-Djava.io.tmpdir=./sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
-Djava.endorsed.dirs=lib/endorsed
[root@docker ~]# cat /usr/local/nexus/bin/nexus.rc
run_as_user="nexus"
Start Nexus
[root@docker ~]# sudo -u nexus /usr/local/nexus/bin/nexus start
Starting nexus
# 查看进程
[root@docker ~]# ps -ef | grep nexus
nexus 12282 1 99 14:35 pts/0 00:01:30 /usr/java/jdk1.8.0_261-amd64/bin/java -server -Dinstall4j.jvmDir=/usr/java/jdk1.8.0_261-amd64 -Dexe4j.moduleName=/usr/local/nexus/bin/nexus -XX:+UnlockDiagnosticVMOptions -Dinstall4j.launcherId=245 -Dinstall4j.swt=false -Di4jv=0 -Di4jv=0 -Di4jv=0 -Di4jv=0 -Di4jv=0 -Xms2703m -Xmx2703m -XX:MaxDirectMemorySize=2703m -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=./sonatype-work/nexus3/log/jvm.log -XX:-OmitStackTraceInFastThrow -Djava.net.preferIPv4Stack=true -Dkaraf.home=. -Dkaraf.base=. -Dkaraf.etc=etc/karaf -Djava.util.logging.config.file=etc/karaf/java.util.logging.properties -Dkaraf.data=./sonatype-work/nexus3 -Dkaraf.log=./sonatype-work/nexus3/log -Djava.io.tmpdir=./sonatype-work/nexus3/tmp -Dkaraf.startLocalConsole=false -Djava.endorsed.dirs=lib/endorsed -Di4j.vpt=true -classpath /usr/local/nexus/.install4j/i4jruntime.jar:/usr/local/nexus/lib/boot/nexus-main.jar:/usr/local/nexus/lib/boot/activation-1.1.1.jar:/usr/local/nexus/lib/boot/jakarta.xml.bind-api-2.3.3.jar:/usr/local/nexus/lib/boot/jaxb-runtime-2.3.3.jar:/usr/local/nexus/lib/boot/txw2-2.3.3.jar:/usr/local/nexus/lib/boot/istack-commons-runtime-3.0.10.jar:/usr/local/nexus/lib/boot/org.apache.karaf.main-4.2.9.jar:/usr/local/nexus/lib/boot/osgi.core-6.0.0.jar:/usr/local/nexus/lib/boot/org.apache.karaf.specs.activator-4.2.9.jar:/usr/local/nexus/lib/boot/org.apache.karaf.diagnostic.boot-4.2.9.jar:/usr/local/nexus/lib/boot/org.apache.karaf.jaas.boot-4.2.9.jar com.install4j.runtime.launcher.UnixLauncher start 9d17dc87 0 0 org.sonatype.nexus.karaf.NexusMain
[root@docker ~]# tail -10 /usr/local/nexus/sonatype-work/nexus3/log/nexus.log
2021-10-09 14:36:59,946+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATED com.sonatype.nexus.plugins.nexus-restore-yum [3.29.2.02]
2021-10-09 14:36:59,957+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATING com.sonatype.nexus.plugins.nexus-ahc-plugin [3.29.2.02]
2021-10-09 14:36:59,994+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATED com.sonatype.nexus.plugins.nexus-ahc-plugin [3.29.2.02]
2021-10-09 14:37:00,004+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATING com.sonatype.nexus.plugins.nexus-ossindex-plugin [3.29.2.02]
2021-10-09 14:37:00,029+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.extender.NexusBundleTracker - ACTIVATED com.sonatype.nexus.plugins.nexus-ossindex-plugin [3.29.2.02]
2021-10-09 14:37:00,037+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.extender.NexusLifecycleManager - Start STORAGE
2021-10-09 14:37:00,054+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.internal.node.LocalNodeAccess - ID: CA942AF0-DDD01F85-0EC0F77F-B11EE769-22AFE69D
2021-10-09 14:37:00,377+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.internal.orient.DatabaseServerImpl - OrientDB version: 2.2.36 (build d3beb772c02098ceaea89779a7afd4b7305d3788, branch 2.2.x)
2021-10-09 14:37:00,393+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.internal.orient.DatabaseServerImpl$1 - OrientDB Server v2.2.36 (build d3beb772c02098ceaea89779a7afd4b7305d3788, branch 2.2.x) is starting up...
2021-10-09 14:37:00,397+0800 INFO [FelixStartLevel] *SYSTEM org.sonatype.nexus.internal.orient.DatabaseServerImpl$1 - Databases directory: /usr/local/nexus/sonatype-work/nexus3/db
[root@docker ~]# ss -ntlp | grep 8081
LISTEN 0 50 *:8081 *:* users:(("java",pid=12901,fd=882))
Stop Nexus
[root@docker ~]# sudo -u nexus /usr/local/nexus/bin/nexus stop
Shutting down nexus
Stopped.
Auto Start Nexus
Create Nexus.service
[root@docker ~]# cat /usr/lib/systemd/system/nexus.service
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/usr/local/nexus/bin/nexus start
ExecStop=/usr/local/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
Start Nexus
[root@docker ~]# systemctl daemon-reload
[root@docker ~]# systemctl start nexus
Check Nexus Status
[root@docker ~]# systemctl status nexus
● nexus.service - nexus service
Loaded: loaded (/usr/lib/systemd/system/nexus.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2021-10-09 14:44:39 CST; 4s ago
Process: 13930 ExecStart=/usr/local/nexus/bin/nexus start (code=exited, status=0/SUCCESS)
Main PID: 14105 (java)
CGroup: /system.slice/nexus.service
└─14105 /usr/java/jdk1.8.0_261-amd64/bin/java -server -Dinstall4j.jvmDir=/usr/java/jdk1.8.0_261-amd64 -Dexe4j.moduleN...
Oct 09 14:44:39 docker systemd[1]: Starting nexus service...
Oct 09 14:44:39 docker systemd[1]: Started nexus service.
[root@docker ~]# ss -ntlp | grep 8081
LISTEN 0 50 *:8081 *:* users:(("java",pid=14105,fd=876))
Useing In Web
http://localhost:8081
Nexus 迁移
停止服务
systemctl stop nexus
打包整个目录
tar zcf nexus_xxx.tar.gz nexus
迁移到新机器
scp nexus_xxx.tar.gz root@10.10.200.xxx:/root
解压文件包
tar zxf nexus_xxx.tar.gz -C /usr/local
启动服务
systemctl start nexus
参考