## zabbix-5.4代理安装

[TOC]

### 1 安装zabbix清华源

rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm

sed -i 's#repo.zabbix.com#mirrors.tuna.tsinghua.edu.cn\/zabbix#g' /etc/yum.repos.d/zabbix.repo


## zabbix服务器端-5.2版本

[TOC]

版本说明

- nginx-1.6.3 /data/nginx-1.6.3/

- php-7.2 /usr/bin/php

- zabbix-5.2.1 /data/zabbix

- mysql-5.7

### 1 nginx-1.6.3安装

参考地址:https://www.wangairui.com/docs/npt/npt-1c4m4454rmaa6

### 2 php-7.4安装

```yaml

yum install epel-release -y

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

yum install -y php72w-* --skip-broken

```

#### 2.1安装完成以后,启动服务

```yaml

systemctl enable php-fpm.service

systemctl start php-fpm.service

```

#### 2.2查看服务版本成功

```yaml

php -version

```

### 3 mysql-5.7 (我使用了rds)

#### 3.1 安装这步骤是在zabbix源码部署时候会有一些依赖,装完卸载即可

#### 3.2 下载并安装MySQL官方的 Yum Repository

```yaml

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

```

#### 3.3 下载并安装MySQL官方的 Yum Repository

使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。之后就开始安装MySQL服务器

```yaml

yum -y install mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server

yum install mysql-devel -y

```

#### 3.4 启动

```yaml

systemctl start mysqld.service

systemctl status mysqld.service

```

#### 3.4 或者参考

https://www.wangairui.com/docs/mysql/mysql-1cm1mk0ujf73p

### 4 zabbix-5.2源码安装

#### 4.1 安装依赖和用户

```yaml

tar -xzvf zabbix-5.2.1.tar.gz

cd zabbix-5.2.1/

yum -y install gcc gcc-c++ curl curl-devel net-snmp net-snmp-devel perl-DBI libxml2-devel libevent-devel pcre

groupadd zabbix

useradd -g zabbix zabbix

usermod -s /sbin/nologin zabbix

```

![](/uploads/zabbix/images/m_7b3b6b0082b448e43e24f056f5b9ecf8_r.png)

```yaml

#### 4.2下载源码包解压安装

cd /opt

wget https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.1.tar.gz

tar xf zabbix-5.2.1.tar.gz

cd zabbix-5.2.1

./configure --prefix=/data/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

make && make install

chown zabbix:zabbix /data/zabbix/ -R

```

#### 4.3 拷贝前端代码到nginx目录

#### 注意后面cp的目录都是在解压出来的源码包下 我的是在/opt/下

```yaml

ln -s /data/zabbix/sbin/zabbix_* /usr/local/sbin/

cd zabbix-5.2.1/

cp misc/init.d/tru64/{zabbix_agentd,zabbix_server} /etc/init.d/;chmod o+x /etc/init.d/zabbix_*

```

```yaml

sed -i "s/DAEMON=\/usr\/local\/sbin\/zabbix_server/DAEMON=\/data\/zabbix\/sbin\/zabbix_server/g" /etc/init.d/zabbix_server

sed -i "s/PIDFILE=\/usr\/local\/sbin\/zabbix_server.pid/PIDFILE=\/data\/zabbix\/sbin\/zabbix_server.pid/g" /etc/init.d/zabbix_server

sed -i "s/DAEMON=\/usr\/local\/sbin\/zabbix_agentd/DAEMON=\/data\/zabbix\/sbin\/zabbix_agentd/g" /etc/init.d/zabbix_agentd

sed -i "s/PIDFILE=\/tmp\/zabbix_agentd.pid/PIDFILE=\/data\/zabbix\/sbin\/zabbix_agentd.pid/g" /etc/init.d/zabbix_agentd

```

```yaml

cd zabbix-5.2.1/

cp -ar ui/* /data/nginx-1.6.3/html/

chown -R www:www /data/nginx-1.6.3/html/

```

#### 4.4 修改zabbix——server配置文件

```yaml

echo "" > /data/zabbix/etc/zabbix_server.conf

cat > /data/zabbix/etc/zabbix_server.conf <<-'EOF'

LogFile=/data/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/data/zabbix/zabbix_server.pid

SocketDir=/data/zabbix

DBName=zabbix

DBUser=zabbix

DBPassword=数据库密码

DBSocket=/var/lib/mysql/mysql.sock

StartPollers=15

StartHTTPPollers=3

SNMPTrapperFile=/var/log/snmptrap/snmptrap.log

Timeout=4

AlertScriptsPath=/data/zabbix/alertscripts

ExternalScripts=/data/zabbix/externalscripts

LogSlowQueries=3000

StatsAllowedIP=127.0.0.1

EOF

修改zabbix_server.conf配置文件中代码设置为如下:

########################################

LogFile=/tmp/zabbix_server.log

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=123456

########################################

```

#### 4.6 修改php.ini配置文件

```yaml

########################################

PHP option "post_max_size" 8M 16M Fail

PHP option "max_execution_time" 30 300 Fail

PHP option "max_input_time" 60 300 Fail

pdo_mysql.default_socket= /tmp/mysql.sock

mysqli.default_socket = /tmp/mysql.sock

extension = bcmath.so

########################################

sed -i "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php.ini

sed -i "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini

sed -i "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini

sed -i "s/mysqli.default_socket=/mysqli.default_socket=/var/lib/mysql/mysql.sock/g" /etc/php.ini

sed -i "s/pdo_mysql.default_socket=/pdo_mysql.default_socket=/var/lib/mysql/mysql.sock/g" /etc/php.ini

chmod -R 777 /var/www/html/conf/

/etc/init.d/zabbix_server restart

systemctl restart httpd

## zabbix客户端[5.4]

[TOC]

官网地址:https://www.zabbix.com/cn/download?zabbix=5.4&os_distribution=red_hat_enterprise_linux&os_version=7&db=&ws=

### 1 添加源

```yaml

https://repo.zabbix.com/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm

yum clean all

yum install zabbix-agent

rpm -qa |grep zabbix

```

### 2修改客户端配置;

```yaml

echo ""> /etc/zabbix/zabbix_agentd.conf

cat > /etc/zabbix/zabbix_agentd.conf <<--EOF

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

LogFileSize=0

Server=127.0.0.1

ServerActive=127.0.0.1

Hostname=Zabbix server

Include=/etc/zabbix/zabbix_agentd.d/*.conf

EOF

```

### 3 启动

```yaml

systemctl restart zabbix-agent

systemctl enable zabbix-agent

```