版本

Centos7 php7.2.1+mysql5.6+zabbix4.2.3+nginx1.14
#期望安装php+zabbix+nginx到/data目录下方便管理

  1. mkdir -p /data/installation && cd /data

1.安装PHP

安装相关依赖,并编译安装php 7.2.1(php版本需要大于5+)

  • php官网
    • https://www.php.net/downloads.php
      1. yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libicu-devel libxslt-devel gcc-c++ glibc-headers
      2. wget https://www.php.net/distributions/php-7.2.1.tar.gz
      3. tar -xvf php-7.2.1.tar.gz && cd php-7.2.1
      4. useradd -M -s /sbin/nologin php
      5. ./configure \
      6. --prefix=/data/php \
      7. --with-mhash \
      8. --with-openssl \
      9. --with-config-file-path=/data/php/etc \
      10. --disable-short-tags \
      11. --enable-fpm \
      12. --with-fpm-user=php \
      13. --with-fpm-group=php \
      14. --enable-xml \
      15. --with-libxml-dir \
      16. --enable-bcmath \
      17. --enable-calendar \
      18. --enable-intl \
      19. --enable-mbstring \
      20. --enable-pcntl \
      21. --enable-shmop \
      22. --enable-soap \
      23. --enable-sockets \
      24. --enable-zip \
      25. --enable-mbregex \
      26. --enable-mysqlnd \
      27. --enable-mysqlnd-compression-support \
      28. --with-mysqli=mysqlnd \
      29. --with-pdo-mysql=mysqlnd \
      30. --with-gd \
      31. --enable-ftp \
      32. --with-curl \
      33. --with-xsl \
      34. --with-iconv \
      35. --with-freetype-dir \
      36. --with-jpeg-dir \
      37. --with-png-dir \
      38. --with-zlib \
      39. --enable-sysvsem \
      40. --enable-inline-optimization \
      41. --with-xmlrpc \
      42. --with-gettext
      使用最大CPU核数编译后安装
      1. make -j `nproc ` && make install
      开机自启动
      1. mv /data/php/etc/php-fpm.conf.default /data/php/etc/php-fpm.conf
      2. mv /data/php/etc/php-fpm.d/www.conf.default /data/php/etc/php-fpm.d/www.conf
      3. cp /data/installation/php-7.2.1/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
      4. chmod 766 /etc/init.d/php-fpm
      5. systemctl daemon-reload
      6. /sbin/chkconfig php-fpm on
      7. service php-fpm restart
      上传php.ini到/data/php/etc/
      1. wget https://2070n1o927.iok.la/source/Centos7_installation/php/php.ini
      2.安装MYSQL

下载mysql-5.6.16.tar.gz至/data,并安装相关依赖以及解压

  • mysql官网
    • https://dev.mysql.com/get/Downloads/
      1. yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make sysstat
      2. useradd -M -s /sbin/nologin mysql
      3. cd /data && wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz
      4. tar -xvf mysql-5.6.16.tar.gz && cd mysql-5.6.16
      编译配置
      1. cmake \
      2. -DCMAKE_INSTALL_PREFIX=/data/mysql \
      3. -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
      4. -DSYSCONFDIR=/etc \
      5. -DSYSTEMD_PID_DIR=/data/mysql \
      6. -DDEFAULT_CHARSET=utf8 \
      7. -DDEFAULT_COLLATION=utf8_general_ci \
      8. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
      9. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
      10. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
      11. -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
      12. -DMYSQL_DATADIR=/data/mysql/data \
      13. -DWITH_SYSTEMD=1
      使用最大CPU核数编译后安装
      1. make -j `nproc ` && make install
      修改编译安装完成后的文件夹权限
      1. chown -R mysql:mysql /data/mysql/
      初始化数据库
      1. /data/mysql/bin/mysqld \
      2. --initialize-insecure \
      3. --user=mysql \
      4. --basedir=/data/mysql \
      5. --datadir=/data/mysql/data
      mysql配置文件 ```bash cat > /etc/my.cnf << EOF [mysqld] datadir=/data/mysql/data socket=/data/mysql/mysql.sock user=mysql

      若取消注释,表示允许本地无密码登陆。

      skip-grant-tables

      表示允许任何IP都可以访问mysql服务

      bind-address = 0.0.0.0

      最大连接数

      max_connections=3000

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

[mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] socket=/data/mysql/mysql.sock EOF

  1. 开机自启动
  2. ```bash
  3. cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
  4. /data/mysql/scripts/mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
  5. /data/mysql/bin/mysqld_safe --user=mysql &
  6. systemctl daemon-reload
  7. systemctl enable mysqld
  8. /sbin/chkconfig mysqld on
  9. systemctl restart mysqld
  10. netstat -anpt | grep 3306

安装mysql客户端

yum install mysql mysql-server

停止防火墙(按自己需求)

systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables

3.安装ZABBIX

下载zabbix-4.2.3.tar.gz至/data,并安装相关依赖以及解压

  • zabbix官网
    • https://www.zabbix.com/download_sources
      cd /data
      yum install expect net-snmp gcc  mysql-devel  libxml2-devel  net-snmp-devel  libevent-devel  curl-devel -y
      wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.2.3/zabbix-4.2.3.tar.gz/download && mv download zabbix-4.2.3.tar.gz
      tar -xvf  zabbix-4.2.3.tar.gz  && cd zabbix-4.2.3
      useradd -M -s /sbin/nologin zabbix
      
      编译配置
      ./configure --prefix=/data/zabbix \
      --with-mysql=/data/mysql/bin/mysql_config \
      --with-net-snmp \
      --with-openssl \
      --with-libcurl \
      --with-libxml2 \
      --with-libpcre \
      --with-iconv \
      --enable-server \
      --enable-agent \
      --enable-proxy \
      --enable-ipv6
      
      使用最大CPU核数编译后安装
      make -j `nproc ` && make install
      
      配置zabbix_server自启动(有兴趣深入的,可以研究一下自启动文件,以及为什么做软连接)
      ln -s /data/zabbix/sbin/zabbix_server /usr/local/sbin/zabbix_server
      ln -s /data/zabbix/bin/zabbix_get /usr/local/sbin/zabbix_get
      mv /data/zabbix/share/zabbix /data/zabbix/share/zabbix_bak
      cp -r /data/zabbix-4.2.3/frontends/php /data/zabbix/share/zabbix
      cp /data/zabbix-4.2.3/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
      mv /data/zabbix-4.2.3* /data/installation/
      chmod 766 /etc/init.d/zabbix_server
      systemctl daemon-reload
      systemctl enable zabbix_server
      /sbin/chkconfig zabbix_server on
      sed -i 's/# DBPassword=/DBPassword=zabbix/g' /data/zabbix/etc/zabbix_server.conf
      sed -i 's/# DBSocket=/DBSocket=\/data\/mysql\/mysql.sock/g' /data/zabbix/etc/zabbix_server.conf
      service zabbix_server restart
      

修改zabbix-agent配置文件中zabbix-server的 IP地址,以及本机主机名。

sed -i 's/Server=127.0.0.1/Server=172.16.169.191/g' /data/zabbix/etc/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=172.16.169.191/g' /data/zabbix/etc/zabbix_agentd.conf
sed -i 's/Hostname=Zabbix server/Hostname=tenant-saas-s/g' /data/zabbix/etc/zabbix_agentd.conf

配置zabbix_agent自启动(有兴趣稍微研究一下自启动文件,以及为什么做软连接)

ln -s /data/zabbix/sbin/zabbix_agentd /usr/local/sbin/zabbix_agentd
cp /data//installation/zabbix-4.2.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
chmod 766 /etc/init.d/zabbix_agentd
systemctl daemon-reload
/sbin/chkconfig zabbix_agentd on
systemctl enable zabbix_agentd
service zabbix_agentd restart

编译安装的字体路径需要修改否则显示吅吅吅吅

wget https://2070n1o927.iok.la/source/Windows/simkai.ttf -O /data/zabbix/share/zabbix/assets/fonts/simkai.ttf
sed  -i.ori 's/DejaVuSans/simkai/g' /data/zabbix/share/zabbix/include/defines.inc.php

mysql数据库中建立zabbix的库以及zabbix用户

mysql  << EOF
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
EOF
mysql -u zabbix -pzabbix --database zabbix < /data/zabbix-4.2.3/database/mysql/schema.sql
mysql -u zabbix -pzabbix --database zabbix < /data/zabbix-4.2.3/database/mysql/images.sql
mysql -u zabbix -pzabbix --database zabbix < /data/zabbix-4.2.3/database/mysql/data.sql

4.安装nginx

下载nginx1.1.14.tar.gz至/data,并安装相关依赖以及解压

  • nginx官网
    • http://nginx.org/en/download.html
      cd /data
      yum -y install gcc gcc-c++ autoconf automake make unzip net-tools sysstat 
      yum -y install pcre-devel openssl openssl-devel
      tar -xvf /data/nginx-1.14.0.tar.gz && cd /data/nginx-1.14.0
      ./configure --prefix=/data/nginx --user=root --group=root --with-threads --with-http_realip_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_slice_module 
      make -j `nproc ` && make install
      mkdir -p /data/nginx/conf/{conf.d,certs}
      mv /data/nginx-1.14.0* /data/installation && cd /data
      echo 'PATH=$PATH:/data/nginx/sbin' >> /etc/profile
      source /etc/profile
      

      配置nginx

vim /data/nginx/conf/nginx.conf

# Nginx Main Configure File.
# NGINX启动用户
 user  root;
# CPU核数
 worker_processes  8;
 events {
     worker_connections  65535;
     }
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

#配置文件路径
include conf.d/*.conf;
}

配置nginx 虚拟主机zabbix

vim /data/nginx/conf/conf.d/zabbix.conf
#修改 server_name

###
server {
        listen       80;
        server_name  192.168.2.177;
        access_log logs/zabbix_acc.log;
        error_log logs/zabbix_err.log;

  # 其他常规配置项自行补充
        root /data/zabbix/share;
        index  index.htm index.html index.php;
        location /zabbix {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ .*\.(php)?$ {
                expires -1s;
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass 127.0.0.1:9000;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

}

配置nginx自启动

cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx project
After=nginx.service

[Service]
Type=forking
User=root
Group=root
PIDFile=/data/nginx/logs/nginx.pid
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload 
#也可以通过环境变量启动
ExecStop=/data/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx

访问zabbix
http://ip