nexus配置yum私有仓库


生产环境,多数主机不可出外网,yum安装起来不太方便,随着生产环境主机数量增多,考虑换一种姿势配置yum代理,就得到了nexus这个东西,特此记录!可以参考nexus官方文档

一、环境准备

OS hostname IP role 是否可出网
CentOS 7.6 nexus 10.4.7.101 nexus服务端
CentOS 7.6 client 10.4.7.102 yum客户端

二、系统默认参数优化

$ cat > /etc/security/limits.conf << EOF
*                -       nofile          655360
*                -       memlock         unlimited
*                -       stack           655360
*                -       nproc           unlimited
EOF


$ cat > /etc/sysctl.conf << EOF
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
fs.file-max=655360
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.pid_max = 655360
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_max_orphans = 655360
net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144

net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216

net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.route.gc_timeout = 100
# 禁止icmp重定向报文
net.ipv4.conf.all.accept_redirects = 0
# 禁止icmp源路由
net.ipv4.conf.all.accept_source_route = 0

net.core.somaxconn = 65535
net.core.rmem_default = 8388608
net.core.wmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144

vm.swappiness = 10
vm.overcommit_memory = 1
vm.max_map_count = 262144
EOF

三、安装java环境

下载Linux环境下的jdk1.8,请去(官网)中下载jdk的安装文件;

$ mkdir /usr/local/java/
$ tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/java/
$ vim /etc/profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_171
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
$ source /etc/profile
$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

四、安装nexus

nexus的二进制包不好从官方下,如果你们有什么国内的下载地址,可以评论里分享下,我这里费尽周折下载了一个最新版本(2020-12-12日下载),提取链接:百度网盘( 提取码:ylpw )。

4.1 解压安装

$ wget https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.0-02-unix.tar.gz
# 官方下载链接(如已下载我网盘的包,可不执行wget,大概率下载不下来)

$ mkdir /data
$ tar zxvf nexus-3.29.0-02-unix.tar.gz -C /data/
$ cd /data
$ mv sonatype-work/ nexus-3.29.0-02/
$ ln -sf nexus-3.29.0-02/ nexus

4.2 修改监听地址及端口(可不做修改)

$ vim /data/nexus/etc/nexus-default.properties
application-port=8081
application-host=0.0.0.0

4.3 修改jvm参数、日志等存储路径

$ vim /data/nexus/bin/nexus.vmoptions
-Xms4096m        # 最小可用内存
-Xmx4096m        # 最大可用内存(建议与最小可用内存保持一致)
-XX:MaxDirectMemorySize=4096m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=/data/nexus/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=/data/nexus/sonatype-work/nexus3
-Dkaraf.log=/data/nexus/sonatype-work/nexus3/log
-Djava.io.tmpdir=/data/nexus/sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
-Djava.endorsed.dirs=lib/endorsed
# 将上面的路径都修改为绝对路径

4.4 启动nexus

注:root用户启动可能会有问题,所以需要创建nexus用户用于启动nexus服务!

$ useradd nexus
$ chown -R nexus /data
$ ln -sf /data/nexus/bin/nexus /usr/local/bin/

$ su -s /bin/bash -c "nexus run" nexus      
# 前台启动nexus(可以看到日志信息,避免配置错误还在傻等着)
$ su -s /bin/bash -c "nexus start" nexus 
# 后台启动nexus

$ ss -lnptu | grep 8081      
# 等待片刻后,确认8081端口在监听(8081端口启动较慢,多点耐心)
tcp    LISTEN     0      50        *:8081                  *:*                   users:(("java",pid=7587,fd=788))

五、配置yum代理

5.1 初始化nexus

访问nexus的web管理页,URL:http://nexus_ip:8081 ,如下:

20210309222825

查看admin密码

$ cat /data/nexus/sonatype-work/nexus3/admin.password
8d47dd29-9cbf-472e-806e-7dbde49bbe4f

20210309222915

更新密码

20210309223042

开启匿名用户访问

20210309223106

5.2 创建rpm包存储系统

enter description here

20210309223446

enter description here

5.3 创建存储库

5.3.1 创建centos存储库

enter description here

enter description here

仓库类型说明

类型 说明
hosted 本地存储。像官方仓库一样提供本地私库功能
proxy 从远程中央仓库中寻找数据的仓库
group 组类型,能够组合多个仓库为一个地址提供服务

下面的 Remote storage填写: https://opsx.alibaba.com/centos/

enter description here

enter description here

5.3.2 创建epel存储库

enter description here

enter description here

下面的 Remote storage填写: http://mirrors.aliyun.com/epel/

enter description here

enter description here

5.4 查看存储库的URL

enter description here

分别查看上面创建的两个存储库,如下:

20210309224225
20210309224236

可以添加docker-ce 和 kubernetes仓库,添加方法跟上述一致
docker-ce的 Remote storage填写: https://download.docker.com/linux/centos/
kubernetes的 Remote storage填写: http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64

5.5 配置客户端

以下操作到不能出网的客户端进行配置。

# 配置默认的repo文件
$ cd /etc/yum.repos.d/
$ mkdir bak
$ mv *.repo bak/


# 将下面的baseurl换成你自己的maven服务地址
$ cat > nexus.repo << EOF
[os]
name=os
baseurl=http://10.4.7.101:8081/repository/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0
[updates]
name=updates
baseurl=http://10.4.7.101:8081/repository/centos/\$releasever/updates/\$basearch/
enabled=1
gpgcheck=0
[extras]
name=extras
baseurl=http://10.4.7.101:8081/repository/centos/\$releasever/extras/\$basearch/
enabled=1
gpgcheck=0
[centosplus]
name=centosplus
baseurl=http://10.4.7.101:8081/repository/centos/\$releasever/centosplus/\$basearch/
enabled=1
gpgcheck=0
[configmanagement]
name=configmanagement
baseurl=http://10.4.7.101:8081/repository/centos/\$releasever/configmanagement/\$basearch/ansible-29/
enabled=1
gpgcheck=0
[epel]
name=Extra Packages for Enterprise Linux 7 - \$basearch
baseurl=http://10.4.7.101:8081/repository/epel/7/\$basearch
enabled=1
gpgcheck=0
[docker-ce]
name=docker-ce
baseurl=http://10.4.7.101:8081/repository/docker-ce/$releasever/$basearch/stable/
enabled=1
gpgcheck=0
[kubernetes]
name=kubernetes
baseurl=http://10.4.7.101:8081/repository/kubernetes/
enabled=1
gpgcheck=0
EOF

$ yum clean all && yum makecache fast    
# 如果makecache报错,请关注最后一条输出,确认是哪个url找不到,然后进行修改。

$ yum repolist      # 查看可用rpm包数量
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                  源名称                                                       状态
centosplus/7/x86_64                     centosplus                                                       69
configmanagement/7/x86_64               configmanagement                                                 39
docker-ce/7/x86_64                      docker-ce                                                       108
epel/x86_64                             Extra Packages for Enterprise Linux 7 - x86_64               13,552
extras/7/x86_64                         extras                                                          451
kubernetes                              kubernetes                                                      633
os/7/x86_64                             os                                                           10,072
updates/7/x86_64                        updates                                                       1,640
repolist: 26,564    # 确认可用rpm包数量

# 随便yum几个试试效果
$ yum -y install nginx php ansible lsof strace 

5.6 查看nexus缓存的rpm包

enter description here

齐活,以后每个需要yum的客户端,只需要按照上面配置客户端进行即可。

posted @ 2021-03-09 22:54  吕振江  阅读(1031)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end