#centos7 建立內網yum源
#centos7 自動化安裝 本地 內網 web源建立、更新 createrepo http OpenStack源部署html
Elven原創 http://www.cnblogs.com/elvi/p/7657770.htmlpython
# Mady by Elven
##########################################
#環境準備linux
#自動化安裝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 #從新加載網絡web
#時間同步 /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安裝配置shell
#設置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 && rebootcentos
##########################################api
#安裝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-linuxbridgebash
#更新源
createrepo --update -p /www/share/centos7_rpm/
##########################################
#Elven原創 http://www.cnblogs.com/elvi/p/7657770.html