http://hermannsspace.de/wp/collect-pnp4nagios-data-in-check_mk-distributed-environment
slave1数据目录
/opt/omd/sites/slave1/var/pnp4nagios/perfdata
slave1是从服务器id,根据实际情况替换
global配置信任登录
ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ''
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 10.0.70.105
global定时同步脚本
cat /opt/sync_cmk_perfdata.sh
#!/bin/bash
perfdata_path="/opt/omd/sites/global/var/pnp4nagios/perfdata/"
SITES=(slave1:10.0.70.105)
for site in ${SITES[*]}
do
site_id=$(echo $site|cut -d : -f 1)
site_host=$(echo $site|cut -d : -f 2)
#获取远程rrd文件列表
rrd_files=$(ssh root@$site_host find /opt/omd/sites/$site_id/var/pnp4nagios/perfdata -name *.rrd)
#远程rrdcache写入磁盘
ssh root@$site_host /omd/sites/$site_id/bin/rrdtool flushcached -d unix:/omd/sites/$site_id/tmp/run/rrdcached.sock $rrd_files
#远程rrd同步到本地
rsync -avz root@$site_host:/opt/omd/sites/$site_id/var/pnp4nagios/perfdata/ $perfdata_path
#替换xml中的远程site_id为本地site_id
find $perfdata_path -name "*.xml" |xargs sed -i "s/sites\/$site_id/sites\/global/g"
done
# crontab -l
*/5 * * * * /opt/sync_cmk_perfdata.sh >/dev/null 2>&1
global配置apache rewrite
cat /opt/omd/apache/multisite_proxy.conf
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/(slave1|slave2|slave3)/(.*) http://10.0.70.104/global/$2 [P]