Environment introduction

  • System version: CentOS 7
  • Nginx version: 1.12.2
  • Php version: 7.1.11
  • Mysql version: 5.6

The preparatory work

  • Turn selinux off. Turning selinux on causes a host of problems, and even Zabbix’s Discovery function doesn’t work properly

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

Check whether the modification is successful

grep SELINUX /etc/selinux/config

Then restart the system

Install Nginx

  • Download nginxWget HTTP: / / http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.12.2-1.el7_4.ngx.x86_64.rpm
  • Install nginxThe RPM - the ivh nginx 1.12.2-1. El7_4. NGX. X86_64. RPM
  • Set nginx to start automatically upon startupsystemctl enable nginx
  • Start the nginxsystemctl start nginx
  • Check the nginx startup statussystemctl status nginx
  • Do not close nginx, modify the configuration file effective methodnginx -s reload
  • The firewall opens port 80firewall-cmd --add-port=80/tcp --permanent
  • Reload the firewall configurationfirewall-cmd --reload
  • View the ports currently open on the firewallfirewall-cmd --list-ports

Mysql installation

  • Centos7 provides mariadb. You can run the following command to query the mysqlyum search mysql|tac
  • Start installing Mariadbyum -y install mariadb mariadb-server
  • Set mysql to start upon startupsystemctl enable mariadb.service
  • Start the mysqlsystemctl start mariadb.service
  • Initialize the mysql database and set the password of user rootmysql_secure_installation

Installing PHP

  • Download php7Wget HTTP: / / http://cn2.php.net/distributions/php-7.1.11.tar.gz
  • Unzip and go to the PHP directoryTar ZXVF php-7.1.11.tar.gz && CD./php-7.1.11
  • Install the extension pack update packageyum install epel-release
  • Install the PHP dependencies
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 yum install -y libmcrypt libmcrypt-devel gccCopy the code
  • Compiling and configuring PHP

./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache

  • Compile and install, take some time to wait slowlymake && make install
  • Add PHP commands to environment variablesvi /etc/profile, add at the end
PATH=$PATH:/usr/local/php/bin

export PATHCopy the code
  • Make the changes effective immediatelysource /etc/profile
  • Viewing environment Variablesecho $PATH
  • Viewing the PHP versionphp -v
  • Configure PHP – FPM
cp ./php.ini-production /etc/php.ini  # copy php.ini-production from PHP source and name it /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /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
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpmCopy the code
  • Modify the /etc/php.ini filevi /etc/php.iniFind the configuration item and modify it as follows
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
date.timezone = Asia/ShanghaiCopy the code
  • Start php-fpm /etc/init.d/php-fpm start

  • Configure nginx, binding server vi/etc/nginx/conf. D/default. Conf

server{
    listen 80;
    server_name  127.0.0.1;
    root /data/www;  This item should be modified to prepare the path for you to store the relevant pages
    location / {
        index  index.php index.html index.htm;
        # If the request is neither a file nor a directory, execute the following rewrite rule
        if (!-e $request_filename)
        {
            Rewrite to index.php as a parameter.
            rewrite ^/(.*)$ /index.php/The $1;
            Change subdir to directory name.
            #rewrite ^/subdir/(.*)$ /subdir/index.php/$1;}}#proxy the php scripts to php-fpm
    location ~ \.php {
        include fastcgi_params;
        # # pathinfo support start
        $path_info specifies a variable to store pathinfo information
        set $path_info "";
        $real_script_name = $real_script_name
        set $real_script_name $fastcgi_script_name;
        # if the address matches the regular expression inside the quotes
        if ($fastcgi_script_name ~ "^ (. +? \.php)(/.+)$") {
            Assign the file address to the variable $real_script_name
            set $real_script_name The $1;
            # assign the argument after the file address to the variable $path_info
            set $path_info $2;
        }
        Configure some parameters for fastCGI
        fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
        # # # pathinfo support end
        fastcgi_intercept_errors on;
        fastcgi_pass   127.0.0.1:9000;
    }

    location ^~ /data/runtime {
        return 404;
    }

    location ^~ /application {
        return 404;
    }

    location ^~ /simplewind {
        return404; }}Copy the code
  • Restart the nginxnginx -s reload
  • Create the test PHP filevi /data/www/info.php
<? php phpinfo();Copy the code
  • Go to http://127.0.0.1/info.php

Install the zabbix server. –

  • Install zabbix YUMThe RPM - the ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
  • Install the zabbixyum -y install zabbix-server-mysql zabbix-agent
  • Create zbbix account in mysql
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to 'zabbix'@The '%' identified by 'zabbixpass';
flush privileges;Copy the code
  • Import the Zabbix table structure and initialize it to the database
cdThe/usr/share/doc/zabbix server - mysql 3.41 / zcat. Create SQL. Gz | mysql -u root -p zabbixCopy the code
  • Configure the Zabbix server sidevi /etc/zabbix/zabbix_server.confFind the configuration item and change the configuration
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpassCopy the code
  • Switch folder owner
chown -R zabbix:zabbix /etc/zabbix
chown -R zabbix:zabbix /usr/lib/zabbixCopy the code
  • Set up zabbixServer upon bootsystemctl enable zabbix-server
  • Start the zabbix serversystemctl start zabbix-server
  • The firewall opens port 10051, which is used by the Zabbix Agentfirewall-cmd --add-port=10051/tcp --permanent
  • Reload the firewall configurationfirewall-cmd --reload
  • View the ports currently open on the firewallfirewall-cmd --list-ports

Install the zabbix – web

  • Download the Zabbix source codeZabbix wget - O - 3.4.4. Tar. Gz http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.4/zabbix-3.4.4.tar.gz/download
  • Unzip and go to the Zabbix directoryThe tar ZXVF zabbix - 3.4.4. Tar. Gz
  • copyZabbix - 3.4.4 / frontends/PHPAll contents of the folder to/data/www/zabbixfolderCp - rf. / zabbix - 3.4.4 / frontends/PHP / / data/WWW/zabbix
  • Creating a Configuration Filemv /data/www/zabbix/conf/zabbix.conf.php.example /data/www/zabbix/conf/zabbix.conf.php
  • Modifying a Configuration Filevi /data/www/zabbix/conf/zabbix.conf.phpTo change the data IP address, database name, user name and password
<? php // Zabbix GUI configuration file. global$DB;

$DB['TYPE']                = 'MYSQL';
$DB['SERVER']            = 'localhost';
$DB['PORT']                = '0';
$DB['DATABASE']            = 'zabbix';
$DB['USER']                = 'zabbix';
$DB['PASSWORD']            = 'zabbixpass';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA']            = ' ';

$ZBX_SERVER                = 'localhost';
$ZBX_SERVER_PORT        = '10051';
$ZBX_SERVER_NAME        = 'zabbix server';

$IMAGE_FORMAT_DEFAULT    = IMAGE_FORMAT_PNG;Copy the code
  • Go to zabbix Web configuration and visit http://127.0.0.1/zabbix

Configuration zabbix agent

  • Edit the Zabbix-Agent configuration filevi /etc/zabbix/zabbix_agentd.confFind the following configuration
Server = 127.0.0.1 ServerActive = 127.0.0.1 Hostname = Zabbix ServerCopy the code

In the preceding command, Server and ServerActive are the IP addresses of the zabbix-server servers. Hostname is the unique name of the Zabbix-Agent, which must be the same as Hostname

  • Set up zabbixServer upon bootsystemctl enable zabbix-agent
  • Start the zabbix serversystemctl start zabbix-agent