Brief description:
In the office environment, Nexus private server is required to provide caching service for development. This blog simply records the steps of building Nexus 2. X private server in the office environment
Nexus website: https://www.sonatype.com
To download the OSS 2. X package: https://download.sonatype.com/nexus/oss/nexus-2.14.8-01-bundle.tar.gz
Clone the experimental machine according to the "CentOS7 experimental machine template construction deployment"
Deployment and construction:
# Host name and hosts configuration
HOSTNAME=nexus
hostnamectl set-hostname "$HOSTNAME"
echo "$HOSTNAME">/etc/hostname
echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts
echo "$(ip a|grep "inet "|grep -v 127|awk -F'[ /]' '{print $6}') $HOSTNAME">>/etc/hosts
# Configure and install jdk1.8
cd /usr/local/
tar -xf /tmp/jdk-8u172-linux-x64.tar.gz
echo 'export JAVA_HOME=/usr/local/jdk1.8.0_172'>>/etc/profile
echo 'export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib'>>/etc/profile
echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH'>>/etc/profile
source /etc/profile
java -version
# Configure and install Maven (not required)
cd /usr/local/
unzip /tmp/apache-maven-3.5.2-bin.zip
echo 'export MAVEN_HOME=/usr/local/apache-maven-3.5.2'>>/etc/profile
echo 'export PATH=$PATH:$MAVEN_HOME/bin'>>/etc/profile
source /etc/profile
mvn --version
# Unzip and install Nexus
cd /usr/local/
tar -xf /tmp/nexus-2.14.8-01-bundle.tar.gz
# Configure Nexus
cd /usr/local/nexus-2.14.8-01/bin
sed -i 's|^NEXUS_HOME=".*$|NEXUS_HOME="/usr/local/nexus-2.14.8-01"|g' nexus
sed -i 's/^#RUN_AS_USER.*/&\nRUN_AS_USER=root/g' nexus
sed -i 's|^#! /bin/sh$|#!/bin/bash|g' nexus
sed -i 's|^#!/bin/bash$|&\nJAVA_HOME=/usr/local/jdk1.8.0_172\nPLATFORM=linux-x86-64|g' nexus
cd /usr/local/nexus-2.14.8-01/bin/jsw/conf
sed -i 's|^wrapper.java.command=java$|wrapper.java.command=/usr/local/jdk1.8.0_172/bin/java|' wrapper.conf
# Configure startup
cat >/usr/lib/systemd/system/nexus.service<<EOF
[Unit]
Description=nexus
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nexus-2.14.8-01/bin/nexus start
ExecReload=/usr/local/nexus-2.14.8-01/bin/nexus restart
ExecStop=/usr/local/nexus-2.14.8-01/bin/nexus stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable nexus.service
systemctl start nexus.service
# The Nexus2 warehouse directory defaults to / usr / local / sonatype work, which can be considered for external storage
Web page configuration:
The default port of Nexus2 is: 8081 The default account of Nexus2 is: admin The default password of Nexus2 is: admin123 The browser accesses port 8081 of Nexus2 host for login configuration: http://192.168.77.10:8081/nexus The configuration process is simple, which involves slow network access in China. Some foreign warehouses need to find domestic image sources
Migration recovery:
Migrate the existing Nexus private server cache data directly to the new private server:
# New Nexus service closed
systemctl stop nexus.service
# Original Nexus service shutdown
systemctl stop nexus.service
# Data synchronization migration
cd /usr/local/sonatype-work/nexus
rm -rf *
scp -r 192.168.21.10:/usr/local/sonatype-work/nexus/* .
# Start recovery
systemctl start nexus.service
[TOC]