搭建系统环境:Red Hat Enterprise Linux release 8.7
先将需要用到的压缩包(jdk-8u251-linux-x64.tar.gz、apache-maven-3.6.2-bin.tar.gz、nexus-3.31.1-01-unix.tar.gz)一并上传至/usr/local/src文件夹下,再执行初始化脚本: source init.sh 8.7,脚本内容如下:
#!/bin/bash
#!/bin/bash
if [ -z $1 ]
then echo '$1 is not exists or is empty'
exit
fi
echo "[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/rockylinux/8/BaseOS/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/rockylinux/8/AppStream/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
[PowerTools]
name=PowerTools
baseurl=https://mirrors.aliyun.com/rockylinux/8/PowerTools/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
[Extras]
name=Extras
baseurl=https://mirrors.aliyun.com/rockylinux/8/extras/\$basearch/os/
gpgcheck=0
enabled=1
gpgkey=https://mirrors.aliyun.com/rockylinux/RPM-GPG-KEY-ANOLIS
" > /etc/yum.repos.d/online.repo
echo vers:$1
sed -i "s/8/$1/g" /etc/yum.repos.d/online.repo
dnf install -y vim
cd /usr/local/src/
tar -zxvf apache-maven-3.6.2-bin.tar.gz
tar -zxvf jdk-8u251-linux-x64.tar.gz
echo "export MAVEN_HOME=/usr/local/src/apache-maven-3.6.2" >> /etc/profile
echo "export JAVA_HOME=/usr/local/src/jdk1.8.0_251" >> /etc/profile
echo "export PATH=\$PATH:\$MAVEN_HOME/bin:\$JAVA_HOME/bin" >> /etc/profile
source /etc/profile
systemctl stop firewalld && systemctl disable firewalld
执行完init.sh后,编辑maven的配置文件settings.xml, 在标签里面天下如下内容:
vim /usr/local/src/apache-maven-3.6.2/conf/settings.xml
aliyunmaven
*
aliyun
https://maven.aliyun.com/repository/public
nexus-163
*
Nexus 163
http://mirrors.163.com/maven/repository/maven-public/
检测下环境是否初始化成功,如下图所示表示环境准备完毕
mvn -v
创建用户
useradd nexus
echo 'nexus'|passwd --stdin nexus
tar -zxvf nexus-3.31.1-01-unix.tar.gz
将nexus解压后的两个目录以及目录下的子目录和文件的属主属组改成nexus
chown -R nexus:nexus nexus-3.31.1-01
chown -R nexus:nexus sonatype-work
vim /etc/security/limits.conf
添加如下内容
nexus - nofile 65536
编辑/usr/local/src/nexus-3.31.1-01/bin/nexus.rc文件
vim /usr/local/src/nexus-3.31.1-01/bin/nexus.rc
编辑/usr/local/src/nexus-3.31.1-01/bin/nexus
vim /usr/local/src/nexus-3.31.1-01/bin/nexus
将INSTALL4J_JAVA_HOME_OVERRIDE前面的#去掉,并且赋值jdk的路径
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/local/src/jdk1.8.0_251
编辑/etc/systemd/system/nexus.service
vim /etc/systemd/system/nexus.service
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65535
ExecStart=/usr/local/src/nexus-3.31.1-01/bin/nexus start
ExecStop=/usr/local/src/nexus-3.31.1-01/bin/nexus stop
User=nexus
Restart=on-abort
TimeoutSec=600
[Install]
WantedBy=multi-user.target
启动nexus
systemctl daemon-reload
systemctl start nexus
查看nexus状态
systemctl status nexus
接下来就来开始访问nexus
访问地址:192.168.225.25:8081
登录下
登录以后需要初始设置一下以及修改登陆密码
创建私服代理仓库
这里填写阿里云仓库地址
在maven的settings.xml里面添加私服仓库地址,把下面这个添加在标签里面即可
maven-public
*
maven-public
http://192.168.225.25:8081/repository/maven-public/
来到jar包上传界面,选中待上传的jar包,然后填写jar包的坐标,其实一般需要手动上传的jar包不多,下面就拿Oracle数据库的驱动包来说明一下