LAMP+NFS實現多個web服務器靜態資源統一存儲

1.前端需支持更大的訪問量,單臺Web服務器已無法滿足需求了,則需擴容Web服務器;

2.雖然動態內容可交由後端的PHP服務器執行,但靜態頁面還需要Web服務器自己解析,那是否意味着多臺Web服務器都需要在各自的系統中都存有一份靜態頁面數據呢?

   其實這樣也不是不可以,畢竟文件本地訪問,速度還是有優勢的,但這卻涉及到多臺Web服務器間內容的一致性問題,這種問題也不可避免;

   那麼如果能將靜態頁面集中存放,所有Web服務器都來集中地取文件,對於文件的一致性就有了保障,這個集中地就叫做“文件共享服務器”;

   文件共享有多種方式,FTPNFSSamba等,而其中NFS作爲網絡文件系統,允許一個系統通過網絡共享目錄和文件,通過使用NFS,用戶和程序可以像訪問本地文件一樣訪問遠端系統上的文件,這種近似訪問本地文件系統的架構貌似很符合我們的需求,我們現在就來實現這個需求!

 

需求實現:

1.web1充當http服務器和DNS解析服務器,客戶端到web1web2的請求,如果是靜態資源請求通過php主機的NFS服務掛載的存儲返回結果

2.web1web2對於客戶端動態資源請求都反向代理到後端php服務器進行執行後返回結果

3.web1web2實現DNS輪詢,客戶端訪問博客網站是負載均衡的。

4.建立wordpress博客

5.數據庫存儲wordpress博客的各種數據


實驗架構:

                             wKioL1Sb9s2xNKs0AALaFr8q1Zg463.jpg

部署實現

一.DNS服務器在web1上的實現

開發環境配置

1 # yum –y groupinstall Development Tools

配置DNS服務器:

安裝DNS服務器軟件bind

1 #yum –y install bind

配置DNS主配置文件:

01 # vim /etc/named.conf
02 //
03 //named.conf
04 //
05 //Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
06 // serveras a caching only nameserver (as a localhost DNS resolver only).
07 //
08 // See/usr/share/doc/bind*/sample/ for example named configuration files.
09 //
10   
11 options {
12 //      listen-on port 53 { 127.0.0.1; };
13 //      listen-on-v6 port 53 { ::1; };
14         directory       "/var/named";
15         dump-file      "/var/named/data/cache_dump.db";
16         statistics-file"/var/named/data/named_stats.txt";
17         memstatistics-file"/var/named/data/named_mem_stats.txt";
18 //      allow-query     { localhost; };
19         recursion yes;
20   
21 //      dnssec-enable yes;
22 //      dnssec-validation yes;
23 //      dnssec-lookaside auto;
24   
25         /* Path to ISC DLV key */
26         /*bindkeys-file"/etc/named.iscdlv.key";
27   
28         managed-keys-directory"/var/named/dynamic";
29         */
30 };
31   
32 logging {
33         channel default_debug {
34                 file"data/named.run";
35                 severity dynamic;
36         };
37 };
38   
39 zone"." IN {
40         type hint;
41         file "named.ca";
42 };
43   
44 include"/etc/named.rfc1912.zones";
45 include "/etc/named.root.key";

 

配置主區域文件:只是在文件尾部添加正向區域

1 # vim /etc/named.rfc1912.zones
2 zone"stu31.com" IN {
3         type master;
4         file "stu31.com.zone";
5 };

 

配置正向區域解析庫文件:

這裏讓客戶端查詢http服務器時能輪換查詢到兩臺web服務器。

01 # vim/var/named/stu31.com.zone
02 $TTL 600
03 $ORIGINstu31.com.
04 @       IN     SOA     ns.stu31.com.   root.stu31.com. (
05                         2014122301
06                         1H
07                         3M
08                         5D
09                         6H )
10 @       IN     NS      ns
11         IN     MX  5   mail
12 ns      IN     A       172.16.31.30
13 www     IN     A       172.16.31.30
14 www     IN     A       172.16.31.31
15 mail    IN      A      172.16.31.30

 配置文件語法檢查:

1 #named-checkzone  stu31.com /var/named/stu31.com.zone  
2 zonestu31.com/IN: loaded serial 2014122301
3 OK

 

啓動DNS服務:

1 # servicenamed start
2 Generating/etc/rndc.key:                                 [  OK  ]
3 Starting named:                                            [ OK  ]

 

測試全部區域解析:

01 # dig -taxfr stu31.com @172.16.31.30
02   
03 ;<<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> -taxfr stu31.com @172.16.31.30
04 ;; globaloptions: +cmd
05 stu31.com.              600     IN     SOA     ns.stu31.com. root.stu31.com.2014122301 3600 180 432000 21600
06 stu31.com.              600     IN     NS      ns.stu31.com.
07 stu31.com.              600     IN     MX      5 mail.stu31.com.
08 mail.stu31.com.         600    IN      A       172.16.31.30
09 ns.stu31.com.           600    IN      A       172.16.31.30
10 www.stu31.com.          600     IN     A       172.16.31.30
11 www.stu31.com.          600     IN     A       172.16.31.31
12 stu31.com.              600     IN     SOA     ns.stu31.com.root.stu31.com. 2014122301 3600 180 432000 21600
13 ;; Querytime: 1 msec
14 ;;SERVER: 172.16.31.30#53(172.16.31.30)
15 ;; WHEN:Wed Dec 24 02:44:40 2014
16 ;; XFR size: 8 records (messages 1, bytes 210)

DNS服務器安裝完畢!這裏是最簡單的正向區域的實現,果有不清楚的話,我前面的博文有詳細介紹。

 

二.      apache服務器在web1web2上的實現

httpd的安裝同時在web1web2上安裝:

DNS服務器地址指向172.16.31.30

開發環境配置:

1 # yum –y groupinstall Development Tools
2 # yum install -ypcre-devel openssl-devel


編譯安裝apr

1 # tar xf apr-1.5.0.tar.bz2
2 # cd apr-1.5.0
3 # ./configure--prefix=/usr/local/apr
4 # make && make install

 

編譯安裝apr-util

1 # tar xf apr-util-1.5.3.tar.bz2
2 # cd apr-util-1.5.3
3 # ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr
4 # make && make install

 

編譯安裝httpd-2.4.10

1 # tar xf httpd-2.4.10.tar.bz2
2 # cd httpd-2.4.10
3 # ./configure --prefix=/usr/local/apache  --sysconfdir=/etc/httpd24 --enable-so--enable-ssl --enabletc/httpd24 --enable-so --enable-ssl --enable-rewrite--with-z --with-pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-modules=most--enable-mpms-shared=all --with-mpm=event
4 #make && make install

Apache服務腳本創建:

複製一個系統上原有的httpd的腳本更改如下:

#cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24

wKioL1Sb98-y2TcNAAGvfAGoWtA428.jpg

加入系統服務:

1 #chkconfig –add httpd24
2 #chkconfig  httpd24 on

啓動httpd服務:

1 # servicehttpd24 restart
2 Stoppinghttpd:                                           [  OK  ]
3 Startinghttpd:                                           [  OK  ]

 

    Web服務器基礎部分搭建完成,只需要後續虛擬主機配置與PHP結合。

 

三.      MariaDB數據庫服務器安裝

MariaDB服務器的DNS指向172.16.31.30

開發環境配置:

1 # yum groupinstall Development Tools
2 # yum -y install pcre-devel openssl-devel

XFS文件系統支持:

1 # yum install xfsprogs

服務器數據庫數據文件存儲考慮到安全性,我將創建一個LVM進行數據庫數據文件的存儲,並採用新型文件系統XFS來提高數據庫服務器的性能。

格式化磁盤:

1 #  echo -n -e"n\np\n3\n\n+10G\nt\n3\n8e\n\w\n" |fdisk /dev/sda
2 # partx -a /dev/sda

創建LVM

1 # pvcreate/dev/sda3
2 # vgcreate myvg/dev/sda3
3 # lvcreate -L 10G -n mylv myvg

創建xfs文件系統:

1 # mkfs -t xfs /dev/myvg/mylv
2 # blkid /dev/myvg/mylv

自動掛載,在/etc/fstab文件尾部添加:

1 # vim /etc/fstab
2 UUID="ba4e1e6c-3b7f-4f66-95b1-f51f8792288d"  /mydata xfs  defaults     0  0

創建數據庫管理用戶:

1 # useradd -M -s /sbin/nologin -d /mydata/data -r mysql

創建數據庫數據文件存儲目錄:

1 # mkdir /mydata/data

並給予mysql用戶數據庫數據文件存儲目錄管理權限:

1 # chown -R mysql:mysql /mydata/data/

解壓數據庫二進制源碼包:

1 # tar xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/
2 # cd /usr/local/

創建軟鏈接:

1 # ln -s mariadb-10.0.10-linux-x86_64/  mysql
2 # cd mysql/

初始化安裝MariaDB

1 # scripts/mysql_install_db --user=mysql--datadir=/mydata/data

mariadb配置文件創建及更改,有模版

安裝系統的時候,/etc/路徑下有一個my.cnf的,這裏換個路徑

01 # mkdir /etc/mysql
02 # cp support-files/my-huge.cnf /etc/mysql/my.cnf
03 # vim /etc/mysql/my.cnf
04 [mysqld]
05 datadir = /mydata/data
06 port            = 3306
07 socket          =/tmp/mysql.sock
08 skip-external-locking
09 key_buffer_size = 384M
10 max_allowed_packet = 1M
11 table_open_cache = 512
12 sort_buffer_size = 2M
13 read_buffer_size = 2M
14 read_rnd_buffer_size = 8M
15 myisam_sort_buffer_size = 64M
16 thread_cache_size = 8
17 query_cache_size = 32M
18 innodb_file_per_table = on
19 # Try number of CPU's*2 for thread_concurrency
20 thread_concurrency = 8

mariadb服務腳本創建

1 # cp support-files/mysql.server /etc/rc.d/init.d/mysqld
2 # chkconfig --add mysqld
3 # chkconfig mysqld on
4 # service mysqld start
5 Starting MySQL.                                           [  OK  ]
6 # ls /mydata/data/
7 aria_log.00000001 ib_logfile0        mysql             mysql.stu31.com.pid
8 aria_log_control  ib_logfile1       mysql-bin.000001 performance_schema

mysqld服務的一些設置

設置環境變量:

1 # vim /etc/profile.d/mysqld.sh
2 export PATH=/usr/local/mysql/bin:$PATH

加載環境變量:

1 # source /etc/profile.d/mysqld.sh

 

輸出mysql的頭文件至系統頭文件路徑/usr/include

1 # ln -sv /usr/local/mysql/include /usr/include/mysql

 

輸出mysql的庫文件給系統庫查找路徑,系統重新加載:

1 # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
2 # ldconfig

測試客戶端啓動:

01 # mysql
02 Welcome to the MariaDB monitor. Commands end with ; or \g.
03 Your MariaDB connection id is 4
04 Server version: 10.0.10-MariaDB-log MariaDB Server
05   
06 Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
07   
08 Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
09   
10 MariaDB [(none)]> select version();
11 +---------------------+
12 | version()           |
13 +---------------------+
14 | 10.0.10-MariaDB-log |
15 +---------------------+
16 1 row in set (0.00 sec)
17   
18 MariaDB [(none)]> \q
19 Bye

給數據庫設置一個密碼。

1 # mysqladmin -u root password
2 New password:
3 Confirm new password:

 

MariaDB安裝完畢,只是基本的數據庫環境,後面還需要數據庫與博客網站結合

 

四.PHP服務器上安裝基於FastCGI的實現

PHP服務器的DNS設置成172.16.31.30

開發環境配置:

1 # yumgroupinstall Development Tools
2 #yum install  –y pcre-devel openssl-devellibxml2-devel php-gd freetype-devel mbstring

 編譯安裝php-5.6.4

1 #tar xf php-5.6.4.tar.xz -C /usr/src/
2 # cd/usr/src/php-5.6.4/
3 #./configure --prefix=/usr/local/php --with-mysql=mysqlnd--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --with-gd --enable-xml --enable-sockets --enable-fpm--with-mcrypt --with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts

安裝:

1 #make&& make install

PHP服務器提供配置文件:

1 #cp php.ini-production /etc/php.ini

php提供Sys啓動控制腳本,加入開機啓動。

1 # cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
2 # chmod +x /etc/rc.d/init.d/php-fpm
3 # chkconfig --list php-fpm
4 service php-fpm supports chkconfig, but is not referenced in anyrunlevel (run 'chkconfig --add php-fpm')
5 # chkconfig --add php-fpm
6 # chkconfig php-fpm on

php-fpm提供配置文件,編輯php-fpm配置文件,修改監聽端口,默認是127.0.0.1

1 # cp /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
2 # vim /usr/local/php/etc/php-fpm.conf
3 pm.max_children = 50
4 pm.start_servers = 5
5 pm.min_spare_servers = 2
6 pm.max_spare_servers = 8
7 pid = /usr/local/php5/var/run/php-fpm.pid
8 listen = 172.16.31.22:9000

 

啓動php-fpm,檢查php監聽端口。

1 # service php-fpm start
2 Starting php-fpm  done
3 # ss -tunl |grep 9000
4 tcp    LISTEN     0     128         172.16.31.22:9000                  *:*

環境變量設置:

1 # vim /etc/profile.d/php.sh
2 export PATH=/usr/local/php/bin:$PATH
3 # source /etc/profile.d/php.sh
4 # php -v
5 PHP 5.4.26 (cli) (built: Dec 21 2014 01:53:51)
6 Copyright (c) 1997-2014 The PHP Group
7 Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

 

PHP部分配置完成,基本的php服務器環境,後面需要與web服務器結合。

 

 

五.      PHP服務器上啓用NFS服務

創建一個目錄或者提供一個特定的文件系統;亦可以參考上面的爲數據庫數據文件存儲創建的特定文件系統:

# mkdir /web

創建wordpress博客的網站存放目錄,我們將其共享出去讓web服務器使用:

#mkdir /web/blog

查看NFS軟件是否安裝:

1 # rpm -qanfs-utils
2 nfs-utils-1.2.3-54.el6.x86_64

NFS服務的配置文件爲/etc/exports,這個文件是NFS的主要配置文件,不過系統並沒有默認值,所以這個文件不一定會存在,可能要使用vim手動建立,然後在文件裏面寫入配置內容。

1 # cat /etc/exports
2 /web/blog 172.16.31.30(rw,async,no_root_squash)172.16.31.31(rw,async,no_root_squash)

配置共享目錄爲可讀寫,客戶端root用戶權限不壓縮

/etc/exports文件內容格式:

<輸出目錄> [客戶端選項(訪問權限,用戶映射,其他)] [客戶端選項(訪問權限,用戶映射,其他)]

開啓nfs服務:

01 [root@php ~]# service nfs restart
02 Shutting down NFS daemon:                                  [  OK  ]
03 Shutting down NFS mountd:                                  [  OK  ]
04 Shutting down NFS quotas:                                  [  OK  ]
05 Shutting down NFS services:                                [  OK  ]
06 Shutting down RPC idmapd:                                  [  OK  ]
07 Starting NFS services:                                     [  OK  ]
08 Starting NFS quotas:                                       [  OK  ]
09 Starting NFS mountd:                                       [  OK  ]
10 Starting NFS daemon:                                       [  OK  ]
11 Starting RPC idmapd:                                       [  OK  ]

 

查看本地NFS文件系統共享的目錄:

1 # showmount -e 172.16.31.32
2 Export list for 172.16.31.32:
3 /web/blog 172.16.31.31,172.16.31.30

 

NFS文件系統建立完成。

 

六.      web1web2上掛載NFS文件系統到本地目錄

NFS客戶端配置

這裏的客戶端就是前端的2Web服務器,先掛載共享目錄,然後測試其讀寫功能

在客戶機上執行mount命令,它向服務器上的端口映射器發出一個RPC調用來獲得服

務器上安裝守護程序的端口號。客戶和端口映射器交互既可以使用TCP也可以使用UDP,但一般使用UDP

NFS文件系統掛載到web服務器上

我們現在web服務器上查看NFS文件系統共享的目錄:

1 # showmount -e172.16.31.32
2 Export list for172.16.31.32:
3 /web/blog172.16.31.31,172.16.31.30

我們先在web服務器上創建本地目錄:/web/blog

1 [root@web1 ~]#mkdir /web/blog -pv

掛載NFS共享的文件目錄到本地:

可以使用臨時掛載:

1 [root@web1 ~]#mount -t nfs 172.16.31.32:/web/blog /web/blog

也可使用開機系統自動掛載:

1 [root@web1 ~]#vim /etc/fstab
2 172.16.31.32:/web/blog  /web/blog               nfs     defaults,_netdev 0 0

這裏的_netdev選項是爲了防止遠程NFS服務器關閉後本地系統不能啓動

掛載完成後查看掛載是否成功:

[root@web1 ~]#mount

/dev/mapper/vg0-rooton / type ext4 (rw)

proc on /proctype proc (rw)

sysfs on /systype sysfs (rw)

devpts on/dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on/dev/shm type tmpfs (rw)

/dev/sda1 on/boot type ext4 (rw)

/dev/mapper/vg0-usron /usr type ext4 (rw)

/dev/mapper/vg0-varon /var type ext4 (rw)

none on/proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

172.16.31.32:/web/blog on/web/blog type nfs (rw,vers=4,addr=172.16.31.32,clientaddr=172.16.31.30)

 

 

七.      安裝wordpress博客系統

1.配置web服務器的虛擬主機支持:

開啓FastCGI模塊和PHP支持及開啓虛擬主機。

#vim /etc/httpd24/httpd.conf

LoadModuleproxy_module modules/mod_proxy.so

LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so

<IfModuledir_module>

    DirectoryIndex index.php index.html

</IfModule>

AddTypeapplication/x-compress .Z

AddType application/x-gzip.gz .tgz

AddTypeapplication/x-httpd-php .php

AddTypeapplication/x-httpd-php-source .phps

Include/etc/httpd24/extra/httpd-vhosts.conf

配置虛擬主機配置文件:

01 #vim/etc/httpd24/extra/httpd-vhosts.conf
02 <VirtualHost 172.16.31.30:80>
03 DocumentRoot"/web/blog"
04 ServerName www.stu31.com
05 ProxyRequests Off
06 ProxyPassMatch^/(.*\.php)$ fcgi://172.16.31.32:9000/www/blog/$1
07 ErrorLog"/web/blog/logs/error_log"
08 CustomLog"/web/blog/logs/access_log" common
09 <Directory"/web/blog/logs">
10     Options none
11     AllowOverride none
12     Require all granted
13 </Directory>
14 </VirtualHost>

注意:

A.需要在nfs共享文件目錄中創建日誌文件目錄logs

#mkdir/web/blog/logs/

B.web服務器的靜態資源請求是到nfs共享文件目錄/web/blog中返回結果,而涉及到動態資源的請求是反向代理到php服務器上的網站目錄/www/blog中執行後返回結果。

C.前端2web服務器都需要配置好虛擬主機。

 

2.在NFS共享服務器上安裝wordpress博客系統

php服務器上創建動態資源存放目錄:

#mkdir  /www/blog

解壓wordpress博客程序:

# unzip wordpress-3.2.1-zh_CN.zip

移動程序到NFS文件共享目錄:

# mv wordpress/* /web/blog/


3.配置wordpress博客系統與數據庫結合

創建wordpress的配置文件:

1 #cd /web/blog
2 # cp wp-config-sample.php wp-config.php

寫入數據庫名稱,用戶名,密碼及數據庫服務器IP地址:

01 #vim wp-config.php
02 // **MySQL 設置 - 具體信息來自您正在使用的主機 ** //
03 /**WordPress 數據庫的名稱 */
04 define('DB_NAME','wpdb');
05   
06 /** MySQL數據庫用戶名 */
07 define('DB_USER','wpadmin');
08   
09 /** MySQL數據庫密碼 */
10 define('DB_PASSWORD','oracle');
11   
12 /** MySQL主機 */
13 define('DB_HOST','172.16.31.33');
14   
15 /** 創建數據表時默認的文字編碼*/
16 define('DB_CHARSET','utf8');
17   
18 /** 數據庫整理類型。如不確定請勿更改 */
19 define('DB_COLLATE', '');

切換到數據庫服務器,在數據庫添加庫,授權,添加授權密碼

01 [root@mysqlmysql]# mysql -u root -p
02 Enter password:
03 Welcome to the MariaDB monitor.  Commands end with ; or \g.
04 Your MariaDB connection id is 8
05 Server version: 10.0.10-MariaDB-log MariaDB Server
06   
07 Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
08   
09 Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.
10   
11 MariaDB [(none)]> create schema wpdb;
12 Query OK, 1 row affected (0.04 sec)
13   
14 MariaDB [(none)]> grant all on wpdb.* to 'wpadmin'@'172.16.%.%'identified by 'oracle';
15 Query OK, 0 rows affected (0.05 sec)
16   
17 MariaDB [(none)]> flush privileges;
18 Query OK, 0 rows affected (0.00 sec)
19   
20 MariaDB [(none)]> \q
21 Bye


4.重新啓動httpd服務

1 # servicehttpd24 restart 
2 Stoppinghttpd:                                           [  OK  ]
3 Startinghttpd:                                           [  OK  ]

 

八.      實現測試

我們通過瀏覽器訪問博客網站,我這裏是一個在虛擬機上訪問,一個在實體機上訪問:

wKioL1Sb_LLRmIa1AAViCWnBzoc499.jpg

上圖的訪問是在web1完成的

下圖的訪問是在web2完成的

wKiom1Sb_CfCD2gRAAOWugGw_bs350.jpg

結果非常完美哦!o(∩_∩)o

 

.我們在此基礎上安裝Drupal網站

實現創建drupal網站:

DNS服務器需要添加域名解析:

01 [root@web1 ~]# vim/var/named/stu31.com.zone
02 $TTL 600
03 $ORIGIN stu31.com.
04 @      IN      SOA     ns.stu31.com.   root.stu31.com. (
05                         2014122302
06                         1H
07                         3M
08                         5D
09                         6H )
10 @      IN      NS      ns
11        IN      MX  5  mail
12 ns     IN      A       172.16.31.30
13 www    IN      A       172.16.31.30
14 www    IN      A       172.16.31.31
15 web    IN      A       172.16.31.30
16 web    IN      A       172.16.31.31
17 mail   IN      A       172.16.31.30

 

重啓named服務:

1 [root@web1 ~]# service named restart
2 Stopping named:                                            [  OK  ]
3 Starting named:                                           [  OK  ]

 

測試解析:

01 [root@web2 ~]# dig -t A [email protected]
02   
03 ; <<>> DiG9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> -t A [email protected]
04 ;; global options: +cmd
05 ;; Got answer:
06 ;; ->>HEADER<<- opcode: QUERY,status: NOERROR, id: 60232
07 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2,AUTHORITY: 1, ADDITIONAL: 1
08   
09 ;; QUESTION SECTION:
10 ;web.stu31.com.                 IN      A
11   
12 ;; ANSWER SECTION:
13 web.stu31.com.          600     IN     A       172.16.31.30
14 web.stu31.com.          600     IN     A       172.16.31.31
15   
16 ;; AUTHORITY SECTION:
17 stu31.com.              600     IN     NS      ns.stu31.com.
18   
19 ;; ADDITIONAL SECTION:
20 ns.stu31.com.           600     IN     A       172.16.31.30
21   
22 ;; Query time: 4 msec
23 ;; SERVER: 172.16.31.30#53(172.16.31.30)
24 ;; WHEN: Wed Dec 24 08:16:36 2014
25 ;; MSG SIZE rcvd: 96

 

 

php服務器上創建NFS文件目錄共享,以存放drupal網站的靜態資源:

1 [root@php ~]# mkdir /web/drupal
2 [root@php ~]# showmount -e 172.16.31.32
3 Export list for 172.16.31.32:
4 /web/blog 172.16.31.31,172.16.31.30
5 [root@php ~]# vim /etc/exports
6 /web/blog 172.16.31.30(rw,async,no_root_squash)172.16.31.31(rw,async,no_root_squash)
7 /web/drupal 172.16.31.30(rw,async,no_root_squash) 172.16.31.31(rw,async,no_root_squash)

 

重啓NFS共享文件系統:

01 [root@php drupal]# service nfs restart
02 Shutting down NFS daemon:                                  [  OK  ]
03 Shutting down NFS mountd:                                  [  OK  ]
04 Shutting down NFS quotas:                                  [  OK  ]
05 Shutting down NFS services:                                [  OK  ]
06 Shutting down RPC idmapd:                                  [  OK  ]
07 Starting NFS services:                                     [  OK  ]
08 Starting NFS quotas:                                       [  OK  ]
09 Starting NFS mountd:                                       [  OK  ]
10 Starting NFS daemon:                                       [  OK  ]
11 Starting RPC idmapd:                                       [  OK  ]

 

NFS共享服務器端查看共享的文件目錄:

1 [root@php drupal]# showmount -e172.16.31.32
2 Export list for 172.16.31.32:
3 /web/drupal 172.16.31.31,172.16.31.30
4 /web/blog  172.16.31.31,172.16.31.30

 

準備好drupal程序包:包含中文語言包

1 [root@php ~]# ll
2 -rw-r--r-- 1 root root  3229858 Dec 22 08:21drupal-7.34.tar.gz
3 -rw-r--r-- 1 root root   582727 Dec 21 21:48drupal-7.34.zh-hans.po


解壓程序包:

1 [root@php ~]# tar xf drupal-7.34.tar.gz
2 [root@php ~]# mv drupal-7.34/* /web/drupal/
3 [root@php ~]# cd /web/drupal/
4 [root@php drupal]# cp sites/default/default.settings.phpsites/default/settings.php
5 [root@php drupal]# chmod a+w sites/default/

 

將中文語言包放置到指定目錄:

1 [root@php drupal]# cp/root/drupal-7.34.zh-hans.po profiles/standard/translations/

 

創建drupal動態資源存放目錄,並且將drupal網站目錄複製一份到動態資源存放目錄:

1 [root@php drupal]# mkdir /www/drupal
2 [root@php drupal]# cp -a * /www/drupal/

 

下面配置NFS客戶端,將NFS服務器共享的drupal網站目錄映射到web服務器:


切換到web服務器:

我們需要創建網站目錄:

[root@web1 ~]# mkdir /web/drupal

實現自動掛載:

[root@web1 ~]# vim /etc/fstab

172.16.31.32:/web/drupal  /web/drupal           nfs     defaults,_netdev 0 0

[root@web1 ~]# mount -a

[root@web1 ~]# mount

/dev/mapper/vg0-root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts(rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

/dev/mapper/vg0-usr on /usr type ext4 (rw)

/dev/mapper/vg0-var on /var type ext4 (rw)

none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)

172.16.31.32:/web/blog on /web/blog typenfs (rw,vers=4,addr=172.16.31.32,clientaddr=172.16.31.30)

172.16.31.32:/web/drupal on /web/drupaltype nfs (rw,vers=4,addr=172.16.31.32,clientaddr=172.16.31.30)

 

web2服務器做同樣的操作即可。

[root@web2 ~]# ls /web/drupal/

authorize.php  index.php           INSTALL.txt      profiles    themes

CHANGELOG.txt  INSTALL.mysql.txt   LICENSE.txt      README.txt  update.php

COPYRIGHT.txt  INSTALL.pgsql.txt   MAINTAINERS.txt  robots.txt UPGRADE.txt

cron.php       install.php         misc             scripts     web.config

includes       INSTALL.sqlite.txt  modules          sites       xmlrpc.php

PHP服務器上NFS共享文件內的網站的內容就掛載到本地了!!!

 

web1服務器的虛擬主機配置:

01 [root@web1 ~]# vim/etc/httpd24/extra/httpd-vhosts.conf
02 <VirtualHost 172.16.31.30:80>
03    DocumentRoot "/web/drupal"
04    ServerName web.stu31.com
05    ProxyRequests Off
06    ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.31.32:9000/www/drupal/$1
07    ErrorLog "/web/drupal/logs/drupal-error_log"
08    CustomLog "/web/drupal/logs/drupal-access_log" common
09    <Directory "/web/drupal">
10        Options none
11        AllowOverride none
12        Require all granted
13    </Directory>
14 </VirtualHost>

 

測試配置文件語法:

1 [root@web1 ~]# httpd -t
2 (2)No such file or directory: AH02291:Cannot access directory '/web/drupal/logs/' for error log of vhost defined at/etc/httpd24/extra/httpd-vhosts.conf:38
3 (2)No such file or directory: AH02291:Cannot access directory '/web/blog/logs/' for error log of vhost defined at/etc/httpd24/extra/httpd-vhosts.conf:24
4 AH00014: Configuration check failed

提示的錯誤是日誌文件目錄未創建!創建日誌目錄:

1 [root@web1 ~]# mkdir /web/drupal/logs
2 [root@web1 ~]# httpd -t             
3 Syntax OK

 

web2的虛擬主機配置:注意只需要改變一下虛擬主機的地址即可了!

01 [root@web2 ~]# mkdir /web/drupal
02 <VirtualHost 172.16.31.31:80>
03    DocumentRoot "/web/drupal"
04    ServerName web.stu31.com
05    ProxyRequests Off
06    ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.31.32:9000/www/drupal/$1
07    ErrorLog "/web/drupal/logs/drupal-error_log"
08    CustomLog "/web/drupal/logs/drupal-access_log" common
09    <Directory "/web/drupal">
10        Options none
11        AllowOverride none
12        Require all granted
13    </Directory>
14 </VirtualHost>

 

虛擬主機配置完成!

 

切換到數據庫服務器爲drupal網站創建數據庫及數據庫管理用戶及密碼:

01 [root@mysql ~]# mysql -uroot -p
02 Enter password:
03 Welcome to the MariaDB monitor.  Commands end with ; or \g.
04 Your MariaDB connection id is 32
05 Server version: 10.0.10-MariaDB-log MariaDBServer
06   
07 Copyright (c) 2000, 2014, Oracle, SkySQL Aband others.
08   
09 Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
10   
11 MariaDB [(none)]> create databasedrupal;
12 Query OK, 1 row affected (0.00 sec)
13   
14 MariaDB [(none)]> show databases;
15 +--------------------+
16 | Database           |
17 +--------------------+
18 | drupal             |
19 | information_schema |
20 | mysql              |
21 | performance_schema |
22 | test               |
23 | wpdb               |
24 +--------------------+
25 6 rows in set (0.02 sec)
26   
27 MariaDB [(none)]> grant all on drupal.*to 'drupal'@'172.16.%.%' identified by 'oracle';
28 Query OK, 0 rows affected (0.03 sec)
29   
30 MariaDB [(none)]> flush privileges;
31 Query OK, 0 rows affected (0.01 sec)
32   
33 MariaDB [(none)]> \q
34 Bye

  

重啓httpd服務:

1 [root@web1 ~]# service httpd24 restart
2 Stopping httpd:                                           [  OK  ]
3 Starting httpd:                                           [  OK  ]
4   
5 [root@web2 ~]# service httpd24 restart
6 Stopping httpd:                                           [  OK  ]
7 Starting httpd:                                           [  OK  ]

 

 

開始去客戶端安裝drupal

輸入web.stu31.com訪問drupal網站:

選擇標準安裝:

wKiom1Sb_yXjk__VAAEdeWooyPA135.jpg

選擇簡體中文:

wKioL1Sb_-CA5f31AAEE7kH3gi4639.jpg

檢查安裝條件是否通過:

wKioL1Sb__bQfhxCAAK2Xe-lF3Y690.jpg

出現不可寫,需要對sites目錄賦予寫權限:

需要同時更改NFS共享目錄和php服務器本地的/www/drupal目錄:

1 [root@php ~]# chmod -R a+w/web/drupal/sites/
2 [root@php ~]# chmod -R a+w /www/drupal/sites/

 

再次刷新安裝成功進入下一步:

設置數據庫,填入我們在上面設置的數據庫名稱和用戶名及密碼

wKiom1Sb_5yRIvT8AAJWuqXRg3Q484.jpg

安裝模塊:

wKiom1Sb_3aCeZGJAAFVA4a_05o688.jpg

設置網站:

wKiom1Sb_7-CfTYSAAHt-fy5Rro165.jpg

完成安裝:

wKiom1Sb_9vxQMenAACa5m1AHe8901.jpg

進入網站首頁:

wKioL1ScAJyBXLTAAAIeFFzIfUo998.jpg

安裝完成後將sites/default/settings.php的權限更改爲只讀權限,考慮到安全:

1 [root@php ~]# chmod 444/web/drupal/sites/default/settings.php
2 [root@php ~]# chmod 444/www/drupal/sites/default/settings.php

 

到這裏drupal網站安裝就完成了!!!

原文:http://sohudrgon.blog.51cto.com/3088108/1596068

發佈了42 篇原創文章 · 獲贊 2 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章