公司上线了一套云平台后(如openstack),在提升企业高效创建虚机能力之后,客户对于每个虚机进行yum源安装软件包问题很头疼,
很多用户还是通过之前的老方式:上传iso文件--->挂载到本地文件目录--->配置本地的yum源,但是作为一个云平台,这种功能和操作的
方式太过于“鸡肋”,加上因为生产环境中无法连接互联网,所以也没办法使用网上的yum源(如ali的yum源)。
解决办法:
通过在云平台上创建一台本地的yum源虚机,这样只需要在该虚机上配置好相应的iso包的yum配置,其他局域网可通的虚机直接
复制使用repo文件即可。方便快捷。。1、创建本地系统iso,进行配置相关安装包安装
[root@yum-source-centos ~]# mkdir /yum-iso [root@yum-source-centos ~]# mkdir /yum-source2、赋值 +x 权限给 /etc/rc.d/rc.local 可以在开机自动配置
[root@yum-source-centos ~]# chmod +x /etc/rc.d/rc.local [root@yum-source-centos ~]# cp CentOS-7.0-1406-x86_64-DVD.iso /yum-iso/ [root@yum-source-centos ~]# ll /yum-iso/ total 4050944 -rw-r--r-- 1 root root 4148166656 Apr 2 19:28 CentOS-7.0-1406-x86_64-DVD.iso [root@yum-source-centos ~]#3、关闭 & 禁用防火墙和NetworkManger
[root@yum-source-centos ~]# # stop & disable firewalld and NetworkManager [root@yum-source-centos ~]# systemctl stop firewalld systemctl disable firewalld systemctl stop NetworkManager systemctl disable NetworkManager[root@yum-source-centos ~]# systemctl disable firewalld [root@yum-source-centos ~]# systemctl stop NetworkManager [root@yum-source-centos ~]# systemctl disable NetworkManager Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. [root@yum-source-centos ~]#4、关闭禁用selinux
[root@yum-source-centos ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config [root@yum-source-centos ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three two values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted [root@yum-source-centos ~]# setenforce 0 setenforce: SELinux is disabled [root@yum-source-centos ~]#5、挂载本地的iso文件,进行yum源配置过程中所需要的软件包的安装
[root@yum-source-centos ~]# mount -o loop /yum-iso/CentOS-7.0-1406-x86_64-DVD.iso /yum-source/ mount: /dev/loop0 is write-protected, mounting read-only [root@yum-source-centos ~]# echo "mount -o loop /yum-iso/CentOS-7.0-1406-x86_64-DVD.iso /yum-source/" >>/etc/rc.local [root@yum-source-centos ~]#6、预先配置本地yum源文件,配置本地yum的目的主要为了方便搭建yum服务器时安装相关其他软件,如httpd、createrepo等。
[root@yum-source-centos ~]# cd /etc/yum.repos.d/ [root@yum-source-centos yum.repos.d]# mkdir bak [root@yum-source-centos yum.repos.d]# mv CentOS-* bak/ [root@yum-source-centos yum.repos.d]# echo "[Cenos7]" >>/etc/yum.repos.d/CentOS-Base.repo [root@yum-source-centos yum.repos.d]# echo "name = Centos7">>/etc/yum.repos.d/CentOS-Base.repo [root@yum-source-centos yum.repos.d]# echo "baseurl=file:///yum-source/">>/etc/yum.repos.d/CentOS-Base.repo [root@yum-source-centos yum.repos.d]# echo "gpgcheck=1">>/etc/yum.repos.d/CentOS-Base.repo [root@yum-source-centos yum.repos.d]# echo "enabled=1">>/etc/yum.repos.d/CentOS-Base.repo [root@yum-source-centos yum.repos.d]# echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7">>/etc/yum.repos.d/CentOS-Base.repo [root@yum-source-centos yum.repos.d]# [root@yum-source-centos yum.repos.d]# ls -rlt total 8 drwxr-xr-x 2 root root 4096 Apr 2 19:30 bak -rw-r--r-- 1 root root 118 Apr 2 19:30 CentOS-Base.repo [root@yum-source-centos yum.repos.d]# [root@yum-source-centos yum.repos.d]# cat CentOS-Base.repo [Cenos7] name = Centos7 baseurl=file:///yum-source/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [root@yum-source-centos yum.repos.d]# yum install httpd createrepo7、新建yum源目录并拷贝相关镜像文件
* 配置7.2-1511镜像的yum源配置
[root@yum-source-centos data]# mkdir -p /data/yum.repo/centos/7.2-1511/os/x86_64/Packages [root@yum-source-centos data]# mkdir -p /data/yum.repo/centos/7.2-1511/updates/x86_64/Packages [root@yum-source-centos data]# mkdir -p /data/yum.repo/tools/ [root@yum-source-centos data]# cp -R /yum-source/centos7-2-1511/Packages/* /data/yum.repo/centos/7.2-1511/os/x86_64/Packages/ [root@yum-source-centos data]# cp -R /yum-source/centos7-2-1511/repodata /data/yum.repo/centos/7.2-1511/os/x86_64 [root@yum-source-centos data]# cp -R /yum-source/centos7-2-1511/repodata /data/yum.repo/centos/7.2-1511/updates/x86_64 [root@yum-source-centos data]# cp -R /yum-source/centos7-2-1511/repodata /data/yum.repo/tools [root@yum-source-centos data]# cp -R /yum-source/centos7-2-1511/RPM-GPG-KEY-CentOS-7.2-1511 /data/yum.repo/* 配置7.0-1406镜像的yum源配置
[root@yum-source-centos data]# mkdir -p /data/yum.repo/centos/7.0-1406/os/x86_64/Packages [root@yum-source-centos data]# mkdir -p /data/yum.repo/centos/7.0-1406/updates/x86_64/Packages [root@yum-source-centos data]# mkdir -p /data/yum.repo/tools/7.0-1406 [root@yum-source-centos data]# cp -R /mnt/Packages/* /data/yum.repo/centos/7.0-1406/os/x86_64/Packages/ [root@yum-source-centos data]# cp -R /mnt/repodata /data/yum.repo/centos/7.0-1406/os/x86_64 [root@yum-source-centos data]# cp -R /mnt/repodata /data/yum.repo/centos/7.0-1406/updates/x86_64 [root@yum-source-centos data]# cp -R /mnt/repodata /data/yum.repo/tools/7.0-1406 [root@yum-source-centos data]# cp -R /mnt/RPM-GPG-KEY-CentOS-7 /data/yum.repo/RPM-GPG-KEY-CentOS-7.0-14068、yum源虚机上启动http服务:
#删除原有的/var/www/html目录
[root@yum-source-centos ~]# rm -rf /var/www/html#建立安装文件与tomcat部署目录的软连接
[root@yum-source-centos ~]# ln -s /data/yum.repo /var/www/html#启动服务
[root@yum-source-centos ~]# service httpd start#验证httpd是否成功启动
[root@yum-source-centos ~]# service httpd status#验证yum源相关资源是否能正常访问
[root@yum-source-centos ~]#wget http://10.4.8.20/RPM-GPG-KEY-CentOS-7.2-1511#如果httpd服务正常运行,但资源无法正常访问,请进行以下检查:
9、检查/etc/httpd/conf/httpd.conf相关配置是否满足访问要求
[root@yum-source-centos data]# rm -rf /var/www/html [root@yum-source-centos data]# [root@yum-source-centos data]# ln -s /data/yum.repo /var/www/html [root@yum-source-centos data]# [root@yum-source-centos data]# service httpd start Redirecting to /bin/systemctl start httpd.service [root@yum-source-centos data]# wget http://10.4.8.20/RPM-GPG-KEY-CentOS-7 -bash: wget: command not found [root@yum-source-centos data]# yum install wget Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package wget.x86_64 0:1.14-10.el7_0.1 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================= Installing: wget x86_64 1.14-10.el7_0.1 Cenos7 545 k Transaction Summary ======================================================================================================================================================================= Install 1 Package Total download size: 545 k Installed size: 2.0 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : wget-1.14-10.el7_0.1.x86_64 1/1 Verifying : wget-1.14-10.el7_0.1.x86_64 1/1 Installed: wget.x86_64 0:1.14-10.el7_0.1 Complete! [root@yum-source-centos data]# [root@yum-source-centos data]# [root@yum-source-centos data]# wget http://10.4.8.20/RPM-GPG-KEY-CentOS-7.2-1511 --2018-04-02 20:53:05-- http://10.4.8.20/RPM-GPG-KEY-CentOS-7.2-1511 Connecting to 10.4.8.20:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1690 (1.7K) Saving to: ‘RPM-GPG-KEY-CentOS-7.2-1511’ 100%[=============================================================================================================================>] 1,690 --.-K/s in 0s 2018-04-02 20:53:05 (173 MB/s) - ‘RPM-GPG-KEY-CentOS-7.2-1511’ saved [1690/1690]10、本地yum源repo配置文件
[root@yum-source-centos yum-iso]# cat /etc/yum.repos.d/CentOS-Base.repo [CentOS-7.2-1511] name=CentOS-7.2-1511 - Base baseurl=http://10.4.8.20/centos/7.2-1511/os/x86_64/ gpgcheck=1 enabled=1 gpgkey=http://10.4.8.20/RPM-GPG-KEY-CentOS-7 [CentOS-7.0-1406] name=CentOS-7.0-1406 - Base baseurl=http://10.4.8.20/centos/7.0-1406/os/x86_64/ gpgcheck=1 enabled=1 gpgkey=http://10.4.8.20/RPM-GPG-KEY-CentOS-7.0-140611、本地网络可通的局域网的其他软件的yum源配置
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ll total 28 -rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo -rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo -rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo -rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# mkdir bak [root@localhost yum.repos.d]# mv CentOS-*.repo bak/ [root@localhost yum.repos.d]# ll total 4 drwxr-xr-x 2 root root 4096 Apr 2 21:08 bak [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# vim CentOS-CentOS-7-0-1406.repo [CentOS-7.0-1406] name=CentOS-7.0-1406 - Base baseurl=http://10.4.8.20/centos/7.0-1406/os/x86_64/ gpgcheck=0 enabled=1 ~ "CentOS-Base.repo" [New] 5L, 114C written [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# yum clean all Loaded plugins: fastestmirror, langpacks Cleaning repos: CentOS-7.0-1406 Cleaning up everything [root@localhost yum.repos.d]# yum update [root@localhost yum.repos.d]# yum list
#小结:
至此本地局域网的yum源已经搭建完成了,只要网络可通,不需要为每台虚机都上传iso来yum源安装解决依赖问题
于北京后厂村 2018年4月4日 王慧 tyger
Xiomara2021_01-02
Katharina2020_01-21
Delilah2020_01-18
Nydia2018_07-15
Elizabeth2018_07-03