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 分離安裝

相關文章
相關標籤/搜索