上一篇讲了如何快速安装数百台服务器,本篇讲局域网yum源站和ntp时间同步服务器搭建
一,局域网YUM源站
安装相关软件包
继续在管理机192.168.128.10上操作
yum install httpd yum-utils wget createrepo reposync -y
systemctl enable httpd && systemctl start httpd
修改管理机的yum源为阿里镜像源
修改为阿里镜像源可以提升速度
mkdir /etc/yum.repos.d/repobak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repobak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
同步阿里源到本地
mkdir -p /var/www/html/centos/7/{os,extras}
mkdir -p /var/www/html/epel/7
同步base源到本地:
reposync -r base -p /var/www/html/centos/7/os --norepopath
同步extras源到本地:
reposync -r base -p /var/www/html/centos/7/extras --norepopath
同步epel源到本地:
reposync -r epel -p /var/www/html/epel/7 --norepopath
创建YUM仓库,生成repodata目录并自动创建索引信息
createrepo -pdo /var/www/html/centos/7/os /var/www/html/centos/7/os
createrepo -pdo /var/www/html/centos/7/extras /var/www/html/centos/7/extras
createrepo -pdo /var/www/html/epel/7 /var/www/html/epel/7
定时同步本地yum源
vim /root/reposync.sh
#!/bin/bash
datetime=`date +"%Y-%m-%d"`
##epel
echo $datetime >>/var/log/reposync_epel.log
reposync -r epel -p /var/www/html/epel/7 --norepopath >>/var/log/reposync_epel.log
createrepo --update /var/www/html/epel/7 >>/var/log/reposync_epel.log
##os
echo $datetime >>/var/log/reposync_os.log
reposync -r os -p /var/www/html/centos/7/os --norepopath >>/var/log/reposync_os.log
createrepo --update /var/www/html/centos/7/os >>/var/log/reposync_os.log
##extras
echo $datetime >>/var/log/reposync_extras.log
reposync -r extras -p /var/www/html/centos/7/extras --norepopath >>/var/log/reposync_extras.log
createrepo --update /var/www/html/centos/7/extras >>/var/log/reposync_extras.log
#定时任务
crontab -e
0 3 * * 6 /bin/bash /root/reposync.sh
二,时间同步服务器搭建
继续在管理机192.168.128.10上操作
yum install chrony -y
systemctl start chronyd && systemctl enable chronyd
修改时间源为阿里时间源
sed -i ‘s/0.centos.pool.ntp.org/ntp1.aliyun.com/g’ /etc/chrony.conf
sed -i ‘s/1.centos.pool.ntp.org/ntp2.aliyun.com/g’ /etc/chrony.conf
sed -i ‘s/2.centos.pool.ntp.org/ntp3.aliyun.com/g’ /etc/chrony.conf
sed -i ‘s/3.centos.pool.ntp.org/ntp4.aliyun.com/g’ /etc/chrony.conf
echo “allow 192.168.128.0/24” >>/etc/chrony.conf
systemctl restart chronyd
firewall-cmd --permanent --add-rich-rule “rule family=ipv4 source address=“192.168.128.0/24” service name=“ntp” accept”
firewall-cmd --reload