一、服务器规划:
IP地址 |
服务器名称 |
主机名 |
192.168.1.210 |
zabbix-server |
node1.test.com |
192.168.1.211 |
zabbix-agent |
node1.test.com |
二、搭建环境
2.1 安装软件
[root@node1 ~]# yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
[root@node1 ~]# vi /etc/httpd/conf/httpd.conf
ServerName 192.168.1.210 (或者node1.test.com) //修改为主机名
DirectoryIndex index.html index.php //修改
:wq
[root@node1 ~]# vi /etc/php.ini
date.timezone = PRC //修改为中国时区
:wq
[root@node1 ~]# systemctl stop firewalld.service
[root@node1 ~]# setenforce 0
[root@node1 ~]# systemctl start httpd.service //启动httpd服务
[root@node1 ~]# systemctl start mariadb.service //启动mariadb服务
启动端口:
[root@node1 ~]# netstat -lntup | grep 80
tcp6 0 0 :::80 :::* LISTEN 1549/httpd
[root@node1 ~]# netstat -lntup | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1778/mysqld
[root@node1 ~]#
2.2初始化数据库
[root@node1 ~]# mysql_secure_installation //初始化mysql数据库,并配置root用户密码
其余选项一直n就可以了,出现下面这几句就说明设置成功了:
2.3测试LAMP搭建
[root@node1 ~]# vi /var/www/html/index.php //创建一个测试页,测试LAMP是否搭建成功
<?php
phpinfo();
?>
:wq
访问http://192.168.1.210,出现如下页面则说明测试成功:
2.4创建zabbix库
[www.aa.com@ ~]# mysql -u root -p123456 //root用户登陆数据库
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; //创建zabbix数据库(中文编码格式)
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY '123456'; //授予zabbix用户zabbix数据库的所有权限,密码123456
MariaDB [(none)]> flush privileges; //刷新权限
MariaDB [(none)]> quit //退出数据库
[www.aa.com@ ~]# vi /var/www/html/index.php //修改测试页内容,测试zabbix用户是否能够登陆数据库
<?php
$link=mysql_connect('192.168.1.210','zabbix','123456');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>
:wq
访问http://192.168.1.210,出现如下页面则说明测试成功:
三zabbix部署
[root@node1 ~]# rpm -ivh php-mbstring-5.4.16-42.el7.x86_64.rpm
[root@node1 ~]# rpm -ivh php-bcmath-5.4.16-42.el7.x86_64.rpm //安装zabbix所需要EPEL源和zabbix的yum源
[root@node1 ~]#rpm -ivh rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm //下载这个rpm包需要公网环境,会自动生成yum源文件
[root@node1 ~]# yum install zabbix-server-mysql zabbix-web-mysql -y //安装依赖包
[root@node1 ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p -h 192.168.1.210 zabbix
//以上为导入数据到数据库zabbix中(最后一个zabbix是数据库zabbix),且因为用户zabbix是%(任意主机),所以登录时需要加上当前主机ip(-h 192.168.1.210),密码是用户zabbix登陆密码123456
[root@node1 ~]# vi /etc/zabbix/zabbix_server.conf //配置数据库用户及密码,修改如下配置代码行
[root@node1 ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
92:DBHost=192.168.1.210
100:DBName=zabbix
116:DBUser=zabbix
125:DBPassword=123456
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
376:ListenIP=192.168.1.210
474:Timeout=4
517:AlertScriptsPath=/usr/lib/zabbix/alertscripts
528:ExternalScripts=/usr/lib/zabbix/externalscripts
564:LogSlowQueries=3000
[root@node1 ~]#
[root@node1 ~]# vi /etc/httpd/conf.d/zabbix.conf //修改时区
php_value date.timezone Asia/Shanghai
:wq
[root@node1 ~]# systemctl enable zabbix-server
[root@node1 ~]# systemctl start zabbix-server
[root@node1 ~]# netstat -anpt | grep zabbix //监听在10051端口上,如果没监听成功,可重启zabbix-server服务试试
tcp 0 0 192.168.1.210:10051 0.0.0.0:* LISTEN 6114/zabbix_server
[Z3001] connection to database 'zabbix' failed: [2003] Can't connect to MySQL server on '192.168.1.210' (13)
解决方案:关闭selinux防火墙(临时、永久)
[root@node1 ~]# systemctl restart httpd.service
访问http://192.168.1.210/zabbix/ //注意这里IE浏览器打不开,最好用火狐或者360等浏览器
设置中文环境:Administrator-Users-点击用户Admin-语言中设置,效果如下:
四、部署zabbix-agent
[root@node1 ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
[root@node1 ~]# yum install -y zabbix-agent
[root@node1 ~]# vim /etc/zabbix/zabbix_agentd.conf
[root@node1 ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf
13:PidFile=/var/run/zabbix/zabbix_agentd.pid
32:LogFile=/var/log/zabbix/zabbix_agentd.log
43:LogFileSize=0
98:Server=192.168.1.210
139:ServerActive=127.0.0.1
150:Hostname=node1.test.com
268:Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@node1 ~]# systemctl stop firewalld
[root@node1 ~]# setenforce 0
[root@node1 ~]# systemctl restart zabbix-agent.service
[root@node1 ~]# netstat -lntup | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 11012/zabbix_agentd
tcp 0 0 192.168.1.210:10051 0.0.0.0:* LISTEN 6114/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 11012/zabbix_agentd
[root@node1 ~]#