Welcome to Elvin's blog

#centos7 创建内网yum源 OpenStack源部署

#centos7 创建内网yum源
#centos7 自动化安装 本地 内网 web源创建、更新 createrepo http OpenStack源部署

Elven原创 http://www.cnblogs.com/elvi/p/7657770.html

 

 

# Mady by Elven

##########################################
#环境准备

#自动化安装centos7
#下载系统镜像
#http://mirrors.aliyun.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
#使用ISO镜像 + ks文件自动化安装
#安装界面选择"Install CentOS7" 按TAB键进入编辑,添加自动化安装脚本 ks=http://elven.vip/ks/c7cd.ks
#按Enter开始自动化安装


#更改grub启动项,更改等待时间,更改字符界面
[ `uname -r` = *el6* ] && { Grubcfg=/boot/grub/grub.cfg; } || { Grubcfg=/boot/grub2/grub.cfg; }
echo  "修改 $Grubcfg"
cp $Grubcfg{,.bak}
sed -i 's#timeout=5#timeout=2#g' $Grubcfg
sed -i 's#rhgb##g' $Grubcfg

#关闭selinux、防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0

#设置hostname
hostnamectl set-hostname yum

#设置固定IP
#ifconfig #查看网卡名
NetName=ens37 #网需要设置的网卡
rm -f /etc/sysconfig/network-scripts/ifcfg-$NetName
nmcli con add con-name $NetName ifname $NetName autoconnect yes type ethernet \
     ip4 172.16.11.25/24 ipv4.dns "172.16.11.14 119.29.29.29" ipv4.gateway "172.16.11.1"
nmcli connection reload #重新加载网络


#时间同步
/usr/sbin/ntpdate ntp6.aliyun.com 
echo "*/3 * * * * /usr/sbin/ntpdate ntp6.aliyun.com  &> /dev/null" > /tmp/crontab
crontab /tmp/crontab

#更换阿里源
mv /etc/yum.repos.d/CentOS-Base.repo{,.bak}
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #可选
yum clean all && yum makecache #生成缓存

#--------
#我这里单独使用一个数据盘(可选)
#fdisk快速分区,新建40G
echo -e 'n\np\n1\n\n+40G\nw' | fdisk /dev/sdb
mkfs.ext4 /dev/sdb1
e2label /dev/sdb1 /www
mkdir /www
mount -t ext4 /dev/sdb1 /www
df -h|grep /dev/sdb1
#开机挂载磁盘
echo "mount -t ext4 /dev/sdb1 /www" >>/etc/rc.d/rc.local
tail -1 /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
#--------

#########################
#yum安装配置


#设置yum下载目录
mkdir -p /www/share/yum
cp /etc/yum.conf{,.bak}
sed -i 's#^keepcache=0#keepcache=1#' /etc/yum.conf
sed -i 's/^cachedir/#cachedir/' /etc/yum.conf
sed -ir '3 icachedir=/www/share/yum/$basearch/$releasever \n' /etc/yum.conf
head /etc/yum.conf

#升级,重启
yum update -y && reboot


##########################################


#安装createrepo,http服务
yum install createrepo httpd -y

#配置http目录共享
echo '#http share
Alias /share /www/share
<Directory "/www/share">
    Options Indexes FollowSymLinks
    IndexOptions NameWidth=* DescriptionWidth=* FoldersFirst
    IndexOptions SuppressIcon HTMLTable Charset=UTF-8 SuppressHTMLPreamble
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
'>/etc/httpd/conf.d/share.conf
cp /etc/httpd/conf/httpd.conf{,.bak}
echo "
ServerName localhost
#关闭版本号显示
ServerSignature Off
ServerTokens Prod
">>/etc/httpd/conf/httpd.conf
systemctl enable httpd.service
systemctl restart httpd.service
netstat -antp|grep 'httpd'
#浏览器访问 172.16.11.25/share ,能访问即正常

#创建YUM仓库
mkdir -p /www/share/centos7_rpm
createrepo -p /www/share/centos7_rpm/

#创建源文件
echo "
[My_share]
name=My_Souce
baseurl=http://172.16.11.25/share/centos7_rpm/
gpgcheck=0
enabled=1
cost=88
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
">/www/share/Lan7.repo


## RPM更新
# yum缓存的rpm包拷贝到/www/share/centos7_rpm/
find /www/share/yum -name *.rpm |sed -r 's#.*#mv & /www/share/centos7_rpm/\n#'|bash
# #下载没有安装过的包
# yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称
# #下载已经安装过的包
# yum reinstall --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称

#更新源
createrepo --update -p /www/share/centos7_rpm/

##########################################
#rpm下载、yum更新 shell
echo '#!/bin/sh [ $# = 0 ] && { echo "更新源" /usr/bin/createrepo --update -p /www/share/centos7_rpm/ } || { echo "yum下载" yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y $* echo "更新源" /usr/bin/createrepo --update -p /www/share/centos7_rpm/ } '>yumd.sh ln -s $(pwd)/yumd.sh /usr/bin/yumd chmod +x yumd.sh # 执行 yumd 更新源 # 执行 yumd 软件1 软件2 ,就会下载相关软件并更新源 ########################################## #客户端使用源 wget -O /etc/yum.repos.d/Lan7.repo http://172.16.11.25/share/Lan7.repo #客户端测试,查看源名称 yum install httpd


##########################################

#下载OpenStack安装包(仅作为参考,根据需求添加其它组件)
yum install centos-release-openstack-pike -y #安装OpenStack官方源
yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y \
python-openstackclient openstack-selinux python-openstackclient python2-PyMySQL \
openstack-utils \
mariadb mariadb-server mariadb-galera-server python2-PyMySQL \
erlang socat rabbitmq-server \
openstack-keystone httpd mod_wsgi memcached python-memcached \
apr apr-util \
openstack-glance python-glance \
openstack-nova-api openstack-nova-conductor \
openstack-nova-console openstack-nova-novncproxy \
openstack-nova-scheduler openstack-nova-placement-api \
openstack-nova-compute python-openstackclient openstack-selinux \
openstack-neutron openstack-neutron-ml2 \
openstack-neutron-linuxbridge python-neutronclient ebtables ipset \
openstack-neutron-linuxbridge ebtables ipset \
openstack-dashboard \
openstack-cinder targetcli python-keystone lvm2 \
corosync pacemaker pcs fence-agents resource-agents \

openstack-neutron-linuxbridge

#更新源
createrepo --update -p /www/share/centos7_rpm/

##########################################



#Elven原创 http://www.cnblogs.com/elvi/p/7657770.html

 

posted @ 2017-10-12 20:16  blog-elvin-vip  阅读(6409)  评论(0编辑  收藏  举报