分布式监控系统Zabbix-3.0.3的安装记录
环境说明
zabbix-server:192.168.1.30 #zabbix的服务端(若要监控本机,则需要配置本机的Zabbix agent,下面会提到)
zabbix-agent:192.168.1.7 #zabbix的客户端(被监控端,需要配置Zabbix agent,下面会提到)
一、zabbix-server端的操作记录(192.168.1.30 )
zabbix服务器端要提前安装好LNMP环境(mysql,nginx,php5的安装目录均是/usr/local)
创建Zabbix运行的用户:
[[email protected] ~]# groupadd zabbix
[[email protected] ~]# useradd -g zabbix zabbix
安装libcurl和net-snmp:
[[email protected] ~]# yum install net-snmp-devel curl-devel
安装Fping:
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget -c http://fping.org/dist/fping-3.4.tar.gz
[[email protected] src]# tar zxvf fping-3.4.tar.gz
[[email protected] src]# # cd fping-3.4
[[email protected] fping-3.4]# ./configure
[[email protected] fping-3.4]# make && make install
[[email protected] fping-3.4]# chown root:zabbix /usr/local/sbin/fping
[[email protected] fping-3.4]# chmod 4710 /usr/local/sbin/fping
安装Zabbix Server:
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget -c http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz/download
[[email protected] src]# tar zxvf zabbix-3.0.3.tar.gz
[[email protected] src]# cd zabbix-3.0.3
[[email protected] zabbix-3.0.3]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl
[[email protected] zabbix-3.0.3]# make && make install
Zabbix Server配置与启动
创建Zabbix数据库和MySQL用户:
[[email protected] ~]# mysql -p
........
mysql> create schema zabbix character set utf8;
Query OK, 1 row affected (0.05 sec)
mysql> create user ‘zabbix‘@‘%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.16 sec)
mysql> grant all on zabbix.* to ‘zabbix‘@‘%‘;
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
导入Zabbix初始数据:
切换到zabbix的解压目录下,这里是/usr/local/src目录下
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# cd zabbix-3.0.3
[[email protected] zabbix-3.0.3]#cd database/mysql/
[[email protected] mysql]# pwd
/usr/local/src/zabbix-3.0.3/database/mysql
[[email protected] mysql]# ls
data.sql images.sql schema.sql
[[email protected] mysql]# mysql -uroot - #登陆mysql,进行zabbix初始数据导入
mysql> set sql_log_bin=0;
mysql> source ./schema.sql;
mysql> source ./images.sql;
mysql> source ./data.sql;
mysql> set sql_log_bin=1;
编辑/usr/local/zabbix/etc/zabbix_server.conf:
[[email protected] ~]#vim /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=192.168.1.30
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBPort=3306
FpingLocation=/usr/local/sbin/fping
从安装目录拷贝zabbix_server脚本,并编辑:
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# cd zabbix-3.0.3
[[email protected] zabbix-3.0.3]# cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/
[[email protected] zabbix-3.0.3]# mkdir -p /usr/local/zabbix/logs
[[email protected] zabbix-3.0.3]# chown -R zabbix:zabbix /usr/local/zabbix
[[email protected] zabbix-3.0.3]# vim /etc/init.d/zabbix_server
[[email protected] zabbix-3.0.3]# cat /etc/init.d/zabbix_server
...
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"
CONF_FILE="/usr/local/zabbix/etc/zabbix_server.conf"
...
start() {
...
daemon $ZABBIX_BIN -c $CONF_FILE
...
}
调整防火墙规则(开放端口10051):
[[email protected] ~]# vim /etc/sysconfig/iptables
...
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
...
[[email protected] ~]# /etc/init.d/iptables restart
启动Zabbix Server:
[[email protected] ~]# service zabbix_server start #也可以直接/usr/local/zabbix/sbin/zabbix_server方式启动
Starting Zabbix Server: [ OK ]
停止Zabbix Server:
[[email protected] ~]# service zabbix_server stop
Stopping Zabbix Server: [ OK ]
配置开机自动启动:
[[email protected] ~]# chkconfig --add zabbix_server
[[email protected] ~]# chkconfig --level 35 zabbix_server on
Zabbix的Web前端
在安装目录将frontends拷贝到指定的web root:
[[email protected] ~]# mkdir -p /data/www/zabbix
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# cd zabbix-3.0.3
[[email protected] zabbix-3.0.3]#cp -a frontends/php/* /data/www/zabbix/
[[email protected] zabbix-3.0.3]# chown -R www:www /data/www/zabbix
Nginx配置:
[[email protected] ~]# cat /usr/local/nginx/conf/nginx.conf
...
server {
listen 80;
server_name zabbix.zrwm.com;
error_log logs/zabbix_error.log;
access_log logs/zabbix_access.log;
root /data/www/zabbix;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
...
php.ini配置:
[[email protected] ~]# cat /usr/local/php5/etc/php.ini
...
memory_limit = 128M
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
session.auto_start = 0 ;必须为0
mbstring.func_overload = 2
...
注:PHP需要至少开启扩展:gd,bcmath,ctype,libXML,xmlreader,xmlwriter,session,sockets,mbstring,gettext,mysql
如下,查看是否包括了上面所提到的扩展模块
[[email protected] ~]# /usr/local/php5/bin/php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib
[Zend Modules]
访问Web界面http://zabbix.zrwm.com,进行相关web配置,配置完成后使用默认用户admin(密码:zabbix)登陆即可.
二、zabbix客户端的操作记录(192.168.1.7)
安装Zabbix,配置Zabbix agent:
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# wget -c wget -c http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz/download
[[email protected] src]# cd zabbix-3.0.3
[[email protected] zabbix-3.0.3]# ./configure --prefix=/usr/local/zabbix --enable-agent
[[email protected] zabbix-3.0.3]# make && make install
[[email protected] zabbix-3.0.3]# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
配置zabbix_agentd:
[[email protected] ~]# groupadd zabbix
[[email protected] ~]# useradd -g zabbix zabbix
[[email protected] ~]# mkdir -p /usr/local/zabbix/logs
[[email protected] ~]# chown zabbix:zabbix -R /usr/local/zabbix/
[[email protected] ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
[[email protected] ~]# cat /usr/local/zabbix/etc/zabbix_agentd.conf
...
PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Server=192.168.1.30
ListenPort=10050
ServerActive=192.168.1.30
Hostname=192.168.1.7
Timeout=15
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
...
配置Zabbix Agent启动脚本:
[[email protected] ~]# cat /etc/init.d/zabbix_agentd
...
prog="Zabbix Agent"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
CONF_FILE="/usr/local/zabbix/etc/zabbix_agentd.conf"
...
start() {
...
daemon $ZABBIX_BIN -c $CONF_FILE
...
}
...
开启防火墙端口10050:
[[email protected] ~]# cat /etc/sysconfig/iptables
...
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
...
[[email protected] ~]# /etc/init.d/iptables restart
启动zabbix_agentd:
[[email protected] ~]# /etc/init.d/zabbix_agentd start
Starting Zabbix Agent: [ OK ]
配置开机自动启动:
[[email protected] ~]# chkconfig --add zabbix_agentd
[[email protected] ~]# chkconfig --level 35 zabbix_agentd on
测试下zabbix agent是否正常工作:
[[email protected] ~]# /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf -t system.uptime
system.uptime [u|68301]
到此,zabbix3.0.3监控系统的基本环境安装完成~后续会更新zabbix监控项添加的操作记录,敬请期待~~