搭建本地repo源:
使用rpm包,在CentOS上搭建本地源,方便机器直接yum安装软件,以安装saltstack和ansible为例,本文非常适合不能上网,啥也没装的虚拟机。
1)挂载CentOS7系统镜像
# mkdir /mnt/centos70
# mount -o loop CentOS-7-x86_64-Everything-1611.iso /mnt/centos70/
2)设置本地repo文件
# vi /etc/yum.repos.d/local.repo
[Centos7]
name=Centos7.0
baseurl=file:///mnt/centos70
enabled=1
gpgcheck=0
3)从镜像安装createrepo、httpd,设置防火墙端口
# yum install createrepo httpd
# firewall-cmd --list-ports
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --reload
4)解压安装包(这边压缩包里面放了需要的rpm包,saltstack的直接官网下载),createrepo命令给安装包创建索引。
# tar –zcvf ansible-2.3.tar.gz –C /var/www/html/
# tar –zcvf salt2017.7.0.tar.gz –C /var/www/html/
# cd /var/www/html/
# createrepo --update salt2017.7.0
# createrepo --update ansible-2.3.0
5)添加salt和ansible的repo配置
[root@centos7-1406 html]# cat /etc/yum.repos.d/local.repo
[Centos7]
name=Centos7.0
baseurl=file:///mnt/centos7
enabled=0 #设置禁止
gpgcheck=0
[salt]
name=salt2017.7.0
baseurl=http://<yum server ip addr>/salt2017.7.0
enabled=1
gpgcheck=0
[ansible-2.3]
name=ansible-2.3
baseurl=http:// <yum server ip addr>/ansible-2.3.0
enabled=1
gpgcheck=0
6)在其他机器上,就可以刷新repo、安装salt和ansible
# yum clean all
# yum makecache
# yum repolist
# yum install salt salt-master salt-ssh
# yum install ansible
7)ansible的winrm安装
# python get-pip.py --no-index --find-links=pkgs/
# pip install --no-index --find-links=pkgs/ -r winrm.txt
8)else:如果pip没安装的话,先离线安装pip:
#先安装pip,pip和wheel都要放在pkgs里面
# python get-pip.py --no-index --find-links=pkgs/
Tips:如果遇到http报错权限问题,修改SELinux策略:
/ansible-2.3.0/repodata/repomd.xml: [Errno 14] HTTP Error 403 - Forbidden
Trying other mirror.
# chcon -R -t httpd_user_content_t /var/www/html/