lnmp的两台主机搭建

文章目录

    • 一、环境说明
    • 二、安装nginx和mysql+php
      • 1.安装mysql和php
      • 2.安装nginx
      • 3.验证lnmp是否成功
      • 4.安装zabbix
      • 5.安装NFS
      • 6.验证zabbix界面是否能登陆

一、环境说明

主机说明 ip 系统说明
qy-nginx+NFS 192.168.69.130 centos7
qy-mysql-php-zabbix 192.168.69.133 centos7

二、安装nginx和mysql+php

lnmp的两台主机搭建_第1张图片

1.安装mysql和php

[root@mysql-php ~]#yum groups mark install 'Development Tools'
[root@mysql-php ~]#yum -y install wget bzip2 bzip2-devel gcc gcc-c++
[root@mysql-php ~]#  yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@mysql-php ~]# groupadd -r -g 306 mysql
[root@mysql-php ~]# useradd -r -M -s /sbin/nologin -g mysql mysql
[root@mysql-php src]# ls
debug  kernels  mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@mysql-php src]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql-php src]# cd /usr/local/
[root@mysql-php local]# ln -s mysql-5.7.23-linux-glibc2.12-x86_64/  mysql
[root@mysql-php local]# chown -R mysql.mysql /usr/local/mysql
[root@mysql-php local]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36 3月   2 16:18 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/
[root@mysql-php local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mysql-php local]# . /etc/profile.d/mysql.sh
[root@mysql-php ~]# mkdir /opt/data
[root@mysql-php ~]# chown -R mysql.mysql /opt/data/
[root@mysql-php ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
[root@mysql-php ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@mysql-php ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@mysql-php ~]# cat > /etc/my.cnf < [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@mysql-php ~]#cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql-php ~]#sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@mysql-php ~]#sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
[root@mysql-php ~]#service mysqld start
[root@mysql-php ~]#mysql> set password = password(qinyong');
[root@mysql-php ~]#cd /usr/src/
[root@mysql-php ~]#wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@mysql-php ~]#tar xf php-7.2.8.tar.xz
[root@mysql-php ~]#cd /usr/src/php-7.2.8
[root@mysql-php ~]# ./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-mysqli=/usr/local/mysql/bin/mysql_config \
 --with-openssl \
 --with-pcre-regex \
 --with-pdo-mysql \
 --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
 make && make install &> /dev/null
 if [ $? -ne 0 ];then
     exit
     echo "php失败"
 else
     echo "php成功"
 fi
[root@mysql-php ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@mysql-php ~]# source /etc/profile.d/php7.sh
[root@mysql-php ~]# which php
[root@mysql-php ~]# php -v 
[root@mysql-php ~]# cp php.ini-production /etc/php.ini
[root@mysql-php ~]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@mysql-php ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@mysql-php ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@mysql-php ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@mysql-php ~]# cat >> /usr/local/php7/etc/php-fpm.conf << EOF
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
EOF
[root@mysql-php ~]# service php-fpm restart
[root@mysql-php ~]# mkdir /var/www
[root@mysql-php ~]# cat > /var/www/index.php << EOF

EOF
[root@mysql-php ~]# chown -R nginx.nginx /var/www

2.安装nginx

安装nginx

####1.准备环境#####
[root@qy-nginx ~]# setenforce 0
[root@qy-nginx ~]# systemctl stop firewalld
[root@qy-nginx ~]# yum -y install wget vim
####2.安装nginx软件#####
[root@qy-nginx ~]# useradd -r -M -s /sbin/nologin nginx
[root@qy-nginx ~]# cd /usr/src/
[root@qy-nginx src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@qy-nginx src]# yum -y groups mark install 'Development Tools'
[root@qy-nginx src]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@qy-nginx src]# mkdir -p /var/log/nginx
[root@qy-nginx src]#chown -R nginx.nginx /var/log/nginx
[root@qy-nginx src]# tar -xf nginx-1.12.0.tar.gz
[root@qy-nginx src]# cd nginx-1.12.0
[root@qy-nginx nginx-1.12.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@qy-nginx nginx-1.12.0]#make && make install
[root@qy-nginx nginx-1.12.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@qy-nginx nginx-1.12.0]# chmod +x /etc/profile.d/nginx.sh 
[root@qy-nginx nginx-1.12.0]# . /etc/profile.d/nginx.sh
[root@qy-nginx nginx-1.12.0]# vim /etc/init.d/nginx
#/bin/bash
case \$1 in
start)
       /usr/local/nginx/sbin/nginx
        if
                [ $? -ne 0 ];then
                echo 'start failed'
        else
                echo 'start success'  
        fi
        ;;
stop)
        /usr/local/nginx/sbin/nginx -s stop
        if
                [ $? -ne 0 ];then
                echo 'stop failed'
        else
                echo 'stop success'  
        fi
        ;;
restart)
        /usr/local/nginx/sbin/nginx -s stop
        /usr/bin/sleep 1
        /usr/local/nginx/sbin/nginx
        if
                [ $? -ne 0 ];then
                echo 'restart failed'
        else
                echo 'restart success'  
        fi
        ;;
reload)
        /usr/local/nginx/sbin/nginx -s reload
        if
                [ $? -ne 0 ];then
                echo 'reload failed'
        else
                echo 'reload success'  
        fi
        ;;
esac
[root@qy-nginx nginx-1.12.0]# vim /usr/local/nginx/conf/nginx.conf
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            alias          /var/www;
            fastcgi_pass   192.168.69.133:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
            include        fastcgi_params;
        }


[root@qy-nginx ~]#mkdir -p /var/log/nginx
[root@qy-nginx ~]#chown -R nginx.nginx /var/log/nginx
[root@qy-nginx ~]#nginx -s reload
[root@qy-nginx ~]#systemctl stop firewalld
[root@qy-nginx ~]#setenforce 0
[root@qy-nginx ~]#chmod +x /etc/init.d/nginx
[root@qy-nginx ~]#service nginx start

3.验证lnmp是否成功

lnmp的两台主机搭建_第2张图片

4.安装zabbix

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  php-7.2.8  php-7.2.8.tar.xz  zabbix-4.0.4.tar.gz
[root@localhost src]# yum -y install net-snmp-devel libevent-devel
[root@localhost src]#  groupadd -r zabbix
[root@localhost src]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
[root@localhost src]# tar xf zabbix-4.0.4.tar.gz 
[root@localhost src]# cd zabbix-4.0.4/
[root@localhost zabbix-4.0.4]# mysql -uroot -pqinyong                       建立zabbix数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
[root@localhost ~]# cd /usr/src/zabbix-4.0.4/database/mysql/
[root@localhost mysql]# ls
data.sql  images.sql  Makefile.am  Makefile.in  schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# cd /usr/src/zabbix-4.0.4/
[root@localhost zabbix-4.0.4]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[root@localhost zabbix-4.0.4]# make && make install
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# sed -i 's/(max_input_time=)*/\1 300/g' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

5.安装NFS

[root@localhost ~]# yum -y install nfs-utils
[root@localhost zabbix-4.0.4]# systemctl start nfs-server
[root@localhost zabbix-4.0.4]# systemctl enable nfs-server
[root@localhost zabbix-4.0.4]# cp -a frontends/php/* /var/www/
cp:是否覆盖"/var/www/index.php"? Y
[root@localhost zabbix-4.0.4]# chmod 777 /var/www/conf
[root@localhost zabbix-4.0.4]# cat /etc/exports
/var/www 192.168.69.130(insecure,rw,no_root_squash)
[root@localhost zabbix-4.0.4]#  systemctl restart nfs-server

在192.168.69.130修改

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
        location ~ \.php$ {
        alias           /var/www;
            fastcgi_pass   192.168.69.133:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
            include        fastcgi_params;     
       }
[root@localhost ~]# yum -y install showmount
[root@localhost ~]# showmount -e 192.168.69.133
Export list for 192.168.69.133:
[root@localhost ~]# mount -t nfs 192.168.69.133:/var/www/ /usr/local/nginx/html
[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   17G  1.5G   16G    9% /
devtmpfs                 899M     0  899M    0% /dev
tmpfs                    911M     0  911M    0% /dev/shm
tmpfs                    911M  9.5M  902M    2% /run
tmpfs                    911M     0  911M    0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M   14% /boot
tmpfs                    183M     0  183M    0% /run/user/0
192.168.69.133:/var/www   17G  9.9G  7.2G   58% /usr/local/nginx/html
[root@localhost ~]# vim /etc/fstab
192.168.69.133:/var/www /usr/local/nginx/html nfs defaults,_netdev 0 0
[root@localhost ~]# systemctl stop firewalld

6.验证zabbix界面是否能登陆

lnmp的两台主机搭建_第3张图片
lnmp的两台主机搭建_第4张图片

你可能感兴趣的:(nginx,lnmp,NFS,linux,运维知识,zabbix)