centos7 安装部署zabbix监控服务端和客户端
部署zabbix服务端需要LNMP环境(nginx,mysql,php),其它数据库也可以,我这里使用mysql
系统信息:
[root@localhost ]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@localhost ]# uname -r
3.10.0-693.el7.x86_64
部署zabbix服务端
首先要关闭firewall,就是防火墙(CentOS 7.0默认使用的是firewall作为防火墙)
- systemctl stop firewalld.service #停止firewall
- systemctl disable firewalld.service #禁止firewall的开机自启动
1.添加用户和组:
[root@localhost ]# useradd zabbix -s /sbin/nologin
2.安装依赖软件库:
yum install mysql-devel libcurl-devel libxml2-devel mysql-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel libevent-devel –y
3.下载zabbix源码包:
4.进入源码包进行编译安装
解压:tar xf zabbix-3.2.3.tar.gz
cd zabbix-3.2.3
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-gettext
编译源码是最容易出错的 常见的'Not found XXX library',
Not found mysqllclient library : 安装mysql-devel yum install mysql-devel -y
LIBXML2 library not found :安装libxml2-devel
cannot useunixODBC library: 安装 unixODBC-devel
Curl library not found: 安装 curl-devel
lnvalid Net-SNMP directory - unable to find net-snmp-config 安装net-snmp-config
lnvalid OPENIPMI directory - unable to find ipmiif.h 安装OpenIPMI-devel
configure: error: Unable to use libevent (libevent check failed)安装 libevent-devel
make && make install 一般来说,我们会开启SNMP监控,那么要加上 --with-snmp 如果想一步到位
--启动 server---/usr/local/zabbix/sbin/zabbix_server
下面有两个启动脚本 cp /usr/local/src/zabbix-3.2.3/misc/init.d/fedora/core5/zabbix_server /etc/init.d/
修改路径 vim /etc/init.d/zabbix_server
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"
同理agent也是 --启动agent--- /usr/local/zabbix/sbin/zabbix_agentd
也可以使用系统启动脚本来启动:
配置 Agnet 开机启动 cp /usr/local/src/zabbix-3.2.3/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/
5.配置mysql数据库:
创建数据库,设置utf8避免zabbix中文乱码:
create database zabbix default charset utf8;
数据库用户授权:
grant all on zabbix.* to zabbix@'%' identified by 'zabbix';
刷新生效
flush privileges;
导入以下数据库
[root@localhost mysql]# ls /usr/local/src/zabbix-3.2.3/database/mysql //你的源码包目录
data.sql images.sql schema.sql
/usr/local/mysql/bin/mysql -uzabbix -p zabbix zabbix < /usr/local/src/zabbix-3.2.3/database/mysql/schema.sql //导入顺序不能错
/usr/local/mysql/bin/mysql -uzabbix -p zabbix zabbix < /usr/local/src/zabbix-3.2.3/database/mysql/images.sql
/usr/local/mysql/bin/mysql -uzabbix -p zabbix zabbix < /usr/local/src/zabbix-3.2.3/database/mysql/data.sql
6.配置zabbix服务端
[root@wiki mysql]# vim /usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix //数据库名
DBUser=zabbix //数据库用户
DBPassword=zabbix //数据库密码
DBPort=3306 //数据库监听端口
ListenIP=服务器ip //服务器ip
LogFile=/tmp/zabbix_server.log //zabbix日志保存路径
DBHost=数据库所在服务器ip //填数据库所在的机器ip
systemctl start zabbix-server
编辑PHP配置
# vi /etc/httpd/conf.d/zabbix.conf
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
快捷修改命令
# sed -i "s/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/g" /etc/httpd/conf.d/zabbix.conf
启动Apache服务
# systemctl start httpd
开机启动Apache服务
# systemctl enable httpd
7.zabbix管理网站配置: 这个是你得项目路径 我的是根目录下的/www/zabbix 如果是apache 它默认的路径是/var/www/html
复制zabbix的web端到你的项目路径
cp zabbix-3.2.3/frontends/php/* /www/zabbix
8.访问
记得给zabbix下的conf文件权限
-----报错------
53221:20190126:143402.331 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143402.331 database is down: reconnecting in 10 seconds
53221:20190126:143412.332 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143412.332 database is down: reconnecting in 10 seconds
53221:20190126:143422.332 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143422.332 database is down: reconnecting in 10 seconds
53221:20190126:143432.332 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143432.333 database is down: reconnecting in 10 seconds
53221:20190126:143442.333 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143442.333 database is down: reconnecting in 10 seconds
53221:20190126:143452.333 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143452.333 database is down: reconnecting in 10 seconds
53221:20190126:143502.334 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
53221:20190126:143502.334 database is down: reconnecting in 10 seconds
解决办法:
[root@localhost lib]# mkdir /var/lib/mysql
[root@localhost lib]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
重启mysql service mysqld restart