系统相关
首页 > 系统相关> > Centos7.8系统源码安装部署zabbix5.0.3

Centos7.8系统源码安装部署zabbix5.0.3

作者:互联网

一、安装nginx 

二、安装PHP 

三、源码安装zabbix 

四、配置web页面 

五、安装zabbix proxy 

六、安装grafana

附1:安装php报错问题处理 

附2:Mysql数据库配置 

附3:配置centos7.8系统yum源

一、安装nginx

安装如下依赖包:

sudo yum install gcc pcre-devel openssl-devel

创建nginx用户和用户组:

sudo groupadd -f nginx

sudo useradd -g nginx nginx

下载上传nginx-1.19.2.tar.gz至服务器,解压文件包命令如下:

tar -xvf nginx-1.19.2.tar.gz

 

安装编译nginx命令如下:

./configure \

--group=nginx \

--user=nginx \

--prefix=/u01/nginx \

--conf-path=/u01/nginx/etc/nginx/nginx.conf \

--error-log-path=/u01/nginx/logs/error.log \

--http-log-path=/u01/nginx/logs/access.log \

--http-client-body-temp-path=/u01/nginx/tmp/nginx/client_body \

--http-proxy-temp-path=/u01/nginx/tmp/nginx/proxy \

--http-fastcgi-temp-path=/u01/nginx/tmp/nginx/fastcgi \

--pid-path=/u01/nginx/logs/nginx.pid \

--lock-path=/u01/nginx/lock/nginx \

--with-http_stub_status_module \

--with-http_ssl_module \

--with-http_gzip_static_module \

--with-pcre

sudo make && make install

 

配置nginx.conf

**************************************************************************

location ~ \.php$ {

        #    root           html;

            root   /u01/nginx/html/zabbix;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

**************************************************************************

配置nginx开机自启动

1、创建/usr/lib/systemd/system/nginx.service文件,输入如下内容:s

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

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

 

[Service]

Type=forking

PIDFile=/u01/nginx/logs/nginx.pid

ExecStartPre=/u01/nginx/sbin/nginx -t -c /u01/nginx/etc/nginx/nginx.conf

ExecStart=/u01/nginx/sbin/nginx -c /u01/nginx/etc/nginx/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true

 

[Install]

WantedBy=multi-user.target

2、重载系统服务:

systemctl daemon-reload

3、设置开机启动:

systemctl enable zabbix-server.service

 

 

二、安装PHP

下载安装如下依赖包:

sudo yum install libxml2-devel sqlite-devel libcurl-devel libpng-devel libjpeg-turbo-devel libXpm-devel freetype-devel libicu-devel gcc-c++ libxslt-devel oniguruma-devel libsodium-devel openldap-devel net-snmp-devel

如果yum源没有oniguruma oniguruma-devel libsodium libsodium-devel libwebp-devel安装包,则需要从网上下载安装。

sudo cp -frp /usr/lib64/libldap* /usr/lib/

 

源码安装libzip-1.2.0

./configure

sudo make && sudo make install

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

    

    源码安装PHP

sudo ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/php --with-freetype --with-jpeg  --with-zlib  --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --enable-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip  --enable-soap --with-gettext --enable-opcache --with-xsl --with-webp --with-xpm --with-snmp --with-ldap

备注:需要在root环境下编译,,否则会提示libzip错误

make && make install

 

php启动命令:

/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

 

配置php-fpm

cp php.ini-production /usr/local/php/etc/php.ini

修改php.ini文件,将对应参数做如下修改。

max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone =Asia/Shanghai

cd sapi/fpm && cp php-fpm.conf /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

测试php-fpm配置

/usr/local/php/sbin/php-fpm -t

/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf -t

sudo chown -R nginx:nginx /usr/local/php/var

 

php-fpm开机自启动

vim /usr/lib/systemd/system/php-fpm.service

***********************************************

[Unit]

Description=PHP-FPM

After=network.target syslog.target2

 

[Install]

WantedBy=default.target

Alias=php-fpm.service

 

[Service]

User=nginx

Group=nginx

#User and Group can be set in the php-fpm configure file

Type=forking

#PIDFile=/usr/local/php/var/run/php-fpm.pid

#不需要在这里指定pid文件位置,需要到php-fpm.conf文件中指定

ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

ExecStop=/bin/kill -INT $MAINPID

ExecReload=/bin/kill -USR2 $MAINPID

****************************************************************************

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

systemctl daemon-reload

Systemctl enable php-fpm.service

Systemctl start php-fpm.service

 

三、源码安装zabbix

     

安装如下依赖包:

 yum install unixODBC-devel ncurses-devel OpenIPMI libevent java-1.8.0-openjdk-devel openldap-devel gnutls-devel

下载安装libssh2-devel OpenIPMI-devel libevent-devel

下载上传zabbix安装包至服务器,解压命令如下:tar -xvf zabbix-5.0.3.tar.gz

开始编译安装:

./configure --prefix=/u01/zabbix --enable-server  --enable-ipv6  --with-mysql=/app/mysql5.7.26/install/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --with-jabber --with-ssh2 --with-zlib --with-libpcre --enable-java --with-ldap --with-gnutls

sudo make && sudo make install

groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

 

cd zabbix-5.0.3

cp -r ui/ /u01/nginx/html/zabbix

chmod 777 /u01/nginx/html/zabbix/conf

cd /u01/zabbix

mkdir logs

chown -R zabbix:zabbix /app/zabbix

systemctl restart nginx.service

 

修改/app/zabbix/etc/zabbix_server.conf文件,将对应参数修改如下。

LogFile=/u01/zabbix/logs/zabbix_server.log

PidFile=/u01/zabbix/logs/zabbix_server.pid

DBHost=10.210.4.35

DBName=zabbix

DBUser=zabbix

DBPassword=******

DBPort=3306

 

配置zabbix服务开机自启动

1、创建/etc/systemd/system/zabbix-server.service文件,并输入如下内容:

[Unit]

Description=Zabbix Server

After=syslog.target

After=network.target

 

[Service]

Environment="CONFFILE=/u01/zabbix/etc/zabbix_server.conf"

EnvironmentFile=-/u01/zabbix/sbin/zabbix_server

Type=forking

Restart=on-failure

PIDFile=/u01/zabbix/logs/zabbix_server.pid

KillMode=control-group

ExecStart=/u01/zabbix/sbin/zabbix_server -c $CONFFILE

ExecStop=/bin/kill -SIGTERM $MAINPID

RestartSec=10s

 

[Install]

WantedBy=multi-user.target

2、重载系统服务:

systemctl daemon-reload

3、设置开机启动:

systemctl enable zabbix-server.service

 

四、配置web页面

打开浏览器http://$ip/setup.php

 

 点击下一步;

 

 

 

如果没有错误提示,继续点击下一步;

 

 

 输入MySQL数据库连接信息,然后点击下一步;

 

 

 如果出现如下信息,说明zabbix已经安装配置完成!

 

 

 

 

 

五、安装zabbix proxy

创建用户

groupadd -g 5007 zabbix

useradd -u 5007 -g zabbix -G zabbix zabbix

 

创建proxy 数据库,proxy库只需要执行schema.sql

/mysql/mysql8.0/bin/mysql -uroot -p -S /u01/mysqlzabix/mysql.sock

create database zabbixproxy01 character set utf8 collate utf8_bin;

grant all privileges on zabbix.* to zabbix@'%' identified by 'Bqproxy@2020';

grant all privileges on *.* to 'zabbix'@'%' with grant option;

flush privileges;

sudo /mysql/mysql8.0/bin/mysql -uzabbix -p -S /u01/mysqlzabix/mysql.sock;

use zabbixproxy01;

source schema.sql;  
quit

 

安装依赖包

sudo yum install mysql++-devel net-snmp-devel libssh2-devel libxml2-devel OpenIPMI-devel libevent-devel gnutls-devel java-1.8.0-openjdk-devel openldap-devel libcurl-devel unixODBC-devel

编译安装proxy

./configure --prefix=/u01/zabbix --enable-proxy  --enable-ipv6  --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --with-jabber --with-ssh2 --with-zlib --with-libpcre --enable-java --with-ldap --with-gnutls

sudo make && sudo make install

sudo mkdir /u01/zabbix/logs

sudo chown -R zabbix:zabbix /u01/zabbix

 

配置开机自启动

1、创建/etc/systemd/system/zabbix-proxy.service文件,并输入如下内容:

[Unit]

Description=Zabbix Proxy

After=syslog.target

After=network.target

 

[Service]

Environment="CONFFILE=/u01/zabbix/etc/zabbix_proxy.conf"

EnvironmentFile=-/u01/zabbix/sbin/zabbix_proxy

Type=forking

Restart=on-failure

PIDFile=/u01/zabbix/logs/zabbix_proxy.pid

KillMode=control-group

ExecStart=/u01/zabbix/sbin/zabbix_proxy -c $CONFFILE

ExecStop=/bin/kill -SIGTERM $MAINPID

RestartSec=10s

 

[Install]

WantedBy=multi-user.target

2、重载系统服务:

systemctl daemon-reload

3、设置开机启动:

systemctl enable zabbix-server.service

 

六、安装grafana

下载上传安装包至服务器grafana-7.2.0-1.x86_64.rpm;

执行安装命令:

sudo yum install grafana-7.2.0-1.x86_64.rpm

sudo systemctl daemon-reload

sudo systemctl enable grafana-server.service

sudo systemctl start grafana-server.service

打开浏览器,输入http://zabbix.baonengmotor.com:3000/登录grafana,输入用户名密码,admin/Xqtsbsb*16。

安装zabbix插件

下载上传alexanderzobnin-zabbix-app-4.0.1.zip至服务器/var/lib/grafana/plugins上,并解压:

unzip alexanderzobnin-zabbix-app-4.0.1.zip

sudo systemctl restart grafana-server.service

 

 

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.2.x86_64.rpm

sudo yum localinstall influxdb-1.8.2.x86_64.rpm

编辑配置文件
vim /etc/influxdb/influxdb.conf
仔细研究InfluxDB的配置文件,默认的配置是这样的
[meta]
    dir = "/var/lib/influxdb/meta"
[data]
    dir = "/var/lib/influxdb/data"
    wal-dir = "/var/lib/influxdb/wal"
[http]
    # The bind address used by the HTTP service.
    # bind-address = ":8086"
可以根据需要,灵活修改上面的这几项配置,要确保目录存在,确保指定的端口没有被占用,使用下面的命令排查目前已经占用的端口
netstat -nltup
将目录修改为/u01/influxdb
mkdir -p  /u01/influxdb
chown influxdb:influxdb /u01/influxdb/

 

附1:安装php报错问题处理

如果php报不支持ldap提示,则操作如下:

Php编译后支持ldap

cd php-7.4.5/ext/ldap

/usr/local/php/bin/phpize

cp -frp /usr/lib64/libldap* /usr/lib/

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

修改php.ini,取消掉如下行注释:

extension=ldap.so

 

附2:Mysql数据库配置

在mysql数据库服务器端创建zabbix数据库、数据库账户及到导入zabbix sql语句,操作命令如下:

create database zabbix character set utf8 collate utf8_bin;

grant all privileges on zabbix.* to zabbix@'%' identified by 'Bqzabbix@2020';

grant all privileges on *.* to 'zabbix'@'%' with grant option;

flush privileges;

source schema.sql;     

source images.sql;

source data.sql;
quit

 

 

附3:配置centos7.8系统yum源

mount -t auto /dev/cdrom /mnt/cdrom 

************************************************************

name=CentOS-$releasever - Media

baseurl=file:///media/cdrom/

gpgcheck=1

enabled=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

************************************************************

yum makecache

 

标签:zabbix5.0,--,devel,Centos7.8,nginx,zabbix,源码,php,u01
来源: https://www.cnblogs.com/huss2016/p/14717512.html