一、安装前准备
1.监控服务器(需要使用Web页面操作,因此需要部署LNMP)
- 设置主机名(zabbixserver)
- 设置IP地址(192.168.2.5)
- 关闭防火墙、SElinux
2.监控客户端(2.100和2.200)
- 主机web1(192.168.2.100)
- 主机web2(192.168.2.100)
- 关闭防火墙、SElinux
角色 | IP |
---|---|
zabbix_serveer | 192.168.2.5 |
web1 | 192.168.2.100 |
web2 | 192.168.2.100 |
可以先装一台模板机进行克隆,更快速的准备好
二、配置环境
1、所有主机都需要操作
- 防火墙设置信任所有
- selinux设为宽松模式
[root@zabbix_server ~]# firewall-cmd --set-default-zone=trusted
[root@zabbix_server ~]# sed -i '/SELINUX/s/enforcing/permissive/' /etc/selinux/config
[root@zabbix_server ~]# setenforce 0
步骤一:部署LNMP环境
1.安装LNMP环境
Zabbix监控管理控制台需要通过Web页面展示出来,并且还需要使用MYSQL来存储数据,因此需要先为zabbix准备基础LNMP环境。
[root@zabbix_server ~]# yum -y install gcc pcre-devel openssl-devel wget
[root@zabbix_server ~]# wget http://1.116.86.11/nginx-1.17.6.tar.gz
[root@zabbix_server ~]# tar xf nginx-1.17.6.tar.gz
[root@zabbix_server ~]# cd nginx-1.17.6
[root@zabbix_server nginx-1.17.6]# ./configure --with-http_ssl_module
[root@zabbix_server nginx-1.17.6]# make && makeinstall
[root@zabbix_server ~]# yum -y install php-fpm php php-mysql
[root@zabbix_server ~]# yum -y install mariadb mariadb-server mariadb-devel
2.修改Nginx配置文件
配置Nginx支持PHP动态网站,因为有大量PHP脚本需要执行,因此还需要开启Nginx的各种fastcgi缓存,加速PHP脚本的执行速度。
[root@zabbix_server ~]# vi /usr/local/nginx/conf/nginx.conf
... ...
http{
fastcgi_buffers 8 16k; #缓存php生成的页面内容,8个16k
fastcgi_buffer_size 32k; #缓存php生产的头部信息,32k
fastcgi_connect_timeout 300; #连接PHP的超时时间,300秒
fastcgi_send_timeout 300; #发送请求的超时时间,300秒
fastcgi_read_timeout 300; #读取请求的超时时间,300秒
... ...
location ~\.php${
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
... ...
}
3.启动服务
启动Nginx、php-fpm、mariadb开机自启动
[root@zabbix_server ~]# systemctl enable php-fpm --now
[root@zabbix_server ~]# systemctl enable mariadb --now
#设置Nginx开机自启动两种方法
[root@zabbix_server ~]# echo /usr/local/nginx/sbin/nginx >> /etc/rc.local #设置Nginx开机自启动,或者是用下面的方法配置nginx.service
[root@zabbix_server ~]# vim /lib/systemd/system/nginx.service #配置Nginx.service(推荐)
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@zabbix_server ~]# systemctl enable nginx --now
步骤二:部署监控服务器Zabbix Server
1.源码安装Zabbix Server
多数源码包都是需要依赖包的,zabbix也一样,源码编译前需要先安装依赖包。
[root@zabbix_server ~]# yum -y install net-snmp-devel curl-devel autoconf libevent-devel #安装依赖包
[root@zabbix_server ~]# wget http://1.116.86.11/zabbix-3.4.4.tar.gz
[root@zabbix_server ~]# tar xf zabbix-3.4.4.tar.gz
[root@zabbix_server ~]# cd zabbix-3.4.4
[root@zabbix_server zabbix-3.4.4]# ./configure --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-libcurl --with-net-snmp
#################################################################
#--enable-server安装部署zabbix服务器端软件 #
#--enable-agent安装部署zabbix被监控端软件 #
#--enable-proxy安装部署zabbix代理相关软件 #
#--with-mysql指定mysql_config路径 #
#--with-net-snmp允许zabbix通过snmp协议监控点其设备(如交换机、路由器) #
#--with-libcurl安装相关curl库文件,这样zabbix就可以通过curl连接 #
#################################################################
[root@zabbix_server zabbix-3.4.4]# make install
2.创建并初始化数据库
[root@zabbix_server ~]# mysql
MariaDB [(none)]> CREATE DATABASE zabbix CHARACTER SET utf8;
#创建数据库,数据库名称为zabbix,CHARACTER SET utf8是支持中文字符集
MariaDB [(none)]> GRANT ALL ON zabbix.* TO zabbix@'localhost' IDENTIFIED BY 'zabbix';
#创建可以访问数据库的账户和密码,账户为zabbix,密码为zabbix
MariaDB [(none)]> exit
[root@zabbix_server ~]# cd zabbix-3.4.4/database/mysql/
#导入表注意按顺序导入!!!
[root@zabbix_server mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql
[root@zabbix_server mysql]# mysql -uzabbix -pzabbix zabbix < images.sql
[root@zabbix_server mysql]# mysql -uzabbix -pzabbix zabbix < data.sql
[root@zabbix_server mysql]# mysql -uzabbix -pzabbix -h localhost zabbix
MariaDB [zabbix]> SHOW TABLES; #查看zabbix下导入的表
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| task |
| task_acknowledge |
| task_close_problem |
| task_remote_command |
| task_remote_command_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
140 rows in set (0.00 sec)
3.修改配置文件
[root@zabbix_server mysql]# vim /usr/local/etc/zabbix_server.conf
DBHost=localhost #85行,定义 哪台主机位数据库主机,localhost为主机
DBName=zabbix #95行,设置数据库名称
DBUser=zabbix #111行,设置数据库账户
DBPassword=zabbix #119行,设置数据库密码
LogFile=/tmp/zabbix_server.log #38行,日志的位置,拍错使用,改行仅查看即可
注意!!!配置都要顶格写
4.启动zabbix
[root@zabbix_server ~]# useradd -s /sbin/nologin zabbix
#服务不允许以root身份启动,不创建用户无法启动服务(用户不需要登录系统)
#创建zabbix用户才可以一zabbix用户的身份启动服务
#启动服务后可以通过ps aux查看进程是以什么用户的身份启动的
[root@zabbix_server ~]# zabbix_server #启动服务
[root@zabbix_server ~]# zabbix_server >> /etc/rc.local #设置开机自启动(不推荐,推荐使用systemctl设置)
!!!提示:如果配置文件不对,到时服务无法启动时,不要重复执行zabbix_server,一定要使用killall zabbix_server关闭服务后,再重新启动一次(安装了psmisc软件包,才有killall命令)
4.2启动zabbix(使用systemctl启动)推荐!!!
[root@zabbix_server ~]# vim /usr/lib/systemd/system/zabbix_server.service
[Unit]
Description=Zabbix server
After=network.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/tmp/zabbix_server.pid
ExecStart=/usr/local/sbin/zabbix_server
ExecStop=/bin/kill $MAINPID
[Install]
WantedBy=multi-user.target
[root@zabbix_server ~]# systemctl daemon-reload
[root@zabbix_server ~]# systemctl enable zabbix_server --now
#设置开机自启动,并立即启动[root@zabbix_server ~]# ss -nutlp | grep 10051 #查看服务端口
4.3修改Zabbix_agent配置文件。
[root@zabbix_server ~]# vim /usr/local/etc/zabbix_agentd.conf
Server=127.0.0.1,192.168.2.5 #93行,允许哪些主机监控本机
ServerActive=127.0.0.1,192.168.2.5 #134行,允许哪些主机通过主动模式监控本机
Hostname=zabbix_server #145行,设置本主机名(名称可以任意)
UnsafeUserParameters=1 #280行,是否允许自定义监控传参
LogFile=/tmp/zabbix_agentd.log #设置日志文件,不需要修改
4.4启动Zabbix_agent服务
[root@zabbix_server ~]# zabbix_agentd #启动zabbix_agentd
[root@zabbix_server ~]# zabbix_agentd >> /etc/rc.local #设置开机自启动(不推荐,推荐systemctl启动)
[root@zabbix_server system]# ss -nutlp | grep 10050
#查看服务端口#######################################################(下面是配置systemctl启动)
[root@zabbix_server system]# vim /lib/systemd/system/zabbix_agentd.service
[Unit]Description=Zabbix serverAfter=network.target remote-fs.target nss-lookup.targetWants=network-online.target
[Service]
Type=forking
PIDFile=/tmp/zabbix_server.pid
ExecStart=/usr/local/sbin/zabbix_agentd
ExecStop=/bin/kill $MAINPID
[Install]
WantedBy=multi-user.target
[root@zabbix_server system]# systemctl daemon-reload
[root@zabbix_server system]# systemctl enable zabbix_agentd --now
[root@zabbix_server system]# ss -nutlp | grep 10050 #查看服务端口
6.上线Zabbix的web页面
[root@zabbix_server ~]# \cp -rf zabbix-3.4.4/frontends/php/* /usr/local/nginx/html/
[root@zabbix_server ~]# chown -R apache.apache /usr/local/nginx/html/
此时web页面就部署好了,打开浏览器访问http://192.168.2.5/index.php如下图所示
点击Next setp此时会报错如下图所示,根据错误提示,安装依赖、修改PHP配置文件,买足Zabbix_server的环境要求。
根据提示安装依赖包,修改php.ini
[root@zabbix_server ~]# yum -y install php-gd php-xml php-bcmath php-mbstring[root@zabbix_server ~]# vim /etc/php.inidate.timezone = Asia/Shanghai #878行设置时区max_execution_time = 300 #384行脚本最大执行时间,秒post_max_size = 16M #672行POST数据最大容量max_input_time = 300 #394行 服务器接收数据的时间限制#注意此配置文件注释以分号开头!!![root@zabbix_server ~]# systemctl restart php-fpm #修改完配置文件后重启php-fpm
此时再次刷新页面就没有错误了(注意:这里有一个PHP LDAP是warning状态是没有问题的!!!)
点击Next step,指定数据库填写数据库端口用户密码,如下图所示
点击Nest step 后是配置zabbix_server的默认就好继续下一步…
安装完成后登录默认用户:admin 密码: zabbix
步骤三:部署被监控主机Zabbix Agent
1.源码安装Zabbix agent软件在2.100和2.200做相同操作(以web1为例)
[root@web1 zabbix-3.4.4]# useradd zabbix -s /sbin/nologin
[root@web1 zabbix-3.4.4]# tar xf zabbix-3.4.4.tar.gz
[root@web1 zabbix-3.4.4]# cd zabbix-3.4.4
[root@web1 zabbix-3.4.4]# yum -y install net-snmp-devel curl-devel autoconf libevent-devel gcc
[root@web1 zabbix-3.4.4]# ./configure --enable-agent
[root@web1 zabbix-3.4.4]# make install
2.修改Zabbix_agent配置文件
Server=127.0.0.1,192.168.2.5 #93行ServerActive=127.0.0.1,192.168.2.5 #134行
Hostname=web1 #145改主机名(不改也行随意)EnableRemoteCommands=1 #69行,允许执行命令主动模式需要开启。
UnsafeUserParameters=1 #第280行,表示使用自定义脚本
到此所有环境就配置完成了