三台主机搭建lnmp环境、部署zabbix

版权声明:如需转载请私信我,经我同意才可转载,转载需附上原地址。 https://blog.csdn.net/qq_26553835/article/details/83269559

环境说明

系统平台 IP 服务
CentOS7
redhat7
192.168.102.11 nginx
CentOS7
redhat7
192.168.102.12 mysql
CentOS7
redhat7
192.168.102.13 php

1、lnmp平台软件安装顺序: nginx --> mysql --> php/
2、关闭防火墙和selinux
3、配置网络源
4、准备好软件包
nginx
mysql
php

操作

安装

  • 192.168.102.11
//安装开发工具包 ‘Development Tools’
[root@server ~]# yum -y groupinstall 'Development Tools'

//安装依赖包
[root@server ~]# yum -y install openssl-devel pcre-devel openssl-devel gd-devel gcc gcc-c++ epel-release


//创建nginx的用户和组
[root@server ~]# groupadd -g  1000 nginx
[root@server ~]# useradd -M -s /sbin/nologin -g 1000 -u 1000 nginx
[root@server ~]# id nginx
uid=1000(nginx) gid=1000(nginx) groups=1000(nginx)

//创建日志存放目录
[root@server ~]# mkdir  -p /var/log/nginx/
[root@server ~]# chown -R nginx.nginx /var/log/nginx/

//编译安装nginx
[root@server ~]# tar -xf nginx-1.14.0
[root@server ~]# cd nginx-1.14.0/
[root@server nginx-1.14.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@server nginx-1.14.0]# make && make install


//将路径写入环境变量
[root@server ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@server ~]# . /etc/profile.d/nginx.sh 

//安装后检查配置是否有错
[root@server nginx-1.14.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


//启动nginx
[root@server nginx-1.14.0]# nginx
[root@server ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      128         :::80                      :::*                  
LISTEN     0      128         :::22                      :::*                  
LISTEN     0      100        ::1:25                      :::*

安装mysql

  • 192.168.102.12
//安装依赖包
[root@client ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel gcc gcc-c++ epel-release

//创建mysql用户和组
[root@client ~]# groupadd -r -g 306 mysql
[root@client ~]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql
[root@client ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)

//解压二进制包,并创建连接修改属主和属组
[root@client ~]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@client ~]# cd /usr/local/
[root@client local]# ln -s mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
[root@client local]# chown -R mysql.mysql mysql

//添加环境变量
[root@client local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@client local]# . /etc/profile.d/mysql.sh

//创建存放数据的目录并修改属主
[root@client local]# mkdir /opt/data 
[root@client local]# chown -R mysql.mysql /opt/data

//初始化数据库
[root@client ~]# mysqld --initialize --user=mysql --datadir=/opt/data
//保存密码
echo '密码' > pass      //密码是最后一个字符串(一般12个字符)
//安装后配置
[root@client ~]# ln -s /usr/local/mysql/include/ /usr/local/include/mysql
[root@client ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.con

//生成配置文件
[root@client ~]# cat > /etc/my.cnf << EOF
[mysqld]
datadir=/opt/data
basedir = /usr/local/mysql
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql 
skip-name-resolve
EOF

//配置服务启动脚本
[root@client ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@client ~]# vim /etc/init.d/mysqld 
basedir=/usr/local/mysql
datadir=/opt/data


//启动mysql
[root@client ~]# service mysqld start
Starting MySQL.Logging to '/opt/data/client.err'.
 SUCCESS! 

//修改密码
[root@lishuai ~]# mysql -uroot -p
Enter password:
mysql> set password=password('ls123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

安装PHP

  • 192.168.102.13
//安装依赖包
[root@lishuai local]# yum -y install 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 mhash mhash-devel gcc gcc-c++ epel-release

//解压并编译安装php
[root@lishuai ~]# tar -xf php-7.2.8.tar.xz 
[root@lishuai ~]# cd php-7.2.8/
[root@lishuai php-7.2.8]#  yum -y install php-mysqlnd
[root@lishuai php-7.2.8]# ./configure --prefix=/usr/local/php7  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir=/usr    --with-openssl  --with-pcre-regex  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd  --with-pdo-sqlite  --with-pear  --with-jpeg-dir  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib  --with-config-file-path=/etc  --with-config-file-scan-dir=/etc/php.d  --with-bz2  --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-xml  --enable-zip
[root@lishuai php-7.2.8]# make && make install


//将路径写入环境变量中
[root@lishuai php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@lishuai php-7.2.8]# . /etc/profile.d/php7.sh 


//配置php-fpm
[root@lishuai php-7.2.8]# cp php.ini-production /etc/php.ini
[root@lishuai php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lishuai php-7.2.8]# chmod +x /etc/init.d/php-fpm 
[root@lishuai php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@lishuai php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default  /usr/local/php7/etc/php-fpm.d/www.conf

//编辑php-fpm配置文件,新添如下几行
[root@lishuai php-7.2.8]# vim /usr/local/php7/etc/php-fpm.conf
pm.max_children = 50     //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5      //启动时启动5个进程
pm.min_spare_servers = 2      //最小空闲进程数
pm.max_spare_servers = 8     //最大空闲进程数
[root@lishuai ~]# vim /usr/local/php7/etc/php-fpm.d/www/conf
user = nginx
group = nginx
listen = 192.168.102.13:9000
[root@lishuai ~]# groupadd -g  1000 nginx
[root@lishuai ~]# useradd -M -s /sbin/nologin -g 1000 -u 1000 nginx

//启动php-fpm
[root@lishuai php-7.2.8]# service php-fpm start
Starting php-fpm  done

配置nginx

  • 192.168.102.11
//在php主机上创建虚拟主机目录并生成php测试页面
[root@server ~]# mkdir /var/www
[root@server ~]# cat > /var/www/index.php << EOF
> <?php
>    phpinfo();
> ?>
> EOF
[root@server ~]# chown -R nginx.nginx /var/www


//配置nginx访问页面
[root@server ~]# vim /usr/local/nginx/conf/nginx.conf
user  nginx;
worker_processes  4;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

                      '$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;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        access_log  logs/host.access.log  main;

        location / {
            root   /var/www;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #}

        #
        location ~ \.php$ {
            fastcgi_pass   192.168.102.13:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

                      '$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;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        access_log  logs/host.access.log  main;

        location / {
            root   /var/www;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        server_name  localhost;

        access_log  logs/host.access.log  main;

        location / {
            root   /var/www;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #}

        #
        location ~ \.php$ {
            fastcgi_pass   192.168.102.13:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

PHP

  • 192.168.102.13
    //在php主机上创建虚拟主机目录并生成php测试页面
[root@lishuai ~]# mkdir /var/www
[root@lishuai ~]# cat > /var/www/index.php << EOF
> <?php
>    phpinfo();
> ?>
> EOF
[root@lishuai ~]# chown -R nginx.nginx /var/www

配置nfs

[root@lishuai ~]# yum -y install nfs-utils
[root@lishuai ~]# vim /etc/exports
/var/www 192.168.102.11(rw,no_root_squash)
[root@lishuai ~]# systemctl start nfs-server
[root@lishuai ~]# systemctl enable nfs-server

192.168.102.11
查看能否看到 然后挂载

[root@server ~]# showmount -e 192.168.102.13
Export list for 192.168.102.13:
/var/www 192.168.102.11
[root@server ~]# mount -t nfs 192.168.102.13:/var/www/ /var/www/
[root@server ~]# vim /etc/fstab
192.168.102.13:/var/www /var/www        nfs     defaults,_netdev 0 0

zabbix部署

192.168.102.11

[root@server ~]# groupadd -r zabbix
[root@server ~]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
[root@server ~]# cd /usr/src/
 [root@server src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz 
[root@server src]# tar xf zabbix-3.4.12.tar.gz


数据库导入

[root@server ~]cd zabbix-3.4.12
[root@server zabbix-3.4.12]# cd database/mysql/
[root@server mysql]# yum -y install mariadb
[root@server mysql]# mysql -uzabbix -pzabbix123! -h192.168.102.12 zabbix < schema.sql
[root@server mysql]# mysql -uzabbix -pzabbix123! -h192.168.102.12 zabbix < images.sql
[root@server mysql]# mysql -uzabbix -pzabbix123! -h192.168.102.12 zabbix < data.sql
[root@server mysql]# cd ..
[root@server mysql]# yum -y install mariadb-devel
[root@server mysql]# yum -y install libxml2-devel
[root@server mysql]# yum -y install libcurl-devel
[root@server zabbix-3.4.12]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
[root@server zabbix-3.4.12]# make install
//修改服务端配置文件
//设置数据库信息
[root@server ~]# vim /usr/local/etc/zabbix_server.conf 
DBHost=192.168.102.12
 DBPassword=zabbix123!       //设置zabbix数据库连接密码
//启动zabbix_server和zabbix_agentd
[root@server ~]# zabbix_server 
[root@server ~]# zabbix_agentd


192.168.102.12

[root@client ~]# mysql -uroot -p
Enter password: 
mysql> create database zabbix character set utf8 collate utf8_bin; 
mysql> grant all privileges on zabbix.* to [email protected] identified by ' zabbix123!'; 
mysql> grant all privileges on zabbix.* to [email protected] identified by ' zabbix123!'; 
mysql> flush privileges;
mysql> quit

192.168.102.13

[root@lishuai ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@lishuai ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini 
[root@lishuai ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@lishuai ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini 
[root@lishuai ~]# service php-fpm restart 

192.168.102.11

[root@server ~]# cd zabbix-3.4.12/
[root@server zabbix-3.4.12]#  cp -a frontends/php/* /var/www
[root@server zabbix-3.4.12]# chown -R nginx.nginx /var/www/
[root@server zabbix-3.4.12]# chmod 777 /var/www/conf
[root@server ~]# nginx -s reload

验证
Windows上访问192.168.102.11/index.php
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_26553835/article/details/83269559