zabbix编译安装教程
一.准备机器环境初始化
1.查看ip地址
ifconfig ens32| awk 'NR==2{print $2}'
2.关闭selinux和防火墙
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
3.配置主机名
hostnamectl set-hostname zabbix_server
4.设置时区
timedatectl set-timezone Asia/Shanghai
二.准备zabbix需要的源码安装包
wget http://nginx.org/download/nginx-1.18.0.tar.gz
wget https://www.php.net/distributions/php-7.2.25.tar.gz
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz
三.nginx安装
1.创建一个文件夹,存放安装的nginx文件
mkdir /nginx
2.安装nginx依赖包
yum -y install gcc pcre-devel zlib-devel
3.解压下载好的nginx源码包
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
4.配置编译并安装
./configure --prefix=/nginx
make
make install
5.启动nginx
/nginx/sbin/nginx
6.设置开机自启
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/nginx/sbin/nginx
ExecReload=/nginx/sbin/nginx -s restart
ExecStop=/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
7.关闭nginx设置开机自启
systemctl enable nginx.service
systemctl start nginx
四.php安装
1.下载安装编译工具
yum -y groupinstall 'Development Tools'
2.安装依赖包
yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel
3.创建文件夹,存放PHP安装文件
mkdir /php
4.解压下载好的PHP源码包
tar -zxvf php-7.2.25.tar.gz
5.配置编译并安装
./configure --prefix=/php --with-config-file-path=/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm
make
make install
6.配置PHP-FPM
cd php-7.2.25
cp php.ini-production /etc/php.ini
cp /php/etc/php-fpm.conf.default /php/etc/php-fpm.conf
cp /php/etc/php-fpm.d/www.conf.default /php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
# 启动PHP-FPM
/etc/init.d/php-fpm start
注:然后我们就可以通过systemctl命令来管理PHP啦!
7.配置nginx配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
8.重启nginx
systemctl restart nginx
#登录验证
http://192.168.47.130/
五.mysql安装
1.下载地址
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MYSQL-5.7/mysql-community-server-5.7.36-1.el7.x86_64.rpm
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MYSQL-5.7/mysql-community-client-5.7.36-1.el7.x86_64.rpm
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MYSQL-5.7/mysql-community-common-5.7.36-1.el7.x86_64.rpm
http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MYSQL-5.7/mysql-community-libs-5.7.36-1.el7.x86_64.rpm
https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-devel-5.7.37-1.el7.x86_64.rpm
2.安装依赖包
yum -y install net-tools.x86_64 libaio.x86_64 perl.x86_64
3.安装MySQL
yum -y install mysql-community*
4.启动mysql
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
5.查看临时密码
grep 'password' /var/log/mysqld.log
6.修改mysql密码
mysqladmin -uroot -p'gaoUjwg_)1L!' password 'Admin123.'
7.进入mysql
mysql -uroot -p'Admin123.'
8.设置mysql远程登录权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'Admin123.' WITH GRANT OPTION;
flush privileges;
exit
六.zabbix安装
1.安装依赖
yum install gcc gcc-c++ make unixODBC-devel net-snmp-devel libssh2-devel OpenIPMI-devel libevent-devel pcre-devel libcurl-devel curl-* net-snmp* libxml2-* wget tar -y
2.解压Zabbix
tar -zxvf zabbix-5.0.0.tar.gz
3.创建目录存放zabbix
mkdir /zabbix
4.配置编译并安装
./configure --prefix=/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make && make install
groupadd --system zabbix
useradd --system -g zabbix -c "Zabbix Monitoring System" zabbix
chown -R zabbix:zabbix /zabbix
cd zabbix-5.0.0
cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
ll -d /etc/init.d/zabbix_*
chmod +x /etc/init.d/zabbix_*
5.创建zabbix数据库并依次导入数据文件
mysql -uroot -p'Admin123.'
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'Admin123.';
grant all privileges on zabbix.* to zabbix@127.0.0.1 identified by 'Admin123.';
GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'%'IDENTIFIED BY 'Admin123.' WITH GRANT OPTION;
flush privileges;
6.登录zabbix数据库导入数据
mysql -uzabbix -p'Admin123.'
use zabbix;
source /opt/zabbix-5.0.0/database/mysql/schema.sql
source /opt/zabbix-5.0.0/database/mysql/images.sql
source /opt/zabbix-5.0.0/database/mysql/data.sql
#zabbix账号密码查看
select t.userid,t.alias,t.passwd,t.* from users t;
7.修改配置文件
grep -v "#" /zabbix/etc/zabbix_server.conf
LogFile=/zabbix/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=zabbix_server
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/tmp/mysql.sock
DBPort=3306
StartPollers=100
StartTrappers=10
StartPingers=10
StartDiscoverers=10
Timeout=4
LogSlowQueries=3000
Include=/zabbix/etc/zabbix_server.conf.d/*.conf
StatsAllowedIP=127.0.0.1
grep -v "#" /zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agent.log
LogFile=/tmp/zabbix_agentd.log
DenyKey=system.run[*]
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zabbix_server
Include=/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
8.配置zabbix server启动文件
vim /lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
After=postgresql.service
[Service]
Environment="CONFFILE=/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/zabbix/sbin/zabbix_server
ExecStop=/bin/kill -SIGTERM $MAINPID
TimeoutSec=0
[Install]
WantedBy=multi-user.target
9.配置 zabbix agent 启动文件
vim /lib/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/zabbix/sbin/zabbix_agentd
ExecStop=/bin/kill -SIGTERM $MAINPID
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
10.然后我们拷贝前端文件目录到Nginx服务目录
cp -r /opt/zabbix-5.0.0/ui/* /nginx/html/zabbix
11.php.ini 修改内容如下
vim /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
pdo_mysql.default_socket=/var/lib/mysql/mysql.sock
mysqli.default_socket =/var/lib/mysql/mysql.sock
# 修改完成以后重启PHP
systemctl restart php-fpm