CentOS 7 部署LAMP架構(獨立服務模式)

細節要求:(1) 三者分離于三臺主機,Httpd與PHP以FastCGI模式通訊;

(2) 一個虛擬主機用于提供phpMyAdmin;另一個虛擬主機用于提供wordpress;

(3) 部署PHP加速器:xcache;

一、準備CentOS 7主機環境以及Repo倉庫提供基于rpm安裝包方式的程序包安裝源

安裝主機程序包規劃:

主機1:web-server(192.168.1.132)  –安裝httpd(2.4.6)

主機2:php-server(192.168.1.200)  –安裝php-fpm(5.4.16),php-mysql,xcache,第三方軟件wordpress.phpMyAdmin

主機3:db-server(192.168.1.201)    –安裝mariadb-server(5.5.52)

3臺主機均關閉selinux進程

二、web-server主機服務包與程序安裝過程

#yum install httpd  -y                                                        –安裝httpd服務

#systemctl enable httpd.service                                        –設置httpd服務開機自動運行

#systemctl start httpd.service                                            –啟動httpd服務進程

#systemctl status httpd.serice                                            –查看httpd服務進程狀態

#firewall-cmd –permanent –add-service=http               –設置防火墻允許http服務策略

#firewall-cmd –reload                                                      –加載防火墻策略

#ss -tnl | grep 80                                                               –查看httpd服務監聽狀態

#httpd -M | grep fcgi                                                        –查看httpd服務是否運行fastCGI調用模塊

image.png

三、php-server主機安裝過程

#yum install php-fpm php-mysql php-xcache  -y          –安裝php-fpm服務

#yum install wordpress phpMyAdmin -y                        –安裝第三方軟件

#vim /etc/php-fpm.d/www/conf                                     –配置php-fpm服務參數

listen = 192.168.1.200:9000                                             –設置本機的socket監聽服務

listen.allowed_clients = 192.168.1.132                             –設置允許訪問php-fpm服務的客戶端地址

#systemctl enable php-fpm.service                                 –啟用php-fpm開機自動運行

#systemctl start php-fpm.service                                    –啟動php-fpm服務進程

#systemctl status php-fpm.service                                  –查看服務進程狀態

#firewall-cmd –permanent –add-port=9000/tcp          –設置防火墻允許php-fpm端口策略

#firewall-cmd –reload                                                     –加載防火墻策略

#ss -tnl | grep 9000                                                          –查看php-fpm服務的9000端口是否已啟動并監聽

#mkdir -pv /var/www/http/www                                     –創建測試web-server與php-server代理轉發

#vim /var/www/http/www/index.php                              –創建測試頁面

This is php-server

<?php

     phpinfo();

?>

測試結果

image.pngCentOS 7 部署LAMP架構(獨立服務模式)

針對wordpress第三方軟件的配置

#vim /etc/httpd/conf.d/wordpress.conf

<Directory /usr/share/wordpress>

  AllowOverride Options

  <IfModule mod_authz_core.c>

    # Apache 2.4

   Require all granted                                                   ##允許遠程網絡瀏覽訪問資源

  </IfModule>

  <IfModule !mod_authz_core.c>

    # Apache 2.2

    Order Deny,Allow

    Deny from All

    Allow from 127.0.0.1

    Allow from ::1

</IfModule>

</Directory>

#vim /etc/wordpress/wp-config.php                                                  –定義訪問遠程mariadb數據的信息

// ** MySQL settings – You can get this info from your web host ** //

/** The name of the database for WordPress */

define('DB_NAME', 'test');

/** MySQL database username */

define('DB_USER', 'wordpress');

/** MySQL database password */

define('DB_PASSWORD', 'redhat');

/** MySQL hostname */

define('DB_HOST', '192.168.1.201');

/** Database Charset to use in creating database tables. */

define('DB_CHARSET', 'utf8');

針對phpMyAdmin第三方軟件的配置

#vim /etc/httpd/conf.d/phpMyAdmin.conf

<Directory /usr/share/phpMyAdmin/>

   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>

     # Apache 2.4

     <RequireAny>

       Require all granted                                                         ##允許遠程網絡瀏覽訪問資源

       Require ip ::1

     </RequireAny>

   </IfModule>

   <IfModule !mod_authz_core.c>

     # Apache 2.2

     Order Deny,Allow

     Deny from All

     Allow from 127.0.0.1

     Allow from ::1

   </IfModule>

</Directory>

#vim /etc/phpMyAdmin/config.inc.php                              –僅指定遠程mariadb數據庫IP地址即可,其他保留默認

// The $cfg['Servers'] array starts with $cfg['Servers'][1].  Do not use

// $cfg['Servers'][0]. You can disable a server config entry by setting host

// to ''. If you want more than one server, just copy following section

// (including $i incrementation) serveral times. There is no need to define

// full server array, just define values you need to change.

$i++;

$cfg['Servers'][$i]['host']          = '192.168.1.201'; // MySQL hostname or IP address

$cfg['Servers'][$i]['port']          = '';          // MySQL port – leave blank for default port

$cfg['Servers'][$i]['socket']        = '';          // Path to the socket – leave blank for default socket

$cfg['Servers'][$i]['connect_type']  = 'tcp';       // How to connect to MySQL server ('tcp' or 'socket')

$cfg['Servers'][$i]['extension']     = 'mysqli';    // The php MySQL extension to use ('mysql' or 'mysqli')

$cfg['Servers'][$i]['compress']      = FALSE;       // Use compressed protocol for the MySQL connection

                                                    // (requires PHP >= 4.3.0)

$cfg['Servers'][$i]['controluser']   = '';          // MySQL control user settings

                                                    // (this user must have read-only

$cfg['Servers'][$i]['controlpass']   = '';          // access to the "mysql/user"

                                                    // and "mysql/db" tables).

                                                    // The controluser is also

四、db-server主機安裝過程

#yum install mariadb-server -y                                        –安裝mariadb數據庫服務

#firewall-cmd –permanent –add-service=mysql           –設置防火墻允許mysql服務端口3306

#firewall-cmd –reload                                                     –加載防火墻策略

#vim /etc/my.cnf                                                              –修改mariadb配置文件

skip_name_resolve = ON                                                  –禁用數據庫主機名解析

#systemctl enable mariadb.service                                  –啟用mariadb服務開機自動運行

#systemctl start mariadb.service                                      –啟動mariadb服務

#systemctl status mariadb.service                                    –查看服務進程狀態

#ss -tnl | grep 3306                                                           –查看mysql端口監聽狀態

#/usr/bin/mysql_secure_install                                         –進行數據庫初始化安裝,設置root密碼,是否允許遠程訪問管理等

#mysql -uroot -hlocalhost -p                                           –設置第三方程序訪問數據庫的賬戶權限

Mariadb[(none)]>grant all privileges on test.* to 'wordpress'@'192.168.1.%' identified by 'redhat';       –授予wordpress遠程訪問test數據庫的權限

Mariadb[(none)]>grant all privileges on *.* to 'pmauser'@'192.168.1.%' identified by 'redhat';              –授予pmauser遠程管理mariadb所有數據庫的權限

五、web-server主機上創建虛擬主機,并設置php轉發過程

#mkdir -pv /var/www/http/{www,wordpress,pma}                    –創建不同虛擬主機的主目錄

#touch /var/www/http/{www,wordpress,pma}/index.php         –創建空的.php文件,提供FastCGI轉發

#vim /etc/httpd/conf.d/virtualhost.conf                                    –創建并編輯針對虛擬主機的配置文件

<VirtualHost *:80>                                                                      ##測試FastCGI連通性

   ServerName www.test.com

   DocumentRoot /var/www/http/www

   DirectoryIndex index.php

   ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/var/www/html/$1"

</VirtualHost>

<VirtualHost *:80>                                                                       ##測試phpMyAdmin

   ServerName pma.test.com

   DocumentRoot /var/www/http/pma

   DirectoryIndex index.php

   ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/usr/share/phpMyAdmin/$1"

</VirtualHost>

<VirtualHost *:80>                                                                        ##測試wordpress

   ServerName wordpress.test.com

   DocumentRoot /var/www/http/wordpress

   DirectoryIndex index.php

   ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/usr/share/wordpress/$1"

</VirtualHost>

六、驗證虛擬主機訪問

訪問http://pma.test.com/phpmyadmin  虛擬主機

image.png

輸入運行數據庫遠程訪問的賬戶信息,打開圖形化管理數據庫的頁面

image.png

訪問http://wordpress.test.com 虛擬主機

image.png

原創文章,作者:N24_shishen,如若轉載,請注明出處:http://www.www58058.com/69017

(0)
N24_shishenN24_shishen
上一篇 2017-02-17 08:48
下一篇 2017-02-17 16:42

相關推薦

  • 第十九周作業

    1.描述tomcat的架構 tomcat服務器是一種Servlet/jsp容器,更實質性的說是Servlet容器,因為jsp最終還是被編譯成servlet來執行的。而對于servlet來說,其最長見的用途是擴展java web服務器功能,為來自web客戶的請求提供服務。它完全運行在java虛擬機上。由于它的運行在服務器端,因此他的運行不依賴于瀏覽器。 tom…

    2017-07-11
  • n28 第二周作業

    n28 第二周作業

    Linux干貨 2017-12-09
  • grep基本正則表達式以及擴展正則表達式

    基本正則表達式: grep:Globel serach REgular expression and print out the line 作用:文本搜索工具,根據用戶指定的“模式(過濾條件)”對目標文本逐行進行匹配檢查,打印匹配到的行 模式:由正則表達式的元字符及文本字符所編寫出的過濾條件 grep選項:       &nbs…

    Linux干貨 2016-08-08
  • 系統基礎之Btrfs文件系統詳解

    btrfs文件系統:技術預覽版(centos7) 描述: Btrfs(B-tree,Butter FS,Better fs),GPL授權,Orale,2007 寫實復制特性(Cow)     cp –reflink (只能在btrfs文件系統中使用) 想取代ext系統系統, 支…

    Linux干貨 2016-09-21
  • 編譯安裝nginx并實現反向代理負載均衡和緩存功能

    一、編譯安裝nginx 1、下載 [root@ns1 ~]# wget http://nginx.org/download/nginx-1.10.0.tar.gz 2、解壓 [root@ns1 ~]# tar xf nginx-1.10.0.tar.gz [root@ns1 ~]…

    Linux干貨 2016-05-25
  • 二進制、八進制、十進制、十六進制之間的轉換

    二進制、八進制、十進制、十六進制之間的關系:   二進制:0,1 八進制:0,1,2,3,4,5,6,7, 十進制:0,1,2,3,4,5,6,7,8,9 十六進制:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F   二進制與十進制之間的轉換: 十進制轉二進制:   二進制轉十進制:   二進制與八進制…

    2017-04-01

評論列表(2條)

  • luoweiro
    luoweiro 2017-02-23 07:31

    對于分開部署,后期學到nginx的時候,也可以多采用這種方式,但是要注意如果是多臺機器如何做負載均衡,負載均衡的策略是怎樣的?

    • N24_shishen
      N24_shishen 2017-02-24 10:58

      @luoweiro
      好的。有待后期繼續學習新的知識點以后,在來更新。

欧美性久久久久