1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| #使用ntpdate命令同步时间,并建立周期性任务
#可使用任意节点服务器作为ntp时间服务器,如各节点可上公网,可直接指定公网ntp服务器
1、安装ntp
[iyunv@node2 ~]# yum install -y ntp
[iyunv@node2 ~]# vim /etc/ntp.conf #修改配置文件允许本网段客户端获取地址
将下面的语句
restrict default kod nomodify notrap nopeer noquery
修改为
restrict default nomodify
restrict 192.168.0.0 mask 255.255.255.0 nomodify
[iyunv@node2 ~]# service ntpd start
Starting ntpd: [ OK ]
查看同步过程
[iyunv@node2 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*202.118.1.81 202.118.1.47 2 u 30 64 1 92.249 8.602 0.714
202.112.31.197 .INIT. 16 u - 64 0 0.000 0.000 0.000
2、客户端创建周期任务,每3秒同步时间
[iyunv@node1 ~]# crontab -e
*/3 * * * * /usr/sbin/ntpdate 192.168.0.16 &> /dev/null
[iyunv@node1 ~]# service crond start
#手动同步成功,因ntp一般为自动,手动前kill掉所有ntp进程即可
[iyunv@node1 ~]# ntpdate 192.168.0.16
14 Nov 20:26:09 ntpdate[3786]: adjust time server 192.168.0.16 offset -0.004440 sec
3、时间同步
[iyunv@node2 ~]# date; ssh 192.168.0.15 'date'
Mon Nov 14 20:36:17 CST 2016
root@192.168.0.15's password:
Mon Nov 14 20:36:20 CST 2016
[iyunv@node2 ~]# vim /etc/hosts
192.168.0.15 node1
192.168.0.16 node2
1、生成密钥对
[iyunv@node1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a8:ad:2c:23:83:60:ff:36:73:9d:09:24:37:ae:da:c9 root@centfils
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| . = |
| * S |
|.. o o |
|+ . . o o o |
|+ ooo*.. + |
| o +*E+ |
+-----------------+
2、把公钥传输至远程服务器对应用户的家目录
[iyunv@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.16
The authenticity of host '192.168.0.16 (192.168.0.16)' can't be established.
RSA key fingerprint is e5:84:6c:f7:c0:60:3d:0b:39:b6:1e:12:0d:48:8b:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.16' (RSA) to the list of known hosts.
root@192.168.0.16's password:
Now try logging into the machine, with "ssh 'root@192.168.0.16'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
3、测试
[iyunv@node2 ~]# date; ssh root@192.168.0.15 'date'
Mon Nov 14 21:02:30 CST 2016
Mon Nov 14 21:02:30 CST 2016
|