这里写目录标题
1、首先,必须要有ntp
也就是说首先要进行
yum install ntp
注意,由于我下载的时候,最开始没有设置阿里云的镜像,因此,最开始是没有这个包的,并且centos7也不会提供这个包,所以,必须要手动下载!
注意,是必须要下载这个!!!
有可能可以先下好ntp这个包,然后用U盘拷到Centos下面直接本地安装就可以了。强烈建议安装yum镜像,否则下载时间把你等到气死!
下面分享如何设置yum 镜像问题
因为我下载的Centos7版本自带了wget和curl所以直接下载就好了,如果没有那么只有这样子了
wget:
yum install wget
curl:
yum install curl
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
更新镜像源
清除缓存:yum clean all
生成缓存:yum makecach
备份CentOS 7系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo命令:
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
找到yum源的配置路径
cd /etc/yum.repos.d
打开CentOS-Base.repo文件:
vim CentOS-Base.repo
将文件中的所有http开头的地址更改为https
最后更新yum
yum update
2、给机器设置同步IP
首先给每台机器设置ntp服务开机自启动,但不要启动服务
关闭ntpd
systemctl stop ntpd.service
开机启动
chkconfig ntpd on
然后找到/etc/ntp.conf文件
vim /etc/ntp.conf
修改为如下内容,可以保留注释
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
# 这里一定要清楚自己的ip地址,由于我的机器手动设置的静态IP是
#192.168.10.15-192.168.10.17,所以这里我就应该设置为
#192.168.10.0意思就是说允许192.168.10.0到192.168.10.254网段内的服务器
# 访问,千万注意。还有右面的子网掩码,我特地调为255.255.255.0为的就是几
# 台机器的子网掩码一致,否则出问题也不知道在哪里
# 允许192.168.10.0网段内所有机器从node1同步时键
restrict 192.168.21.0 mask 255.255.255.0 nomodify notrap
# node01通过外网同步时间的服务器列表,注释掉的是默认的
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
# 由于我的机器没有连接外网,所以我没有设置,可以参考设置一下
# 中国国家授时中心服务器地址
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
# 我的机器没有设置这个内容
# 允许上层时间服务器主动修改本机时间
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery
restrict 3.cn.pool.ntp.org nomodify notrap noquery
# 使用本地时间作为时间服务器
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
# 同步时间后,写到硬件中
SYNC_HWCLOCK=yes
到这里主节点node1已经配置完毕,我们先启动Node1,然后配置Node2和Node3即可
这里是启动服务器时间
systemctl start ntpd.service
配置机器二(Node2)和机器三(Node3)其实基本上差不多的
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
# 这里一定要清楚自己的ip地址,由于我的机器手动设置的静态IP是
#192.168.10.15-192.168.10.17,所以这里我就应该设置为
#192.168.10.0意思就是说允许192.168.10.0到192.168.10.254网段内的服务器
# 访问,千万注意。还有右面的子网掩码,我特地调为255.255.255.0为的就是几
# 台机器的子网掩码一致,否则出问题也不知道在哪里
# 允许192.168.10.0网段内所有机器从node1同步时键
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
# node01通过外网同步时间的服务器列表,注释掉的是默认的
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
# 由于我的机器没有连接外网,所以我没有设置,可以参考设置一下
# 中国国家授时中心服务器地址
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
# 我的机器没有设置这个内容
# 允许上层时间服务器主动修改本机时间
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery
restrict 3.cn.pool.ntp.org nomodify notrap noquery
# 外部时间服务器不可用时,以本地时间作为时间服务这里大约是10分钟更新一次
# 允许主时间服务器修改本地时间
restrict 192.168.10.20 nomodify notrap noquery
# 如果主时间服务器不可用,用本地的时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
# 同步时间后,写到硬件中
SYNC_HWCLOCK=yes
同理机器三也要这么设置
最后设置好了后
分别在机器二(Node2)和机器三(Node3)
输入同步时间命令
ntpdate -u +机器的IP地址比如我的
ntpdate -u worker-20
最后的效果如下所示
机器二(Node2)和机器三(Node3)
正确的输出效果如下:
总结
1、学校实验室没有外网,真的很难受,我要一根一根的来弄网线,特别是需要记住我之前设置好的静态IP否则,我的机器SSH就不行了。。。。
2、通过安装ntp我发现了其实可以在Centos的右上角选择网络设置中,手动修改网关地址,比如IP4地址,子网掩码等等,前提你必须要记住。下次我用内网的时候,直接切换自动模式,就不用手动修改网关什么鬼的,那个静态IP设置的我很头疼。以后可以通过手动切换一下网络设置快速修改网络,哈哈哈哈哈这是我最大的收获。
3、如果是我的机器,我肯定要连外网,真的是太麻烦了,yum update有1.5个G的内容没更新。。。。。。