zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
Zabbix主要功能:
zabbix配置文件有两种:
环境 | IP | 安装应用 |
---|---|---|
服务器 | 192.168.8.130 | lamp架构 zabbix servers zabbix agent |
客户端 | 192.168.8.131 | zabbix agent |
部署zabbix 需要部署lamp架构(见lamp架构篇)
# 安装zabbix需要使用php7.4版本 [root@server ~]# tar xf php-7.4.24.tar.xz -C /usr/src/ [root@server php-7.4.24]# ./configure --prefix=/usr/localphp \--with-config-file-path=/etc --enable-fpm --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-json --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix [root@server php-7.4.24]# make && make install ······ # 设置环境变量 [root@server php-7.4.24]# cp /etc/php.ini /opt/ [root@server php-7.4.24]# cp php.ini-production /etc/php.ini cp:是否覆盖'/etc/php.ini'? y [root@server php-7.4.24]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@server php-7.4.24]# chmod +x /etc/rc.d/init.d/php-fpm [root@server php-7.4.24]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@server php-7.4.24]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf [root@server php-7.4.24]# [root@server ~]# service php-fpm start Starting php-fpm done [root@server ~]# service php-fpm stop # 设置开机自启 [root@server ~]# cat /usr/lib/systemd//system/php-fpm.service [Unit] Description=php-fpm server daemon After=network.targe [Service] Type=forking ExecStart=/etc/init.d/php-fpm start ExecStop=/etc/init.d/php-fpm stop [Install] WantedBy=multi-user.target [root@server ~]# systemctl daemon-reload [root@server ~]# systemctl enable --now php-fpm [root@server ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.1:6011 0.0.0.0:* LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
# 安装依赖软件 [root@server ~]# yum -y install net-snmp-devel libevent-devel #下载zabbix https://www.zabbix.com/download_sources # 解压软件包 [root@server ~]# tar xf zabbix-5.4.4.tar.gz -C /usr/src/ # 创建zabbix用户 [root@server ~]# useradd -r -M -s /sbin/nologin zabbix # 配置abbix数据库 [root@server ~]# mysql -uroot -p123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.34 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.08 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '123'; Query OK, 0 rows affected, 2 warnings (0.03 sec) mysql> flush privileges; Query OK, 0 rows affected (0.03 sec) [root@server ~]# cd /usr/src/zabbix-4.0.3/database/mysql/ [root@client mysql]# ls data.sql double.sql images.sql Makefile.am Makefile.in schema.sql [root@client mysql]# mysql -uroot -p123 zabbix < schema.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@client mysql]# mysql -uroot -p123 zabbix < images.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@client mysql]# mysql -uroot -p123 zabbix < data.sql mysql: [Warning] Using a password on the command line interface can be insecure. # 编译安装zabbix [root@server zabbix-5.4.4]# ./configure --enable-server \ --enable-agent \ --with-mysql \ --with-net-snmp \ --with-libcurl \ --with-libxml2 [root@server zabbix-5.4.4]# make install ······
[root@server zabbix-5.4.4]# ls /usr/local/etc/ zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d [root@server zabbix-5.4.4]# vim /usr/local/etc/zabbix_server.conf .... DBPassword=123 # 设置zabbix数据库密码 [root@server ~]# mkdir /var/lib/mysql [root@server ~]# ln -s /tmp/mysql.sock /var/lib/mysql/ # 启动服务 [root@server ~]# zabbix_server [root@server ~]# zabbix_agentd [root@server ~]# [root@server ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:10050 0.0.0.0:* LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
[root@server htdocs]# mkdir zabbix [root@server htdocs]# chown -R apache.apache /usr/local/httpd/htdocs [root@server zabbix-5.4.4]# cp -r ui/* /usr/local/httpd/htdocs/zabbix/ [root@server zabbix-5.4.4]# # 配置http文件 [root@client httpd]# vim conf/httpd.conf <VirtualHost *:80> DocumentRoot "/usr/local/httpd/htdocs/zabbix" ServerName www.test.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/httpd/htdocs/zabbix/$1 <Directory "/usr/local/httpd/htdocs/zabbix"> Options none AllowOverride none Require all granted </Directory> </VirtualHost> [root@client httpd]# systemctl restart httpd # 修改/etc/php.ini的配置并重启php-fpm [root@client ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini [root@client ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini [root@client ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini [root@client ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini [root@client ~]# systemctl restart php-fpm
修改文件权限
[root@client ~]# chown -R apache.apache /usr/local/httpd/htdocs/zabbix [root@client ~]# chmod 777 /usr/local/httpd/htdocs/zabbix/conf [root@client ~]# ll -d /usr/local/httpd/htdocs/zabbix/conf drwxrwxrwx. 3 apache apache 94 9月 26 16:32 /usr/local/httpd/htdocs/zabbix/conf
zabbix默认登陆用户名:Admin,密码:zabbix
恢复zabbix/conf目录的权限为755:
[root@client ~]# chmod 755 /usr/local/httpd/htdocs/zabbix/conf [root@client ~]# ll -d /usr/local/httpd/htdocs/zabbix/conf drwxr-xr-x. 3 apache apache 117 9月 26 16:49 /usr/local/httpd/htdocs/zabbix/conf