二、配置双机ssh信任
unison同步远程目录时要登录到远程服务器,配置互相信任
1,在俩台机器上创建RSA密钥
(1)以root用户登录
(2)在root用户的主目录内创建.ssh目录并设置正确的权限
[iyunv@104 ~]# mkdir ~/.ssh
[iyunv@104 ~]# chmod -R 700 ~/.ssh
(3)使用sshh-keygen命令生产RSA密钥
[iyunv@104 ~]# 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:
75:e4:e8:90:47:3b:c3:60:7a:6d:85:a0:45:db:c1:9e root@104
The key's randomart image is:
+--[ RSA 2048]----+
| .*oo.o |
| = OoB |
| o =.%.o |
| . *E+ |
| S . |
| |
| |
| |
| |
+-----------------+
2、#添加密钥到授权密钥文件中
(1)以root用户登录
(2)在本机执行:
[iyunv@104 ~]# cd ~/.ssh
[iyunv@104 .ssh]# ssh "-p 22" 192.168.9.104 cat /root/.ssh/id_rsa.pub >> authorized_keys
[iyunv@104 .ssh]# ssh "-p 22" 192.168.9.106 cat /root/.ssh/id_rsa.pub >> authorized_keys
[iyunv@104 .ssh]# scp authorized_keys 192.168.9.106:/root/.ssh/ root@192.168.9.106's password:
authorized_keys 100% 780 0.8KB/s 00:00
[iyunv@104 .ssh]# chmod 600 /root/.ssh/authorized_keys
(3)在106机器上执行
[iyunv@106 ~]# chmod 600 /root/.ssh/authorized_keys
(4)验证测试
[iyunv@104 .ssh]# ssh 192.168.9.104 date
Wed Aug 31 12:10:27 CST 2016
[iyunv@104 .ssh]# ssh 192.168.9.106 date
Wed Aug 31 12:10:46 CST 2016
[iyunv@106 ~]# ssh 192.168.9.104 date
The authenticity of host '192.168.9.104 (192.168.9.104)' can't be established.
RSA key fingerprint is 57:83:da:b9:ee:de:2a:1f:f1:74:da:ec:43:fa:7b:56.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.9.104' (RSA) to the list of known hosts.
Wed Aug 31 12:11:10 CST 2016
[iyunv@106 ~]# ssh 192.168.9.106 date
The authenticity of host '192.168.9.106 (192.168.9.106)' can't be established.
RSA key fingerprint is 67:ff:e7:b0:5f:3b:46:e9:d7:8d:e1:10:21:02:8b:ce.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.9.106' (RSA) to the list of known hosts.
Wed Aug 31 12:11:30 CST 2016
#不需要输入密码就能显示系统日期,说明ssh互相信任配置成功
三、编译安装inotify
#inotify特性需要Linux内核的支持,安装inotify-tools确认系统内核为2.6.13版本以上,
[iyunv@104 ~]# uname -r
2.6.32-431.el6.x86_64
[iyunv@104 ~]# ls -l /proc/sys/fs/inotify
total 0
-rw-r--r-- 1 root root 0 Aug 30 12:28 max_queued_events
-rw-r--r-- 1 root root 0 Aug 30 12:28 max_user_instances
-rw-r--r-- 1 root root 0 Aug 30 12:28 max_user_watches
如果有上面三项输出,表示系统已经默认支持inotify,接着就可以开始安装inotify-tools了。
[iyunv@104 ~]# cd /usr/local/src/
[iyunv@104 src]# wget http://github.com/downloads/rvoi ... y-tools-3.14.tar.gz
[iyunv@104 src]# tar xf inotify-tools-3.14.tar.gz
[iyunv@104 src]# cd inotify-tools-3.14
[iyunv@104 inotify-tools-3.14]# ./configure
[iyunv@104 inotify-tools-3.14]# make
[iyunv@104 inotify-tools-3.14]# make install
[iyunv@104 inotify-tools-3.14]# ll /usr/local/bin/inotifywa*
-rwxr-xr-x 1 root root 44287 Aug 31 12:23 /usr/local/bin/inotifywait
-rwxr-xr-x 1 root root 41377 Aug 31 12:23 /usr/local/bin/inotifywatch
#inotify-tools安装完成后,会生成inotifywait和inotifywatch两个指令,其中,inotifywait用于等待文件或文件集上的一个特定事件,它可以监控任何文件和目录设置,并且可以递归地监控整个目录树。
inotifywatch用于收集被监控的文件系统统计数据,包括每个inotify事件发生多少次等信息。
四,配置unison,测试同步zabbix的php目录
#104编写脚本
[iyunv@104 ~]# vim /data0/inotify.sh