编译安装CENTOS8.0+NGINX+MYSQL +PHP+ZABBIX5.0

LNMP系统安装环境准备:

系统版本:CentOS Linux release 8.2.2004 (Core)

PHP版本:php-7.4.9

NGINX版本:nginx-1.19.2

MYSQL版本:MySQL 8.0

zabbix版本:zabbix-5.0.3

以下为下载地址:

PHP

NGINX

ZABBIX

因为这台机器是无法连接外网的,一些依赖安装起来就比较费劲。所以要把镜像挂载在本地

[root@zabbixserver ~]#mount /dev/cdrom /media/

编辑YUM源

[root@zabbixserver ~]#vim /etc/yum.repos.d/CentOS-Media.repo
[c8-media-BaseOS]
name=CentOS-BaseOS-$releasever - Media
baseurl=file:///media/BaseOS
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[c8-media-AppStream]
name=CentOS-AppStream-$releasever - Media
baseurl=file:///media/AppStream
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[root@zabbixserver ~]#dnf clean all
[root@zabbixserver ~]#dnf makecache
[root@zabbixserver ~]#dnf repolist
把下载的源码包都上传到服务器上,并解压。
[root@zl-zabbixserver ~]# tar -zxvf nginx-1.19.2.tar.gz

[root@zl-zabbixserver ~]# tar -zxvf php-7.4.9.tar.gz

[root@zl-zabbixserver ~]# tar -zxvf zabbix-5.0.3.tar.gz
[root@zabbixserver ~]# ls -l
总用量 35712
-rw-------.  1 root   root       1512 8月  31 22:33 anaconda-ks.cfg
-rw-r--r--.  1 root   root      37238 9月   4 09:40 history.txt
drwxr-xr-x.  9 zabbix zabbix      186 9月   3 11:28 nginx-1.19.2
-rw-r--r--.  1 root   root    1048727 9月   3 11:18 nginx-1.19.2.tar.gz
-rw-r--r--.  1 root   root      48452 9月   1 17:02 oniguruma-devel-6.8.2-1.el8.x86_64.rpm
drwxrwxr-x. 19 root   root       4096 9月   3 16:38 php-7.4.9
-rw-r--r--.  1 root   root   16516067 9月   3 16:34 php-7.4.9.tar.gz
drwxr-xr-x. 13 nginx  nginx      4096 9月   3 15:43 zabbix-5.0.3
-rw-r--r--.  1 root   root   18893485 9月   1 00:25 zabbix-5.0.3.tar.gz

因为搜索了一下有mysql的包,那就直接安装MYSQL

[root@zabbixserver ~]#dnf install mysql mysql-server -y
[root@zabbixserver ~]#ln -s /var/lib/mysql/mysql.sock /tmp/

启动MYSQL

[root@zabbixserver ~]#systemctl start mysqld

进入MYSQL并设置ROOT密码

[root@zabbixserver ~]#mysql

mysql>use mysql;
mysql> alter user 'root'@'localhost'IDENTIFIED BY 'MyNewPass@123';
mysql>flush privileges;

创建zabbix数据库

mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> alter user 'root'@'localhost'IDENTIFIED BY 'MyNewPass@123';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql>flush privileges;

导入zabbix数据

mysql>use zabbix;
mysql>source /root/zabbix-5.0.3/database/mysql/schema.sql
mysql>source /root/zabbix-5.0.3/database/mysql/data.sql
mysql>source /root/zabbix-5.0.3/database/mysql/images.sql
mysql>exit

编译安装PHP

[root@zabbixserver ~]#cd php-7.4.9/

[root@zabbixserver ~]#mkdir /usr/local/php7

[root@zabbixserver ~]#./configure --prefix=/usr/local/php7 \
--with-curl --with-freetype \
--enable-gd \
--with-jpeg \
--with-gettext \
--with-kerberos \
--with-libdir=lib64\
--with-libxml \
--with-mysqli \
--with-openssl\
--with-pdo-mysql\
--with-pdo-sqlite \
--with-pear \
--enable-sockets \
--with-mhash \
--with-ldap-sasl \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--with-zip \
--with-config-file-path=/usr/local/php7/etc \
-with-bz2 \
--enable-sysvsem [root@zabbixserver ~]#make && make install

编译过程如果少了什么包可以通过YUM安装

可能会缺少的一些依赖包

[root@zabbixserver ~]#dnf install freetype-devel libxslt-devel libzip  libzip-devel bzip2 libcurl  libcurl-devel libjpeg libjpeg-turbo-devel -y
[root@zabbixserver ~]# cp /root/php-7.4.9/sapi/fpm/www.conf /usr/local/php7/etc/php-fpm.conf
[root@zabbixserver ~]#useradd -s /sbin/nologin -M nginx
[root@zabbixserver ~]#sed -i "s/nobody/nginx/g"  /usr/local/php7/etc/php-fpm.conf
[root@zabbixserver ~]#cp /etc/php.ini  /usr/local/php7/etc/
[root@zabbixserver ~]#vim /usr/local/php7/etc/php.ini
  post_max_size = 16M

  max_execution_time = 300

  max_input_time = 300

  date.timezone = Asia/Shanghai

  memory_limit = 128M

  upload_max_filesize = 2M

启动PHP-FPM

[root@zabbixserver ~]#/usr/local/php7/sbin/php-fpm
[root@zabbixserver ~]# ps -ef |grep php-fpm

root 165931 1 0 9月03 ? 00:00:02 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)

nginx 166515 165931 0 07:56 ? 00:01:40 php-fpm: pool www

nginx 166552 165931 0 08:56 ? 00:01:27 php-fpm: pool www

nginx 167539 165931 0 10:43 ? 00:01:06 php-fpm: pool www

root 172471 2098 0 16:49 pts/0 00:00:00 grep --color=auto php-fpm

编译安装NGINX

[root@zabbixserver ~]#cd nginx-1.19.2/

[root@zabbixserver ~]#./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre --with-pcre-jit --with-http_ssl_module 

[root@zabbixserver ~]#make && make install

编辑NGINX支持PHP-FPM

user nginx;
worker_processes 1;

events{
   worker_connections 1024;


}

http {
   server_tokens off;

   proxy_buffer_size 128k;

   proxy_buffers  32 32k;

   proxy_busy_buffers_size 128k;

   include     mime.types;

   default_type application/octet-stream;
   sendfile    on;
   keepalive_timeout 65;
   server {
      listen   80;

      access_log /usr/local/nginx/logs/ssl.access.log;

      error_log /usr/local/nginx/logs/ssl.error.log;
      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            /usr/local/nginx/html;

      fastcgi_buffer_size 128k;

      fastcgi_buffers 4 256k;

      fastcgi_busy_buffers_size 256k;

      fastcgi_pass  127.0.0.1:9000;

      fastcgi_index  index.php;

      fastcgi_param SCRIPT_FILENAME

      $document_root$fastcgi_script_name;

      include     fastcgi_params;

    }

  }

}

启动NGINX

[root@zabbixserver ~]#/usr/local/nginx/nginx 
[root@zabbixserver ~]#ps -ef |grep nginx

root 165780 1 0 9月03 ? 00:00:00 nginx: master process /usr/local/nginx/nginx

nginx 165781 165780 0 9月03 ? 00:00:06 nginx: worker process

nginx 166515 165931 0 07:56 ? 00:01:46 php-fpm: pool www

nginx 166552 165931 0 08:56 ? 00:01:33 php-fpm: pool www

nginx 167539 165931 0 10:43 ? 00:01:11 php-fpm: pool www

root 172905 2098 0 17:24 pts/0 00:00:00 grep --color=auto nginx

编译安装ZABBIX

 [root@zabbixserver ~]#cd zabbix-5.0.3/
 [root@zabbixserver ~]#mkdir -m u=rwx,g=rwx,o= -p /usr/local/zabbix
 [root@zabbixserver ~]#chown zabbix:zabbix /usr/local/zabbix
 [root@zabbixserver ~]#dnf install -y net-snmp-devel
 [root@zabbixserver ~]#./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
 [root@zabbixserver ~]#make && make install

[root@zabbixserver ~]# grep -v ^# /usr/local/zabbix/etc/zabbix_server.conf

  LogFile=/tmp/zabbix_server.log

  DBHost=localhost

  DBName=zabbix

  DBUser=zabbix

  DBPassword=zabbix

  ListenIP=127.0.0.1

  Timeout=4

  LogSlowQueries=3000

  StatsAllowedIP=127.0.0.1

[root@zabbixserver ~]# grep -v ^# /usr/local/zabbix/etc/zabbix_agentd.conf

  LogFile=/tmp/zabbix_agentd.log

  Server=127.0.0.1

  ServerActive=127.0.0.1

  Hostname=zabbixserver

启动ZABBIX

[root@zabbixserver ~]#/usr/local/zabbix/sbin/zabbix_server
[root@zabbixserver ~]#/usr/local/zabbix/sbin/zabbix_agentd

 [root@zabbixserver ~]# ps -ef |grep zabbix

  zabbix 166623 1 0 09:24 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server

  zabbix 166624 166623 0 09:24 ? 00:00:03 /usr/local/zabbix/sbin/zabbix_server: configuration syncer [synced c

  onfiguration in 0.043215 sec, idle 60 sec]

  zabbix 166625 166623 0 09:24 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: housekeeper [deleted 0 hist/tr

  ends, 0 items/triggers, 0 events, 0 sessions, 0 alarms, 0 audit items, 0 records in 0.003919 sec, idle for 1 hour(s)]

  zabbix 166626 166623 0 09:24 ? 00:00:01 /usr/local/zabbix/sbin/zabbix_server: timer #1 [updated 0 hosts, sup

  pressed 0 events in 0.000622 sec, idle 59 sec]

  zabbix 166627 166623 0 09:24 ? 00:00:01 /usr/local/zabbix/sbin/zabbix_server: http poller #1 [got 0 values i

  n 0.000509 sec, idle 5 sec]

  zabbix 166628 166623 0 09:24 ? 00:00:02 /usr/local/zabbix/sbin/zabbix_server: discoverer #1 [processed 0 rul

  es in 0.000687 sec, idle 60 sec]

  zabbix 166630 166623 0 09:24 ? 00:00:05 /usr/local/zabbix/sbin/zabbix_server: history syncer #1 [processed 0

  values, 0 triggers in 0.000028 sec, idle 1 sec]

  zabbix 166631 166623 0 09:24 ? 00:00:04 /usr/local/zabbix/sbin/zabbix_server: history syncer #2 [processed 0

  zabbix 166717 1 0 09:37 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd

  zabbix 166718 166717 0 09:37 ? 00:00:03 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]

  zabbix 166719 166717 0 09:37 ? 00:00:04 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for conne

  ction]

  zabbix 166720 166717 0 09:37 ? 00:00:04 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for conne

  ction]

  zabbix 166721 166717 0 09:37 ? 00:00:04 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for conne

拷贝zabbix前端到nginx目录

[root@zabbixserver ~]#cp -R ~/zabbix-5.0.3/ui/*  /usr/local/nginx/html/
[root@zabbixserver ~]#cp /usr/local/nginx/html/conf/zabbix.conf.php.example /usr/local/nginx/html/zabbix.conf.php
[root@zabbixserver ~]#grep -v ^# /usr/local/nginx/html/zabbix.conf.php

<?php

// Zabbix GUI configuration file.

$DB['TYPE'] = 'MYSQL';

$DB['SERVER'] = 'localhost';

$DB['PORT'] = '3306';

$DB['DATABASE'] = 'zabbix';

$DB['USER'] = 'zabbix';

$DB['PASSWORD'] = 'zabbix';

防火墙放开80端口

[root@zabbixserver ~]#firewall-cmd --permanent --add-port=80/tcp
[root@zabbixserver ~]#firewall-cmd --reload 

访问zabbix前端http://IP进入安装界面

编译安装CENTOS8.0+NGINX+MYSQL +PHP+ZABBIX5.0

检测依赖和配置文件是否安装正确

编译安装CENTOS8.0+NGINX+MYSQL +PHP+ZABBIX5.0

连接数据库是否正常

编译安装CENTOS8.0+NGINX+MYSQL +PHP+ZABBIX5.0

编译安装CENTOS8.0+NGINX+MYSQL +PHP+ZABBIX5.0

最后贴上一张安装好后的图

编译安装CENTOS8.0+NGINX+MYSQL +PHP+ZABBIX5.0

因为zabbix监控ICMP需要FPING

所以我们要安装,在YUM 源没有搜索到这个包,所以只能下载源码包编译安装

FPING5.0

[root@zabbixserver ~]#  tar -zxvf fping-5.0.tar.gz
[root@zabbixserver ~]#  cd fping-5.0/
[root@zabbixserver ~]#  ./configure --prefix=/usr/local/fping
[root@zabbixserver ~]#  make
[root@zabbixserver ~]#  make install
[root@zabbixserver ~]#/usr/local/fping/sbin/fping -v 
[root@zabbixserver ~]#chown root:zabbix /usr/local/fping/sbin/fping
[root@zabbixserver ~]#chmod 4710 /usr/local/fping/sbin/fping
[root@zabbixserver ~]#ln -s /usr/local/fping/sbin/fping /usr/sbin/fping
[root@zabbixserver ~]#/usr/sbin/fping -v

配置图形时,中文显示是方框的话可以从自己的WINDOS系统的中文字体拷贝一个字体到路径/usr/local/nginx/html/assets/fonts下,如果觉得改配置文件麻烦可以直接把导入的字体名字改成本来在这里的字体的名字。我这里拷贝的是中文楷体路径是“控制面板\所有控制面板项\字体”。

[root@zabbixserver ~]# mv simkai.ttf DejaVuSans.ttf