我这里的监控是使用zabbix,刚开始接触比较费劲,但慢慢的看文档边做边看就好多了,现在回头来看还是zabbix比较好,建议大家可以多看看。

现在来介绍一下zabbix的服务端与客户端的安装

一、服务端的安装(版本是2.0.6)

安装基本依赖包

1
yum install mysql-server mysql-devel libcurl-devel net-snmp-devel php php-gd php-xml php-mysql php-mbstring php-bcmath httpd

关于php与mysql的安装也可以选择源码编译的。

1、下载zabbix包,然后上传到tmp目录,并解压

1
tar zxvf zabbix- 2.0 . 6 .tar.gz

2、创建用户

1
2
groupadd zabbix
useradd -g zabbix zabbix

3、创建数据库(使用mysql数据库)、用户与导入表

1
2
3
4
5
6
7
create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@ 'localhost' identified by 'zabbix' ;
flush privileges;
cd /tmp/zabbix- 2.0 . 6 /database/
mysql -uzabbix -pzabbix zabbix <mysql/schema.sql
mysql -uzabbix -pzabbix zabbix <mysql/p_w_picpaths.sql
mysql -uzabbix -pzabbix zabbix <mysql/data.sql

4、编译安装

1
2
3
cd /tmp/zabbix- 2.0 . 6
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent -- with -mysql --enable-ipv6 -- with -net-snmp -- with -libcurl
make install

5、配置

1
cd /usr/local/zabbix/etc/

下面是是我的配置

1
2
3
4
5
6
grep -v '#' zabbix_server.conf|sed '/^$/d'
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/ var /lib/mysql/mysql.sock

6、启动

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
/usr/local/zabbix/sbin/zabbix_server
ps -ef|grep zabbix
zabbix 16835 1 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16836 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16837 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16838 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16839 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16840 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16841 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16842 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16843 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16844 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16845 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16846 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16847 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16848 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16849 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16850 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16854 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16855 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16856 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16860 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16861 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16862 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16865 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16866 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16868 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16871 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
zabbix 16873 16835 0 19 : 34 ? 00 : 00 : 00 /usr/local/zabbix/sbin/zabbix_server
root 16883 3771 0 19 : 34 pts/ 1 00 : 00 : 00 grep zabbix

7、配置php

1
2
3
4
sed -i 's/^\(.*\)date.timezone =.*$/date.timezone = Asia\/Shanghai/g' /etc/php.ini
sed -i 's/^\(.*\)post_max_size =.*$/post_max_size = 16M/g' /etc/php.ini
sed -i 's/^\(.*\)max_execution_time =.*$/max_execution_time = 300/g' /etc/php.ini
sed -i 's/^\(.*\)max_input_time =.*$/max_input_time = 300/g' /etc/php.ini

修改完成后别忘记重启php-fpm

8、复制web interface到www目录

1
2
3
mkdir / var /www/html/zabbix
cd /tmp/zabbix- 2.0 . 6 /frontends/php/
cp -a . / var /www/html/zabbix/

确认好web服务器配置并开启,就输入http://ip/zabbix来进行web的安装

二、web里部署

在web里安装

103849964.jpg

选择next

1、查看哪个不ok就解决

103935592.jpg

我这个是全部ok,直接next

2、输入的数据库连接信息

104319627.jpg

3、测试连接数据库

104351772.jpg

如果test connection为ok就代表成功

4、输入你的zabbix服务信息

104538425.jpg

选择next

5、之前操作的汇总

104701355.jpg

没有问题,选择next

6、先下载这个文件,然后在传到服务器里,给与777权限,修改用户与组为zabbix

104934100.jpg

然后点击retry

7、没有问题了,选择finish

105008491.jpg

默认的账户为Admin,密码为zabbix,之后就进入zabbix界面了

105038430.jpg

二、客户端的安装

客户端分linux与windows,我分别介绍一下。

1、客户端为linux

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
LANG=C
###check adapter name
zabbix_user= 'zabbix'
zabbix_install_dir= '/usr/local/zabbix'
zabbix_agent_hostname=$(hostname)
zabbix_server_port= '10051'
zabbix_agent_ip=$(/sbin/ifconfig|grep 'inet addr:' |grep -Ev '127.0.0.1' | cut -d: -f2 | awk '{if ($1~/^10.*/) {print $1} else {print $1}}' |head -n 1 )
zabbix_agent_header=$(/sbin/ifconfig|grep 'inet addr:' |grep -Ev '127.0.0.1' | cut -d: -f2 | awk '{if ($1~/^10.*/) {print $1} else {print $1}}' |head -n 1 |cut -d . -f1)
glibc_version=$(/usr/bin/ldd --version|awk 'NR==1{print $NF}' |cut -d . -f2)
function server_agent {
#check zabbix server ip
if [[ $zabbix_agent_header -eq 10 ]] && [[ $(ping -c 2 10.10 . 10.8 >>/dev/ null 2 >& 1 ;echo $?) -eq 0 ]];then
zabbix_server_ip= '10.10.10.8'
else
zabbix_server_ip= '111.111.111.149'
fi
}
function proxy_agent {
#check zabbix server ip
if [[ $zabbix_agent_header -eq 10 ]] && [[ $(ping -c 2 10.10 . 10.15 >>/dev/ null 2 >& 1 ;echo $?) -eq 0 ]];then
zabbix_server_ip= '10.10.10.15'
else
zabbix_server_ip= '222.222.222.82'
fi
}
function base {
# Check if user is root
if [ $(id -u) != "0" ]; then
echo -e "\033[1;31m Error: You must be root to run this script!\033[0m"
exit 1
fi
#check network
ping -c 2 www.baidu.com >>/dev/ null 2 >& 1
if [ $? -ne 0 ];then
echo -e "\033[1;31m Error: The host can't connect to Inetnet!\033[0m"
exit 1
fi
#check wget software
which wget >>/dev/ null 2 >& 1
if [ $? -ne 0 ];then
echo -e "\033[1;31m Error: The wget isn't install,now i will auto install one!\033[0m"
if [ $(grep -i -c "ubuntu" /etc/issue) = 0 ];then
yum install wget -y
else
apt- get install wget -y
fi
fi
which wget >>/dev/ null 2 >& 1
if [ $? -ne 0 ];then
echo -e "\033[1;31m Error: The wget install fail,please manual install wget!\033[0m"
exit 1
fi
#create user for zabbix
if [ $(grep -i -c "ubuntu" /etc/issue) = 1 ];then
/usr/sbin/useradd $zabbix_user -M -s /usr/sbin/nologin
else
/usr/sbin/useradd $zabbix_user -M -s /sbin/nologin
fi
#create directory for install zabbix
/bin/mkdir $zabbix_install_dir
local_dir=$(pwd)
#check system version
system_version=$(uname -m)
#check glibc version
if [ $glibc_version -gt 5 ];then
if [ $system_version == 'x86_64' ];then
#download zabbix agent by system version x86_64
wget http: //www.zabbix.com/downloads/2.0.6/zabbix_agents_2.0.6.linux2_6_23.amd64.tar.gz
#unpack zabbix agent to /usr/loca/zabbix
tar zxf zabbix_agents_2. 0.6 .linux2_6_23.amd64.tar.gz -C $zabbix_install_dir
else
#download zabbix agent by system version i686
wget http: //www.zabbix.com/downloads/2.0.6/zabbix_agents_2.0.6.linux2_6_23.i386.tar.gz
#unpack zabbix agent to /usr/loca/zabbix
tar zxf zabbix_agents_2. 0.6 .linux2_6_23.i386.tar.gz -C $zabbix_install_dir
fi
else
if [ $system_version == 'x86_64' ];then
#download zabbix agent
wget http: //www.zabbix.com/downloads/2.0.3/zabbix_agents_2.0.3.linux2_6.amd64.tar.gz
wget http: //www.zabbix.com/downloads/2.0.6/zabbix_agents_2.0.6.linux2_6_23.amd64.tar.gz
#unpack zabbix agent to /usr/loca/zabbix
tar zxf zabbix_agents_2. 0.6 .linux2_6_23.amd64.tar.gz -C /tmp/
tar zxf zabbix_agents_2. 0.3 .linux2_6.amd64.tar.gz -C $zabbix_install_dir
else
#download zabbix agent by system version x86_64
wget http: //www.zabbix.com/downloads/2.0.3/zabbix_agents_2.0.3.linux2_6.i386.tar.gz
wget http: //www.zabbix.com/downloads/2.0.6/zabbix_agents_2.0.6.linux2_6_23.i386.tar.gz
#unpack zabbix agent to /usr/loca/zabbix
tar zxf zabbix_agents_2. 0.6 .linux2_6_23.i386.tar.gz -C /tmp/
tar zxf zabbix_agents_2. 0.3 .linux2_6.i386.tar.gz -C $zabbix_install_dir
fi
mv /tmp/conf $zabbix_install_dir
fi
#mondiy zabbix agent conf
cd $zabbix_install_dir/conf
sed -i 's#Hostname=Zabbix server#Hostname=' $zabbix_agent_hostname '#' zabbix_agentd.conf
sed -i 's@# SourceIP=@SourceIP=' $zabbix_agent_ip '@' zabbix_agentd.conf
sed -i 's#Server=.*#Server=' $zabbix_server_ip '#' zabbix_agentd.conf
sed -i 's#ServerActive=.*#ServerActive=' $zabbix_server_ip ':' $zabbix_server_port '#' zabbix_agentd.conf
#Disable requiretty
sed -i 's/^Defaults.*.requiretty/#Defaults requiretty/' /etc/sudoers
#add check_lvm.sh content
cat >>$zabbix_install_dir/bin/check_lvm.sh <<EOF
#!/bin/bash
SIZE_1= 102400
SIZE_2= 1024
# Total lvm available
total=\`/sbin/pvdisplay|grep 'PV Size' |gawk '{print \$3}' |head -n 1 \`
# Total lvm used
used=\`/sbin/vgdisplay|grep 'Alloc PE / Size' |gawk '{print \$7}' |head -n 1 \`
# Calc total minus used
free=\`/sbin/vgdisplay|grep 'Free PE / Size' |gawk '{print \$7}' |head -n 1 \`
free_2=\`/sbin/vgdisplay|grep 'Free PE / Size' |gawk '{print \$7,\$8}' |head -n 1 \`
free_3=\$(echo "\$free*\$SIZE_2*\$SIZE_2" |bc)
FREESIZE_1=\$(echo "\$free*\$SIZE_1" |bc)
FREESIZE_2=\$(echo "\$total*\$SIZE_2" |bc)
percent=\$(echo "\$FREESIZE_1 / \$FREESIZE_2" |bc)
case \$ 1 in
lvm_total)
echo \$total
;;
lvm_used)
echo \$used
;;
lvm_free)
echo \$free_3
;;
lvm_percent)
echo \$percent
;;
*)
echo "Usage:\`basename \$0\` {lvm_total|lvm_used|lvm_free|lvm_percent}"
;;
esac
EOF
#add UserParameter
cat >>$zabbix_install_dir/conf/zabbix_agentd.conf<<EOF
UserParameter=memcached_stats[*],(echo stats; sleep 0.1 ) | telnet 127.0 . 0.1 \$ 1 2 >& 1 | awk '/STAT \$2 / {print \$NF}'
UserParameter=mysql[*],mysql -h 127.0 . 0.1 -P 3306 -uzabbix -pzabbix -e "show global status" |grep "\<\$1\>" |cut -f2
UserParameter=redis_stats[*],redis-cli -h $zabbix_agent_ip -p \$ 1 info|grep \$ 2 |cut -d : -f2
UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$4}'
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$7}'
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$8}'
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$11}'
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$12}'
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$13}'
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$6}'
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep \$ 1 | head - 1 | awk '{print \$\$10}'
UserParameter=MongoDB.Status[*],/bin/echo "db.serverStatus().\$1" | /usr/bin/mongo admin | grep "\$2" |awk -F: '{print \$\$2}' |awk -F, '{print \$\$1}'
UserParameter=check_service_number[*],ps aux|grep "\$1" |grep -v grep|wc -l
UserParameter=check_lvm[*],/usr/bin/sudo $zabbix_install_dir/bin/check_lvm.sh \$ 1
EOF
#check check_lvm.sh in the /etc/sudoer
cmd=$(grep check_lvm /etc/sudoers|wc -l)
if [ $cmd -eq 0 ];then
echo "zabbix ALL=NOPASSWD:$zabbix_install_dir/bin/check_lvm.sh" >>/etc/sudoers
fi
#grant 755 to check_lvm.sh
chmod 755 $zabbix_install_dir/bin/check_lvm.sh
#mondiy zabbix install dir user
chown -R $zabbix_user:$zabbix_user $zabbix_install_dir
#start zabbix agent server
$zabbix_install_dir/sbin/zabbix_agentd -c $zabbix_install_dir/conf/zabbix_agentd.conf
#insert boot start to start zabbix agent server
check_rc=$(grep -c "$zabbix_install_dir/sbin/zabbix_agentd -c $zabbix_install_dir/conf/zabbix_agentd.conf" /etc/rc.local)
if [ $check_rc -eq 0 ];then
echo "$zabbix_install_dir/sbin/zabbix_agentd -c $zabbix_install_dir/conf/zabbix_agentd.conf" >>/etc/rc.local
fi
# delete rubbish
rm -rf $local_dir/zabbix_agents_2. 0.3 .linux2_6.amd64.tar.gz
rm -rf $local_dir/zabbix_agents_2. 0.6 .linux2_6_23.amd64.tar.gz
rm -rf /tmp/bin
rm -rf /tmp/sbin
rm -rf $local_dir/$(basename $ 0 )
#check zabbix agent status
if [ $(ps -ef|grep zabbix_agentd|grep -v grep|wc -l) -gt 0 ];then
echo -e "\033[1;32mZabbix agent is start!\033[0m"
exit 0
else
echo -e "\033[1;31mZabbix agent is stop!please check!\033[0m"
exit 1
fi
}
case $ 1 in
install_server_agent)
server_agent
base
;;
install_proxy_agent)
proxy_agent
base
;;
*)
echo "Usage:`basename $0` {install_server_agent|install_proxy_agent}"
;;
esac

其中10.10.10.8为server端口的内网ip,111.111.111.149为server端的ip,这个是server-client直连模式

10.10.10.15为使用proxy模式的proxy内网ip,222.222.222.82为proxy模式proxy的外网ip

注意:如果在redhat或centos系统,请使用shinstall_zabbix_agent.sh module,如果是debian或者ubuntu的话,请使用bash install_zabbix_agent.sh module。

比如你想安装agent直接连接server模式,如果是在centos系统,可以使用shinstall_zabbix_agent.sh install_server_agent,如果在ubuntu里安装可以使用bashinstall_zabbix_agent.sh install_server_agent

同时注意,如果你公司有内网dns并且能在所有zabbix的agent与server里使用的话,那么Hostname填写主机名+域名,如果没有dns,那么就使用ip。

介绍:

本脚本除了能自动化的安装zabbixagent还能实现以下功能:

1、检测当前执行脚本的用户是否为root,如果不为root就退出并提示(此安装脚本需要进行添加监控用户、修改安装目录权限等);

2、现在不需要选择网卡名称,可以自动检测出客户端的ip;

3、可以针对客户端的ip来选择zabbix服务端的ip是走内网监控的还是走外网的ip监控;

4、此脚本均能在centos、redhat、ubuntu系统上运行;

5、此脚本能自动识别本机的glibc版本,如果低于或等于2.5版本,则自动安装zabbixagent的2.03版本(此版本的zabbix agent不要求glibc版本),如果高于2.5版本就安装最新的2.04版本(此版本要求你的glibc大于2.5,如果小于的话就报glibc错误,一般centos6以上都是2.12,而ubuntu server 12.04都是2.15版本)

6、根据不同的系统,在安装zabbix用户的时候,选择不同是nologin方式;

7、增加智能判断/etc/rc.local是否有开机启动zabbix服务;

8、增加智能删除下载的安装包文件;

9、增加代理安装agent,可以选择安装server-agent模式与proxy-agent模式。

10、增加了外网连接检测,如果无法上网则停止运行脚本。

11、增加检测wget软件是否安装,没有安装会按照不同的系统使用不同的方式安装;

12、增加所有监控模板里所有服务监控的用户自定义的UserParameter到zabbix_agentd.conf里;

13、增加监控lvm参数;

14、增加选择32位系统与64位系统来下载不同的软件安装包。

下面介绍客户端为windows的脚本

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
@echo off
Set zabbix_server_ip= 10.10 . 13.8
Set zabbix_server_port= 10051
for /f "tokens=2 delims=:" %%b in ( 'ipconfig^|find /i "ip"^|find /i "ipv4"^|find /i "10"' ) do set fsip=%%b
Set fsip=%fsip: =%
echo Creating zabbix dir
mkdir c:\zabbix
mkdir c:\zabbix\conf
mkdir c:\zabbix\bin
mkdir c:\zabbix\log
echo Copying config
copy /y zabbix\conf\zabbix_agentd.win.conf C:\zabbix\conf\
echo Modiy config
echo LogFile=c:\zabbix\log\zabbix_agentd.log >> C:\zabbix\conf\zabbix_agentd.win.conf
echo SourceIP=%fsip% >> C:\zabbix\conf\zabbix_agentd.win.conf
echo Server=%zabbix_server_ip% >> C:\zabbix\conf\zabbix_agentd.win.conf
echo ServerActive=%zabbix_server_ip%:%zabbix_server_port% >> C:\zabbix\conf\zabbix_agentd.win.conf
echo Hostname=%COMPUTERNAME% >> C:\zabbix\conf\zabbix_agentd.win.conf
echo Copy start file
if exist %windir%\SysWOW64 ( set system_bit= 64 ) else set system_bit= 32
if %system_bit% EQU 64 copy /y zabbix\bin\win32 C:\zabbix\bin\
if %system_bit% EQU 32 copy /y zabbix\bin\win64 C:\zabbix\bin\
echo install zabbix service
C:\zabbix\bin\zabbix_agentd.exe -i -c C:\zabbix\conf\zabbix_agentd.win.conf
echo start zabbix service
net start "Zabbix Agent"
echo set zabbix service auto
sc config "Zabbix Agent" start= auto
echo open firewall for zabbix
netsh firewall set allowedprogram C:\zabbix\bin\zabbix_agentd.exe zabbix ENABLE

使用dos命令+bat脚本,其中10.10.13.8为server端的内网ip,采用server-client直连模式

安装的话,直接双击脚本就可以(请注意,想使用windows安装的话,使用附件里的zabbix_agent_install.rar,然后解压后双击脚本就可以安装)。

目前已经在windows 2008与2012系统上都成功运行

目前客户端为linux与windows的自动安装脚本都给大家,但请使用的时候,根据自己的需求修改下。