> 192.168.56.10 (作為內網時間同步服務器)
> 192.168.56.11
## 1. server端安裝ntp服務
192.168.56.10
```
yum -y install ntp
```
## 2. 修改server配置
```
vi /etc/ntp.conf
# 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
# 1. 網其他機器同步時間
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).
# 2. 中國這邊最活躍的時間服務器()
server 210.72.145.44 perfer # 中國國家受時中心
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
# allow update time by the upper server
#
# 3. 允許上層時間服務器主動修改本機時間
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# 4、外部時間服務器不可用時,以本地時間作為時間服務
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
```
**重啟ntp服務**
```
systemctl start ntpd
```
此時,兩臺時間不一樣
```
[root@localhost ~]# date
Mon May 13 20:47:12 EDT 2019
[root@localhost ~]# date
Mon May 13 08:45:44 EDT 2019
```
## 3. client同步server時間
讓client(192.168.56.11)去時間服務器上同步時間,ntpdate命令用于同步更新互聯網時間,或者NTP服務器時間
安裝ntpdate 命令
```
yum install ntpdate -y
```
與時間服務器同步時間
```
ntpdate 192.168.56.10
```
## 4. 定時任務
```
30 5 * * * root /usr/sbin/ntpdate -u pool.ntp.org && /sbin/clock --systohc
```
每天5點半同步時間,clock --systohc是硬盤時間同步系統時間的意思。
## 5. client與server同步的另一種方式
這種方式麻煩
1、客戶端安裝ntp服務
2、配置客戶端去同步時間服務器的時間
- Linux
- 高級
- 殺毒
- 記一次中毒事件
- clamav查毒軟件
- 處理挖礦病毒
- 定時任務
- kill
- chattr文件保護
- 運行級別
- Linux啟動
- 文件加密
- ssh免密登錄
- .ssh
- 問題
- 腳本
- 阿里云域名解析
- yum源
- 時間同步
- keepalived實現高可用
- dos字符與unix字符
- 大文件上傳
- 基礎
- proc目錄
- 設置宋體
- 基礎命令_01
- 基礎命令_02
- SELinux
- 文件描述符
- 基礎命令_03
- awk
- 系統日志
- date命令
- bc命令
- lsof
- vim快捷鍵
- shell
- 循環控制
- expr
- 執行腳本的方式
- declare
- shell腳本
- 控制啟停腳本
- 數值計算
- centos
- 配置網絡
- 環境
- 灰度環境
- ansible
- 模塊
- 語法
- file模塊
- setup模塊
- ping模塊
- copy模塊
- command模塊
- shell模塊
- service模塊
- cron模塊
- yum模塊
- user 模塊
- group模塊
- 指定用戶
- playbook
- 實例
- ansible安裝
- Jenkins
- shell部署
- 導入已有項目的配置
- 執行shell
- tungsten數據同步
- 防火墻
- netfilter