设为首页 加入收藏

TOP

Centos-一文搞懂时区时钟配置和NTP/chrony设置(二)
2023-08-26 21:10:19 】 浏览:90
Tags:Centos- 文搞懂 时区时 钟配置 NTP/chrony 设置
/ntp.conf

5-3 chrony在线环境同步远程时钟

在线环境:同步外网时钟服务器即可

#安装chrony
rpm -qa | grep chrony
yum -y remove chrony        
yum -y install chrony

#写入配置文件自动同步
mv /etc/chrony.conf /etc/chrony.conf.bakk
cat >> /etc/chrony.conf<<EOF
server ntp.ntsc.ac.cn iburst
server 127.0.0.1 iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.1.0/24
local stratum 10
logdir /var/log/chrony
EOF
cat /etc/chrony.conf
 

六、  NTP搭建集群同步时间

1、  更新阿里源、安装ntp|ntpdate

离线环境提前下载离线包

#更新阿里源
cd /etc/yum.repos.d/ 
curl -L -O https://mirrors.aliyun.com/repo/Centos-7.repo && mv ./Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
curl -L -O  http://mirrors.aliyun.com/repo/epel-7.repo && mv ./epel-7.repo /etc/yum.repos.d/epel.repo
yum clean all && yum makecache
yum install -y epel-*

#安装NTP
rpm -qa | grep ntp                    
yum -y remove ntpdate ntp        
yum -y install ntp  ntpdate

#设置时区上海
timedatectl set-timezone Asia/Shanghai    
date
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl set-timezone Asia/Shanghai

2、  离线环境:3台机器时钟同步其中一台

将192.168.1.131作为主节点,其他节点都同步它,允许同步网段设置为192.168.1.0

3、  NTP主节点配置修改

#主节点:修改配置文件
mv /etc/ntp.conf /etc/ntp.conf.bakk
cat >>/etc/ntp.conf<<EOF                
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 192.168.1.131 nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOF
cat /etc/ntp.conf
#需要把对应restrict IP和restrict网段进行修改即可

4、  NTP其他节点配置修改

#其他节点:ntp客户端配置
mv /etc/ntp.conf /etc/ntp.conf.bakk
cat >>/etc/ntp.conf<<EOF    
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 192.168.1.131   
fudge 192.168.1.131 stratum 10 
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor 
EOF
cat /etc/ntp.conf
#需要把对应server Fudge IP和restrict网段进行修改即可

● 注意:先启动主节点的NTP服务、再启动其他节点

#主节点执行同步
systemctl restart ntpd
systemctl status ntpd
#systemctl enable ntpd

 

● 同步硬件时间,检查集群同步状态,关闭chyony

#其他节点执行同步
ntpdate -u 192.168.1.131

#同步硬件时间
sed -i 's#SYNC_HWCLOCK=no#SYNC_HWCLOCK=yes#g' /etc/sysconfig/ntpdate
hwclock -w            
hwclock -r        

#检查是否成功
ntpstat
ntpq -p
timedatectl

#会冲突,需要停止chronyd.service
systemctl stop chronyd.service
systemctl disable chronyd.service

5、  开放端口123

如果无法同步,请检查防火墙是否开放端口123

netstat -lnptu | grep ntp

#关闭防火墙和selinux
systemctl stop firewalld.service
systemctl disable firewalld.service  
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
sestatus

七、  chrony搭建集群同步时间

1、  更新阿里源、安装chony

离线环境提前下载离线包

#更新阿里源
cd /etc/yum.repos.d/ 
curl -L -O https://mirrors.aliyun.com/repo/Centos-7.repo && mv ./Centos-7.repo /etc/yum.repos.d/CentOS
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【操作系统】2.进程和线程 下一篇Linux运维工程师面试题(2)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目