三台主机搭建lnmp

1、环境说明

使用三台主机分别搭建nginx,mysql,php组成lnmp架构

系统说明 ip 安装服务
centos7 192,.168.69.128 nginx
redhat 192.168.69.130 mysql
centos7 192.168.69.134 php

2、准备好环境关闭防火墙和setlinux

[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[[email protected] ~]# setenforce 0 
[[email protected] ~]# yum -y install wget vim

3、下载好二进制包

搭建仓库下载二进制包
[[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected]  yum.repos.d]# sed -i 's/$releasever/7/g' CentOS-Base.repo 
nginx  [[email protected] ~]#wget http://nginx.org/download/nginx-1.12.0.tar.gz
mysql  [[email protected] ~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
PHP    [[email protected] ~]#wget http://cn.php.net/distributions/php-7.2.8.tar.xz

4、安装配置

4.1.先从192.168.69.128 nginx开始

[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[[email protected] ~]# yum -y groups mark install 'Development Tools'
[[email protected] ~]# groupadd -r nginx
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g nginx nginx
[[email protected] ~]#  groupadd -r nginx
[[email protected] ~]# mkdir  -p /var/log/nginx/
[[email protected] ~]# chown -R nginx.nginx /var/log/nginx/
[[email protected] ~]# tar -xf nginx-1.12.0.tar.gz
[[email protected] 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
[[email protected] nginx-1.12.0]#make && make install
[[email protected] nginx-1.12.0]# echo 'export PATH=/usr/local/nginx/bin:$PATH' > /etc/profile.d/nginx.sh
[[email protected] nginx-1.12.0]# . /etc/profile.d/nginx.sh 
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
error_log  logs/error.log;                                     \\取消错误日志的注释
                                                                 \\启用这几行
events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

 server {
        listen       80;                                \\监听80端口
        server_name  192.168.69.130;

        charset koi8-r;

        access_log  logs/host.access.log  main;

        location / {
            root   /www/qinyong;                                 \\存放网页路径
            index  index.html index.htm;
        }
        #取消下面的注释
 location ~ \.php$ {
            root           /www/qinyong;
            fastcgi_pass   192.168.69.134:9000;     \\php服务器的ip
            fastcgi_index  index.php ;                \\和访问文件名相同
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

4.2.然后192.168.69.130 mysql开始

[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[[email protected] ~]# groupadd -r mysql
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g mysql mysql
[[email protected] ~]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] local]# ln -s mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
[[email protected] src]# groupadd -r mysql
[[email protected] src]# useradd -M -s /sbin/nologin -g mysql mysql 
[[email protected] local]# chown -R mysql.mysql /usr/local/mysql
[[email protected] local]# ll /usr/local/mysql -d
[[email protected] local]# . /etc/profile.d/mysql.sh
[[email protected] local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[[email protected] local]# . /etc/profile.d/mysql.sh 
[[email protected] local]# echo $PATH
[[email protected] local]# mkdir /opt/data
[[email protected] local]# chown -R mysql.mysql /opt/data
[[email protected] local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
[[email protected] data]# cat > /etc/my.cnf <<EOF
> [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
[[email protected] data]#  cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] data]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql                                  添加路径
datadir=/opt/data
[[email protected] data]# service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
. SUCCESS! 
mysql> set password = password('qinyong123!') ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

4.2.然后192.168.69.134 php开始

[[email protected] ]# yum -y install libxml2 libxml2-devel openssl openssl-de vel 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++
[[email protected] ~]# tar -xf php-7.2.8.tar.gz 
[[email protected] ~]# cd php-7.2.8
[[email protected] ~]# ./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  
--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
 [[email protected] ~]#make && make install
 [[email protected] php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[[email protected] php-7.2.8]# . /etc/profile.d/php7.sh
[[email protected] ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] php-7.2.8]# cp php.ini-production /etc/php.ini
[[email protected] php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[[email protected] php-7.2.8]#cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[[email protected] php-7.2.8]#cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[[email protected] ~]# 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                   //最大空闲进程数
[[email protected] php-7.2.8]# service php-fpm start
[[email protected] php-7.2.8]# ss -antl
State       Recv-Q Send-Q                                                           Local Address:Port                                                                          Peer Address:Port              
LISTEN      0      128                                                                  127.0.0.1:9000                                                                                     *:*                  
LISTEN      0      128                                                                          *:22                                                                                       *:*                  
LISTEN      0      100                                                                  127.0.0.1:25                                                                                       *:*                  
LISTEN      0      128                                                                         :::22                                                                                      :::*                  
LISTEN      0      100                                                                        ::1:25                                                                                      :::*        
[[email protected] ~]#mkdir /www/qinyong/ -p
[[email protected] ~]#vim /www/qinyong/index.php
<?php
     phpinfo();
?>
[[email protected] ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 192.168.69.134:9000		##注:监听的IP地址改为服务器的IP地址,端口为9000
listen.allowed_clients = 192.168.69.128		##注:允许192.168.69.128这台服务器访问

验证结果

三台主机搭建lnmp

相关文章:

  • 2021-07-18
  • 2021-08-02
  • 2021-10-05
  • 2021-05-03
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-06-05
  • 2022-12-23
  • 2021-05-04
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案