防火墙iptable、selinux、时间同步 是配置主机的基础
初始化:
- 关闭SELinux
- 关闭iptables,firewalld
- 配置chrony
时间同步
NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms
时间同步实现工具
-
ntp:精度在局域网内可达0.1ms,在互联网上精度在1-50ms,但是同步时间长,逐渐同步
-
chrony:实现NTP协议的软件,在互联网同步两台机器之间的精度在几毫秒,在LAN中,精度为几十微秒。CentOS7后系统自带
-
两者本质既是客户端也是服务器,客户端持续运行
clock与date命令的区别:
-
clock是显示硬件时间
-
data是显示操作系统时间,在没有配置网络时间的情况下,data会读取硬件时间
NTP
NTP服务是利用NTP协议提供时间同步服务的
NTP服务安装
yum install ntp -y
NTP配置
备份配置文件
[root@localhost ~]#cp /etc/ntp.conf{,.bak}
[root@localhost ~]#ls /etc/ntp.conf*
/etc/ntp.conf /etc/ntp.conf.bak
查看配置文件
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
# 不允许其他主机查询我的主机时间并修改
# restrict default nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
# 允许内网其他机器同步时间
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 指定互联网上时间服务器进行时间同步服务,iburst提高时间同步效率
# 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
# 其他主机和此主机时间同步,可以将IP设置为该主机IP
# 自己指定同步阿