LNMP 分离安装

不少人在搭建的时候都是使用的一台机器来部署LNMP环境,可是咱们在实际的工做中通常都是分离部署的。也就是说MySQL是MySQL;它是一台单机,分离部署本身跑本身的服务,提升效率!
三台机器来部署LNMP环境,以下:
LNMP 分离安装php

OS:Centos7.3x86_64
Nginx-1.12.2 IP地址:192.168.10.101
PHP-5.5 IP地址:192.168.10.103
MySQL5.7 IP地址:192.168.10.105
NFS的IP地址:192.168.10.105html

一:NFS的安装
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbindmysql

(2)设置共享目录
[root@localhost ~]# mkdir -p /opt/wwwroot
[root@localhost ~]# vi /etc/exports
/opt/wwwroot 192.168.10.0/24(rw,sync,no_root_squash)nginx

[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl start rpcbindsql

2、安装Nginx数据库

1)安装相关的依赖包
[root@nginx ~]# yum install -y gcc* zlib-devel pcre-develvim

2)创建Nginx用户指定id
[root@nginx ~]#useradd -u 1001 nginxapi

3)下载Nginx源码安装包并安装
[root@nginx src]# tar zxf nginx-1.12.2.tar.gz
[root@nginx src]# cd nginx-1.12.2/
[root@nginx-1.12.2]#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install 服务器

4)建立软链接并启动Nginx访问测试
[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 负载均衡

[root@nginx nginx-1.12.2]# 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

[root@nginx nginx-1.12.2]# nginx
[root@nginx nginx-1.12.2]# netstat -anput | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27185/nginx: master

LNMP 分离安装

[root@localhost ~]#mkdir /www
[root@localhost ~]# mount 192.168.10.105:/opt/wwwroot /www

到这里Nginx已经安装完毕,接下来安装php

2、安装PHP

1)安装相关的依赖包
[root@localhost ~]# yum -y install gcc* libxml2-devel pcre-devel zlib-devel

3)正式安装php
[root@localhost ~]#useradd nginx
[root@localhost ~]# tar zxvf php-5.5.38.tar.gz
[root@localhost ~]# cd php-5.5.38/

[root@localhost php-5.5.38]# ./configure --prefix=/usr/local/php --with-mysql --with-mysqli --enable-fpm && make && make install

提供PHP的配置文件及服务脚本
[root@localhost php-5.5.38]# cp php.ini-production /etc/php.ini

提供php-fpm的服务控制脚本
[root@php php-5.5.38]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.5.38]# chmod +x /etc/init.d/php-fpm
[root@localhost php-5.5.38]# chkconfig --add php-fpm

[root@localhost php-5.5.38]# chkconfig php-fpm on

修改php-fpm主配置文件,并编辑以下:
[root@localhost php-5.5.38]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@localhost php-5.5.38]# vi /usr/local/php/etc/php-fpm.conf
修改内容以下:
pid = run/php-fpm.pid
user = nginx
group = nginx
listen = 192.168.10.103:9000 //PHP主机的IP地址
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
修改完成后启动php服务
[root@localhost php-5.5.38]# service php-fpm restart

[root@localhost ~]#mkdir /www
[root@localhost ~]# mount 192.168.10.105:/opt/wwwroot /www

到这里咱们的php完成!接下来安装MySQL

3、安装MySQL
注:能够用yum安装数据库,那么下面安装mysql的步骤就不须要了
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

[root@localhost ~]# yum -y install mariadb-server mariadb
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysqladmin -u root password "pwd123"

4、配置Nginx支持PHP环境
[root@nginx ~]#vim /usr/local/nginx/conf/nginx.conf
user nginx;

location / {
root /www; 更改网页目录
index index.php index.html index.htm; 添加index.php
}

location ~ .(gif|jpg|jpeg|png|bmp|swf)$ {
root /www;
}

location ~ .php$ {
root /www; 更改目录
fastcgi_pass 192.168.10.102:9000; 注意:在这里添加PHP主机IP地址
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}

若是要作php的负载均衡,nginx的配置文件修改以下:

upstream wordpress {
server 192.168.10.101:9000;
server 192.168.10.102:9000;
}
server {
listen 80;
server_name localhost;
root /www;
charset utf8;

location / {
        index  index.html index.htm index.php;
   }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location ~ \.php$ {
        fastcgi_pass   wordpress;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi.conf;
    }
}

}

[root@nginx ~]# mkdir /www
[root@nginx ~]# chown nginx:nginx /www/
[root@nginx ~]# cd /www/
[root@nginx www]# vim index.php
[root@nginx www]# cat index.php
<?php
phpinfo();
?>
到这里咱们先别重启Nginx接下来在PHP主机操做(1.20)

[root@php ~]# mkdir /www
[root@php ~]# chown -R nginx:nginx /www/
[root@php ~]# cd /www/
[root@php www]# vim index.php
[root@php www]# cat index.php
<?php
phpinfo();
?>
建立完成后接下来咱们重启nginx以及php,访问测试页(1.10&1.20操做)

[root@nginx www]# nginx -s reload
[root@php www]# service php-fpm restart
LNMP 分离安装

访问到如上图那么证实咱们的nginx支持PHP了接下来咱们部署wordpress我的站点
在部署前咱们在数据库服务器上建立wordpress数据库及受权账户(Mysql服务器操做1.30)

五:wordpress网站的部署
1:在mysql中
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on wordpress.* to yankerp@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

2:在nfs中
[root@nginx ~]# tar zxf wordpress-4.9.1-zh_CN.tar.gz
[root@nginx ~]# mv wordpress/* /opt/wwwroot
[root@nginx ~]# useradd nginx
[root@nginx ~]# chown -R nginx:nginx /opt/wwwroot

当咱们建立了yankai的用户咱们查看数据库

LNMP 分离安装

LNMP 分离安装

相关文章
相关标签/搜索