Zabbix监控平台—- 实践 一 监控端环境搭建
环境准备:
4台服务器,centos7 1g 1c
192.168.1.7-Zabbix+Server+WEB
192.168.1.11-Mariadb数据库
192.168.1.8-Agent
192.168.1.9-Agent
192.168.1.10-Agent
# 192.168.1.7-Zabbix+Server+WEB
[root@1-7 ~]# yum -y install lrzsz
[root@1-7 ~]# yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI # 安装依赖工具,依赖库
[root@1-7 ~]# ll zabbix*
-rw-r--r--. 1 root root 16008047 3月 14 11:21 zabbix-3.2.6.tar.gz
[root@1-7 ~]# useradd -s /sbin/nologin zabbix
[root@1-7 ~]# tar xzf zabbix-3.2.6.tar.gz
[root@1-7 ~]# cd zabbix-3.2.6
[root@1-7 zabbix-3.2.6]# yum -y install mariadb mariadb-server mariadb-devel
[root@1-7 zabbix-3.2.6]# service mariadb start
Redirecting to /bin/systemctl start mariadb.service
[root@1-7 zabbix-3.2.6]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix charset=utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
[root@1-7 zabbix-3.2.6]# yum -y install gcc* openssl*
[root@1-7 zabbix-3.2.6]# mysql -uzabbix -p123456 zabbix <database/mysql/schema.sql
[root@1-7 zabbix-3.2.6]# mysql -uzabbix -p123456 zabbix <database/mysql/images.sql
[root@1-7 zabbix-3.2.6]# mysql -uzabbix -p123456 zabbix < database/mysql/data.sql
[root@1-7 zabbix-3.2.6]# ./configure --prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl
Configuration:
Detected OS: linux-gnu
Install path: /usr/local/zabbix
Compilation arch: linux
Compiler: gcc
Compiler flags: -g -O2
Library-specific flags:
database: -I/usr/include/mysql
Net-SNMP: -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include
Enable server: yes
Server details:
With database: MySQL
WEB Monitoring: cURL
Native Jabber: no
SNMP: yes
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -L/usr/lib64/mysql -L/usr/lib64 -rdynamic
Libraries: -lmysqlclient -lnetsnmp -lcurl -lm -ldl -lresolv
Enable proxy: no
Enable agent: yes
Agent details:
TLS: no
Linker flags: -rdynamic
Libraries: -lcurl -lm -ldl -lresolv
Enable Java gateway: no
LDAP support: no
IPv6 support: yes
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@1-7 zabbix-3.2.6]# make -j8;make -j8 install
[root@1-7 zabbix-3.2.6]# pwd
/root/zabbix-3.2.6
[root@1-7 zabbix-3.2.6]# cd misc/
[root@1-7 misc]# ls
images init.d Makefile Makefile.am Makefile.in snmptrap
[root@1-7 misc]# cd init.d/
[root@1-7 init.d]# ls
aix debian fedora freebsd gentoo README suse tru64 ubuntu
[root@1-7 init.d]# cd tru64/ # 最小化的一个系统
[root@1-7 tru64]# ls
zabbix_agentd zabbix_server
[root@1-7 tru64]# pwd
/root/zabbix-3.2.6/misc/init.d/tru64
[root@1-7 tru64]# ll
总用量 8
-rw-r--r--. 1 zabbix zabbix 1519 5月 5 2017 zabbix_agentd
-rw-r--r--. 1 zabbix zabbix 1521 5月 5 2017 zabbix_server
[root@1-7 tru64]# cp * /etc/init.d/
[root@1-7 tru64]# rpm -Uvh http://repo.webtatic.com/yum/el6/latest.rpm # 安装 php,如果安装失败需要从官网下载最新 latest.rpm 之后 yum clean all 继续操作即可
[root@1-7 tru64]# yum remove php*
[root@1-7 tru64]# cd
[root@1-7 ~]# yum install httpd httpd-devel httpd-tools -y
[root@1-7 ~]# yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 -y --skip-broken
[root@1-7 ~]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
[root@1-7 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@1-7 ~]# cd /var/www/html/
[root@1-7 html]# ll
总用量 4
-rwxr-xr-x. 1 root root 24 3月 14 16:09 info.php
[root@1-7 html]# cat info.php # 浏览器访问 192.168.1.7/info.php
<?php
phpinfo();
?>
[root@1-7 html]# cd
[root@1-7 ~]# cd zabbix-3.2.6
[root@1-7 zabbix-3.2.6]# ls
aclocal.m4 ChangeLog config.log configure.ac frontends m4 man README
AUTHORS compile config.status COPYING include Makefile misc sass
bin conf config.sub database INSTALL Makefile.am missing src
build config.guess configure depcomp install-sh Makefile.in NEWS upgrades
[root@1-7 zabbix-3.2.6]# cd frontends/
[root@1-7 frontends]# ls
php
[root@1-7 frontends]# cd php/
[root@1-7 php]# pwd
/root/zabbix-3.2.6/frontends/php
[root@1-7 php]# ls
...
[root@1-7 php]# ll /var/www/html/
总用量 4
-rwxr-xr-x. 1 root root 24 3月 14 16:09 info.php
[root@1-7 php]# mv /var/www/html/info.php /usr/local/src/
[root@1-7 php]# ll /var/www/html/
总用量 0
[root@1-7 php]# cp * /var/www/html/ -a # 浏览器访问 192.168.1.7
# 进行错误修复
[root@1-7 ~]# yum install php56w-mbstring php56w-bcmath php56w-gd php56w-xml -y
[root@1-7 ~]# yum install gd gd-devel -y
[root@1-7 ~]# sed -i '/post_max_size/s/8/16/g;/max_execution_time/s/30/300/g;/max_input_time/s/60/300/g;s/\;date.timezone.*/date.timezone \= PRC/g;s/\;always_populate_raw_post_data/always_populate_raw_post_data/g' /etc/php.ini
[root@1-7 ~]# service httpd restart
[root@1-7 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22976/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1698/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2069/master
tcp6 0 0 :::80 :::* LISTEN 22897/httpd
tcp6 0 0 :::22 :::* LISTEN 1698/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2069/master
[root@1-7 ~]# pkill mysqld
[root@1-7 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1698/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2069/master
tcp6 0 0 :::80 :::* LISTEN 22897/httpd
tcp6 0 0 :::22 :::* LISTEN 1698/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2069/master
# 192.168.1.11-Mariadb数据库
[root@1-11 ~]# yum install mariadb mariadb-server mariadb-devel -y
[root@1-11 ~]# service mariadb restart
Redirecting to /bin/systemctl restart mariadb.service
[root@1-11 ~]# ps -ef | grep mysqld
mysql 15332 1 0 17:30 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 15494 15332 0 17:30 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 15538 15175 0 17:31 pts/1 00:00:00 grep --color=auto mysqld
[root@1-11 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> create database zabbix charset=utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on zabbix.* to zabbix@'192.168.1.7' identified by "123456";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
Bye
[root@1-11 ~]#
# 192.168.1.7-Zabbix+Server+WEB
[root@1-7 ~]# cd zabbix-3.2.6
[root@1-7 zabbix-3.2.6]# ls
aclocal.m4 build conf config.status configure.ac depcomp INSTALL Makefile man NEWS src
AUTHORS ChangeLog config.guess config.sub COPYING frontends install-sh Makefile.am misc README upgrades
bin compile config.log configure database include m4 Makefile.in missing sass
[root@1-7 zabbix-3.2.6]# cd database/
[root@1-7 database]# ls
ibm_db2 Makefile Makefile.am Makefile.in mysql oracle postgresql sqlite3
[root@1-7 database]# cd mysql
[root@1-7 mysql]# ls
data.sql images.sql schema.sql
[root@1-7 mysql]# mysql -h192.168.1.11 -uzabbix -p zabbix <schema.sql
Enter password:
[root@1-7 mysql]# mysql -h192.168.1.11 -uzabbix -p zabbix <images.sql
Enter password:
[root@1-7 mysql]# mysql -h192.168.1.11 -uzabbix -p zabbix <data.sql
Enter password:
# 192.168.1.7-Zabbix+Server+WEB
[root@1-7 mysql]# cd /var/www/html
[root@1-7 html]# chmod o+w conf -R
# 192.168.1.7-Zabbix+Server+WEB
[root@1-7 html]# cd conf
[root@1-7 conf]# ll
总用量 12
-rw-r--rw-. 1 zabbix zabbix 1036 5月 5 2017 maintenance.inc.php
-rw-r--r-- 1 apache apache 451 3月 15 17:56 zabbix.conf.php
-rw-r--rw-. 1 zabbix zabbix 411 5月 5 2017 zabbix.conf.php.example
[root@1-7 conf]# cat zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '192.168.1.11';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = '123456';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '分布式监控Zabbix监控平台';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
# 用户名 admin 密码 zabbix
# 启动 zabbix_server
[root@1-7 ~]# /usr/local/zabbix/sbin/zabbix_server
[root@1-7 ~]# ps -ef | grep zabbix*
zabbix 23094 1 0 18:24 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server
root 23098 2412 0 18:24 pts/0 00:00:00 grep --color=auto zabbix*
[root@1-7 ~]# cd /usr/local/zabbix/
[root@1-7 zabbix]# cd etc/
[root@1-7 etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@1-7 etc]# ll zabbix_server.conf
-rw-r--r--. 1 root root 14663 3月 14 12:26 zabbix_server.conf
[root@1-7 etc]# cp zabbix_server.conf zabbix_server.conf.bak
[root@1-7 etc]# vim zabbix_server.conf # 修改配置文件,zabbix_server 才可以正常启动进行使用
LogFile=/tmp/zabbix_server.log
DBHost=192.168.1.11
DBName=zabbix
DBUser=zabbix
DBPassword=123456
[root@1-7 etc]# /usr/local/zabbix/sbin/zabbix_server
[root@1-7 etc]# yum remove mariadb* -y # 删除为了正常安装 zabbix 时配置的数据库