zabbix部署

zabbix

zabbix介绍

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent

zabbix server可以通过SNMPzabbix agentping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在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的主要特点:

  • 安装与配置简单,学习成本低
  • 支持多语言(包括中文)
  • 免费开源
  • 自动发现服务器与网络设备
  • 分布式监视以及WEB集中管理功能
  • 可以无agent监视
  • 用户安全认证和柔软的授权方式
  • 通过WEB界面设置或查看监视结果
  • email等通知功能

Zabbix主要功能:

  • CPU负荷
  • 内存使用
  • 磁盘使用
  • 网络状况
  • 端口监视
  • 日志监视

zabbix部署

用为zabbix是php语言开发的,所以部署前置要求有lamp架构,具体参考《lamp架构的部署》

这里安装的zabbix是6.2版本,需要mysql版本8.0,需要重新安装mysql8.0

//拉取mysql8.0安装包
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz

//删除mysql
[root@localhost ~]# service mysqld stop
[root@localhost ~]# rm -rf /opt/data
[root@localhost ~]# rm -rf /usr/local/mysql/

//解压mysql8.0安装包
[root@localhost ~]# tar xf  mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-8.0.28-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql

//重新加载mysql库文件
[root@localhost ~]# ldconfig

//初始化mysql
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize --user mysql --datadir /opt/data/
2022-09-01T11:21:18.761587Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 32284
2022-09-01T11:21:18.779279Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-01T11:21:19.559210Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-01T11:21:21.651360Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: e!KN;_!*q1jr
//保存密码
[root@localhost local]# echo 'e!KN;_!*q1jr' > /root/pass

//配置服务启动脚本
[root@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp: overwrite '/etc/init.d/mysqld'? y

[root@localhost local]# vim /etc/init.d/mysqld
//找到一下两行,此为更改后的内容
    basedir=/usr/local/mysql
    datadir=/opt/data
[root@localhost local]# chmod +x /etc/init.d/mysqld

//重启mysql
[root@localhost ~]# service mysqld restart

//登录到mysql
[root@localhost ~]# mysql -uroot -p'e!KN;_!*q1jr'

//修改密码
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

zabbix服务端的安装

//下载zabbix源码包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz

//解压
[root@localhost src]# tar xf zabbix-6.2.2.tar.gz 
[root@localhost src]# cd zabbix-6.2.2/
[root@localhost zabbix-6.2.2]#

//安装依赖包
[root@localhost zabbix-6.2.2]# dnf -y install net-snmp-devel libevent-devel

//创建zabbix系统用户
[root@localhost zabbix-6.2.2]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
//创建zabbix用户的家目录
[root@localhost zabbix-6.2.2]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
[root@localhost zabbix-6.2.2]# chown -R zabbix.zabbix /usr/lib/zabbix/


//配置zabbix数据库
[root@localhost zabbix-6.2.2]# mysql -uroot -p<Password>

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.01 sec)

mysql> create user 'zabbix'@'localhost' identified by 'zabbix123!';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

//按照如下顺序将sql文件导入到zabbix数据库中
[root@localhost zabbix-6.2.2]# cd /usr/src/zabbix-6.2.2/database/mysql/
[root@localhost mysql]# mysql -uroot -p<Password> zabbix < schema.sql 
[root@localhost mysql]# mysql -uroot -p<Password> zabbix < images.sql 
[root@localhost mysql]# mysql -uroot -p<Password> zabbix < data.sql 

[root@localhost mysql]# mysql -uroot -p<Password>
mysql> SET GLOBAL log_bin_trust_function_creators = 0;
//查看zabbix数据库下有哪些表,没有问题的话是176张表
mysql> show tables from zabbix;
…………
| valuemap                   |
| valuemap_mapping           |
| widget                     |
| widget_field               |
+----------------------------+
176 rows in set (0.00 sec)

//编译zabbix
[root@localhost mysql]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ./configure --enable-server --enable-agent --with-mysql  --with-net-snmp --with-libcurl --with-libxml2
[root@localhost zabbix-6.2.2]# make install

zabbix服务端配置

[root@localhost zabbix-6.2.2]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d

//修改服务端配置文件
[root@localhost etc]# vim zabbix_server.conf
//找到下面这行,在下面添加mysql的密码
	# DBPassword=
	DBPassword=zabbix123! //添加密码,zabbix数据库用户的密码

zabbix配置web界面

//配置apache虚拟主机
[root@localhost zabbix-6.2.2]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
# zabbix_web
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName zabbix.example.com
    ErrorLog "logs/zabbix.example.com-error_log"
    CustomLog "logs/zabbix.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

//创建zabbix的web站点目录
[root@localhost zabbix-6.2.2]# mkdir /usr/local/apache/htdocs/zabbix
//将zabbix的web界面php代码复制到站点目录
[root@localhost zabbix-6.2.2]# cp -a /usr/src/zabbix-6.2.2/ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix-6.2.2]# chown -R apache.apache /usr/local/apache/htdocs/

//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost zabbix-6.2.2]# chmod 777 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost zabbix-6.2.2]# ll -d /usr/local/apache/htdocs/zabbix/conf/
drwxrwxrwx 3 apache apache 94 Aug 29 15:05 /usr/local/apache/htdocs/zabbix/conf/

//重启httpd
[root@localhost zabbix-6.2.2]# httpd -t
Syntax OK
[root@localhost zabbix-6.2.2]# systemctl restart httpd.service 

//修改/etc/php.ini的配置并重启php-fpm
[root@localhost zabbix-6.2.2]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost zabbix-6.2.2]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

//启动zabbix_server和zabbix_agentd
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd

在物理机上做hosts域名映射

编辑C:\Windows\System32\drivers\etc\hosts文件
192.168.169.139 zabbix.example.com

去浏览器访问,输入zabbix.example.com,看到如下页面,然后点击next step

继续下一步

确认无误,下一步

登录,用户名:Admin 密码:zabbix

部署完成

恢复zabbix/conf目录的权限为755:

[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf/
drwxr-xr-x 3 apache apache 117 Sep  1 20:17 /usr/local/apache/htdocs/zabbix/conf/
posted @ 2022-09-01 22:34  Zic师傅  阅读(116)  评论(0编辑  收藏  举报