部署zabbix

源码下载地址:

Download Zabbix sources

nginx: download

防火墙和selinux都需要关闭

1、部署监控服务器

1)安装LNMP环境

Zabbix监控管理控制台需要通过Web页面展示出来,并且还需要使用MySQL来存储数据,因此需要先为Zabbix准备基础LNMP环境。

**[**root@zabbixserver ~]# yum **-y install gcc pcre-devel openssl-**devel

**[root@zabbixserver ~]# tar -xf nginx-1.12.2.tar.**gz

[root@zabbixserver ~]# cd nginx-1.12.2

[root@zabbixserver nginx-1.12.2**]**# **./**configure **--with-**http_ssl_module

[root@zabbixserver nginx-1.12.2**]**# make **&&**make install

**[**root@zabbixserver ~]# yum **-y install php php-mysql php-**fpm(注意,在centos8stream里没有php-mysql,需要安装php-mysqlnd)

**[**root@zabbixserver ~]# yum **-y install mariadb mariadb-devel mariadb-**server

2)修改Nginx配置文件

配置Nginx支持PHP动态网站,因为有大量PHP脚本需要执行,因此还需要开启Nginx的各种fastcgi缓存,加速PHP脚本的执行速度。

**[**root@zabbixserver ~]# vim **/usr/local/nginx/conf/nginx.**conf

... ...

http**{**

... ...

fastcgi_buffers 816k**;** #缓存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服务,关闭SELinux与防火墙。

**[**root@zabbixserver ~]# systemctl start mariadb #启动服务

**[root@zabbixserver ~]# systemctl start php-**fpm #启动服务

**[**root@zabbixserver ~]# systemctl enable mariadb #设置开机自启

**[root@zabbixserver ~]# systemctl enable php-**fpm #设置开机自启

**[root@zabbixserver ~]# /usr/local/nginx/sbin/**nginx #启动服务

**[**root@zabbixserver ~]# echo **/usr/local/nginx/sbin/nginx >>/etc/rc.**local

**[**root@zabbixserver ~]# chmod **+**x **/etc/rc.**local

#通过rc**.**local设置开机自启

**[root@zabbixserver ~]# firewall-**cmd **--set-default-zone=**trusted

**[**root@zabbixserver ~]# setenforce 0

**[**root@zabbixserver ~]# sed **-i '/SELINUX/s/enforcing/permissive/'/etc/selinux/**config

注意:

在这里,需要验证一下php是否正常启动了:

ss -ntulp | grep php

如果没有输出,则需要修改php-fpm的配置:

[root@proxy etc]# vim **/etc/php-fpm.d/www.**conf

[www]

listen **=127.0.0.1:**9000 //PHP端口号

pm**.**max_children **=**32 //最大进程数量

pm**.**start_servers **=**15 //最小进程数量

2、部署监控服务器Zabbix Server

1)源码安装Zabbix Server

多数源码包都是需要依赖包的,zabbix也一样,源码编译前需要先安装相关依赖包。

**[**root@zabbixserver ]# yum **-y install net-snmp-**devel \

curl**-devel autoconf libevent-**devel

#安装相关依赖包

[root@zabbixserver]# tar -xf zabbix-3.4.4**.tar.**gz

[root@zabbixserver ]# cd zabbix-3.4.4**/**

[root@zabbixserver zabbix-3.4.4**]**# **./**configure **--enable-**server \

**--enable-**proxy **--enable-agent --with-mysql=/usr/bin/**mysql_config \

**--with-net-**snmp **--with-**libcurl

**--enable-**server安装部署zabbix服务器端软件

**--enable-**agent安装部署zabbix被监控端软件

**--enable-**proxy安装部署zabbix代理相关软件

**--with-**mysql指定mysql_config路径

**--with-net-**snmp允许zabbix通过snmp协议监控其他设备(如交换机、路由器等)

**--with-**libcurl安装相关curl库文件,这样zabbix就可以通过curl连接http等服务,测试被监控主机服务的状态

[root@zabbixserver zabbix-3.4.4**]**# make **&&**make install

2)创建并初始化数据库(root用户默认没有密码)

**[**root@zabbixserver ~]# mysql

mysql**>create database zabbix character set utf8;**

#创建数据库,数据库名称为zabbix,character set utf8是支持中文字符集

mysql**>grant all on zabbix.*to zabbix@'localhost'identified by 'zabbix';**

#创建可以访问数据库的账户与密码,用户名是zabbix,密码是zabbix

mysql**>**exit

#退出数据库

[root@zabbixserver ~]# cd zabbix-3.4.4**/database/mysql/**

[root@zabbixserver mysql]# mysql **-**uzabbix **-**pzabbix zabbix **<schema.**sql

[root@zabbixserver mysql]# mysql **-**uzabbix **-**pzabbix zabbix **<images.**sql

[root@zabbixserver mysql]# mysql **-**uzabbix **-**pzabbix zabbix **<data.**sql

#刚刚创建是空数据库,zabbix源码包目录下,有提前准备好的数据

#使用mysql导入这些数据即可(注意导入顺序)

如果导入有如下问题:

[root@zabbix mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql ERROR 1118 (42000) at line 1244: Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.

修改my.cnf文件,添加或修改以下参数([root@zabbix mysql]# ls /etc/my.cnf):

innodb_file_per_table=1

innodb_file_format=Barracuda

innodb_strict_mode=0

#**-u指定数据库用户名,-**p指定数据库密码

如何测试?

**[**root@zabbixserver ~]# mysql **-**uzabbix **-**pzabbix **-**h localhost zabbix

#**-u指定用户名,-p指定密码,-**h指定服务器IP,最后的zabbix是数据库名称

#使用zabbix账户(密码为zabbix)连接localhost服务器上面的zabbix数据库

mysql**>show tables;**

#查看有没有数据表

mysql**>**exit

#退出数据库

3)修改zabbix_server配置并启动监控服务

修改Zabbix_server配置文件,设置数据库相关参数,启动Zabbix_server服务

**[**root@zabbixserver ~]# 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行,日志的位置,排错使用,该行仅查看即可

AllowUnsupportedDBVersions=1

**[**root@zabbixserver ~]# useradd **-**s **/sbin/**nologin zabbix

#服务不允许以root身份启动,不创建用户无法启动服务(用户不需要登录系统)

#创建zabbix用户才可以以zabbix用户的身份启动服务

#启动服务后可以通过ps aux查看进程是以什么用户的身份启动的

通过创建service文件管理zabbix服务。

**[**root@zabbixserver ~]# vim **/usr/lib/systemd/system/zabbix_server.**service

[Unit]

Description**=**zabbix server

After**=network.target remote-fs.target nss-lookup.**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@zabbixserver ~]# systemctl enable zabbix_server **--**now

**[**root@zabbixserver ~]# ss **-**ntulp |grep zabbix_server #确认连接状态,端口10051

tcp LISTEN 0128***:10051*:*users:(("zabbix_server",pid=23275,fd=4),("zabbix_server",pid=23274,fd=4)**

4) 修改Zabbix_agent配置文件,启动Zabbix_agent服务

**[**root@zabbixserver ~]# 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行,设置本机主机名(名称可以任意)

LogFile**=/tmp/zabbix_agentd.**log #设置日志文件(不需要修改)

UnsafeUserParameters**=**1 #280行,是否允许自定义监控传参

编写zabbix_agentd的service文件,通过systemd管理服务。

**[**root@zabbixserver ~]# vim **/usr/lib/systemd/system/zabbix_agentd.**service

[Unit]

Description**=**zabbix agent

After**=network.target remote-fs.target nss-lookup.**target

[Service]

Type**=**forking

PIDFile**=/tmp/zabbix_agentd.**pid

ExecStart**=/usr/local/sbin/**zabbix_agentd

ExecStop**=**/bin/kill $MAINPID

[Install]

WantedBy**=multi-user.**target

**[**root@zabbixserver ~]# systemctl enable zabbix_agentd **--**now

**[**root@zabbixserver ~]# ss **-**ntulp |grep zabbix_agentd #查看端口信息为10050

tcp LISTEN 0128***:10050*:*users:(("zabbix_agentd",pid=23505,fd=4),("zabbix_agentd",pid=23504,fd=4)**

5)上线Zabbix的Web页面

[root@zabbixserver ~]# cd zabbix-3.4.4**/frontends/php/**

[root@zabbixserver php]# cp -r */usr/local/nginx/html/

[root@zabbixserver php]# chown **-R apache.**apache /usr/local/nginx/html/

#这里修改所有者使用**:或者.**都可以。

#修改权限的原因如下:

#php**-fpm的账户是apache,后面我们需要让php-**fpm对网站目录具有读写操作,

#而/usr/local**/nginx/html默认是root所有,仅root具有写权限,php-**fpm无写权限

浏览器访问Zabbix_server服务器的Web页面

火狐浏览器访问【 firefox http://192.168.2.5/index.php

#第一次访问,初始化PHP页面会检查计算机环境是否满足要求,如果不满足会给出修改建议

#默认会提示PHP的配置不满足环境要求,需要修改PHP配置文件

根据错误提示,安装依赖、修改PHP配置文件,满足Zabbix_server的环境要求。

**[**root@zabbixserver ~]# yum **-y install php-gd php-**xml

**[**root@zabbixserver ~]# yum **-y install php-bcmath php-**mbstring

**[**root@zabbixserver ~]# vim **/etc/php.**ini

date**.**timezone **=Asia/**Shanghai #878行,设置时区

max_execution_time **=**300 #384行,最大执行时间,秒

post_max_size **=**32M #672行,POST数据最大容量

max_input_time **=**300 #394行,服务器接收数据的时间限制

**[root@zabbixserver ~]# systemctl restart php-**fpm

3、部署被监控主机Zabbix Agent

1)源码安装Zabbix agent软件

在2.100和2.200做相同操作(以web1为例)。

**[**root@web1 ~]# useradd **-**s **/sbin/**nologin zabbix

**[**root@web1 ~]# yum **-y install gcc pcre-**devel autoconf

**[root@web1 ~]# tar -xf zabbix-3.4.4.tar.**gz

[root@web1 ~]# cd zabbix-3.4.4**/**

[root@web1 zabbix-3.4.4**]**# **./**configure **--enable-**agent

[root@web1 zabbix-3.4.4**]**# make **&&**make install

2)修改agent配置文件,启动Agent

**[**root@web1 ~]# 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**=**web1 #145行,被监控端自己的主机名

EnableRemoteCommands**=**1

#69行,监控异常后,是否允许服务器远程过来执行命令,如重启某个服务

UnsafeUserParameters**=**1 #280行,是否允许自定义key传参

**[root@web1 ~]# firewall-**cmd **--set-default-zone=**trusted

**[**root@web1 ~]# sed **-i '/SELINUX/s/enforcing/permissive/'/etc/selinux/**config

**[**root@web1 ~]# setenforce 0

**[**root@web1 ~]# vim **/usr/lib/systemd/system/zabbix_agentd.**service

[Unit]

Description**=**zabbix agent

After**=network.target remote-fs.target nss-lookup.**target

[Service]

Type**=**forking

PIDFile**=/tmp/zabbix_agentd.**pid

ExecStart**=/usr/local/sbin/**zabbix_agentd

ExecStop**=**/bin/kill $MAINPID

[Install]

WantedBy**=multi-user.**target

**[**root@web1 ~]# systemctl enable zabbix_agentd **--**now

#启动服务器并设置开机自启动

相关推荐
powerfulzyh3 小时前
Ubuntu24.04远程开机
linux·ubuntu·远程工作
ulimpid3 小时前
Command | Ubuntu 个别实用命令记录(新建用户、查看网速等)
linux·ubuntu·command
HHoao3 小时前
Ubuntu启动后第一次需要很久才能启动GTK应用问题
linux·运维·ubuntu
小灰兔的小白兔3 小时前
【Ubuntu】Ubuntu常用命令
linux·运维·ubuntu
GFCGUO3 小时前
ubuntu18.04运行OpenPCDet出现的问题
linux·python·学习·ubuntu·conda·pip
winds~3 小时前
ubuntu中软件的进程管理-结束软件运行
linux·运维·ubuntu
阳光不锈@3 小时前
麒麟桌面系统安装和配置Node.js
linux·麒麟系统安装node.js
bush43 小时前
使用root账号ssh登录虚拟机ubuntu
运维·ubuntu·ssh
叫我龙翔4 小时前
【Linux】进程间关系与守护进程
linux·运维·服务器·计算机网络
小诸葛的博客4 小时前
Ubuntu如何如何安装tcpdump
linux·ubuntu·tcpdump