Nexus部署本地yum源
在生产环境中,我们总会遇到下载或更新rpm包的操作,但是往往我们不可能所有的服务器都能连接外网(特别是一些zf单位)。所以理想的情况下就是我们有一台linux服务器可以连外网,其余的服务器通过它做代理来更新rpm包。
有一些比较传统的方法是把包下载到本地,通过createrepo命令生成本地仓库,其余的服务器通过ftp/http的方式来访问,但是有时候我们会需要一些拓展的包,所以有没有一种比较方便的方式让我们可以代理到阿里或者163的yum源呢。
下面我们就讲一下使用Nexus代理,不管是你是centos6,centos7或者ubuntu,也不管你是rpm还是pip或是yum,Nexus都可以满足你的需求。
安装:
操作系统:centos7
[root@yangdong ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
nexusServer: 192.168.105.233
安装前的准备: 关闭selinux,安装jdk,安装maven
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
# mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /opt/apache-maven-3.6.1
Java version: 1.8.0_151, vendor: Oracle Corporation, runtime: /opt/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.el7.x86_64", arch: "amd64", family: "unix"
环境配置:
export JAVA_HOME=/opt/jdk1.8.0_151 export PATH=$PATH:$JAVA_HOME/bin export PATH=$PATH:/opt/apache-maven-3.6.1/bin export MAVEN_HOME=/opt/apache-maven-3.6.1 export RUN_AS_USER=root
安装包地址:
https://www.sonatype.com/nexus-repository-oss
百度网盘:
链接:https://pan.baidu.com/s/1v77nB57eiYOQxI5ZBvv87w
提取码:cz79
安装Nexus:
[root@yangdong opt]# tar xf latest-unix.tar.gz #会生成 nexus-3.18.1-01 sonatype-work两个目录 [root@yangdong opt]# ls apache-maven-3.6.1 jdk1.8.0_151 latest-unix.tar.gz sonatype-work apache-maven-3.6.1-bin.tar.gz jdk-8u151-linux-x64.tar.gz nexus-3.18.1-01
启动Nexus:
[root@yangdong opt]# cd nexus-3.18.1-01/bin/ [root@yangdong bin]# ./nexus start WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ Starting nexus
[root@yangdong nexus-3.18.1-01]# ./bin/nexus status
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
nexus is running.
配置Nexus:
访问地址:http://192.168.105.233:8081
初始用户:admin 密码:cat /opt/sonatype-work/nexus3/admin.password
建立仓库:
这个时候我们就已经部署好了,只需要在客户端配置repo文件就可以了。
#yum clean all #yum makecache [root@yangdong ~]# cd /etc/yum.repos.d/ [root@yangdong yum.repos.d]# ls nexus.repo repot [root@yangdong yum.repos.d]# cat nexus.repo [nexus] name=Nexus Yum Repository baseurl=http://192.168.105.233:8081/repository/yumGroup/$releasever/os/$basearch/ enabled=1 gpgcheck=0
这个时候你可能会报错:
[root@yangdong yum.repos.d]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors http://192.168.105.233:8081/repository/yumGroup/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 401 - Unauthorized Trying other mirror.
是因为你是匿名用户访问Nexus,因此认证不通过。需要打开匿名用户的权限。
这时候我们下载一个包试试:
[root@yangdong yum.repos.d]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status nexus/7/x86_64 Nexus Yum Repository 10,019 repolist: 10,019 [root@yangdong yum.repos.d]# yum -y install httpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed --> Processing Dependency: httpd-tools = 2.4.6-88.el7.centos for package: httpd-2.4.6-88.el7.centos.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.centos.x86_64 --> Running transaction check ---> Package httpd-tools.x86_64 0:2.4.6-88.el7.centos will be installed ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================= Installing: httpd x86_64 2.4.6-88.el7.centos nexus 2.7 M Installing for dependencies: httpd-tools x86_64 2.4.6-88.el7.centos nexus 90 k mailcap noarch 2.1.41-2.el7 nexus 31 k Transaction Summary ======================================================================================================================================================================= Install 1 Package (+2 Dependent packages) Total download size: 2.8 M Installed size: 9.6 M Downloading packages: (1/3): httpd-tools-2.4.6-88.el7.centos.x86_64.rpm | 90 kB 00:00:00 (2/3): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00 (3/3): httpd-2.4.6-88.el7.centos.x86_64.rpm | 2.7 MB 00:00:00 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 2.7 MB/s | 2.8 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mailcap-2.1.41-2.el7.noarch 1/3 Installing : httpd-tools-2.4.6-88.el7.centos.x86_64 2/3 Installing : httpd-2.4.6-88.el7.centos.x86_64 3/3 Verifying : httpd-tools-2.4.6-88.el7.centos.x86_64 1/3 Verifying : mailcap-2.1.41-2.el7.noarch 2/3 Verifying : httpd-2.4.6-88.el7.centos.x86_64 3/3 Installed: httpd.x86_64 0:2.4.6-88.el7.centos Dependency Installed: httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7 Complete!
可以看到我们的仓库已经识别到了Nexus,同时我们下载了httpd的包。这时候我们去Nexus上看下是否缓存了。
可以看到我们的Nexus已经缓存到了本地,下载在有客户端现在httpd就可以直接从Nexus获取了。
同时,Nexus也可做maven的缓存,这个后期有需要的时候会继续更新!
#批量上传本地的rpm包:
for i in `ls /var/centos6`; do curl -v --user 'admin:admin123' --upload-file $i http://192.168.105.233:8081/repository/yumDev/$i; done