1.前端需支持更大的访问量,单台Web服务器已无法满足需求了,则需扩容Web服务器;
2.虽然动态内容可交由后端的PHP服务器执行,但静态页面还需要Web服务器自己解析,那是否意味着多台Web服务器都需要在各自的系统中都存有一份静态页面数据呢?
其实这样也不是不可以,毕竟文件本地访问,速度还是有优势的,但这却涉及到多台Web服务器间内容的一致性问题,这种问题也不可避免;
那么如果能将静态页面集中存放,所有Web服务器都来集中地取文件,对于文件的一致性就有了保障,这个集中地就叫做“文件共享服务器”;
文件共享有多种方式,FTP,NFS,Samba等,而其中NFS作为网络文件系统,允许一个系统通过网络共享目录和文件,通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件,这种近似访问本地文件系统的架构貌似很符合我们的需求,我们现在就来实现这个需求!
需求实现:
1.web1充当http服务器和DNS解析服务器,客户端到web1和web2的请求,如果是静态资源请求通过php主机的NFS服务挂载的存储返回结果
2.web1和web2对于客户端动态资源请求都反向代理到后端php服务器进行执行后返回结果
3.web1和web2实现DNS轮询,客户端访问博客网站是负载均衡的。
4.建立wordpress博客
5.数据库存储wordpress博客的各种数据
实验架构:
部署实现
一.DNS服务器在web1上的实现
开发环境配置
1 | # yum –y groupinstall Development Tools |
配置DNS服务器:
安装DNS服务器软件bind
配置DNS主配置文件:
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). |
08 | // See/usr/share/doc/bind*/sample/ for example named configuration files. |
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; }; |
22 | // dnssec-validation yes; |
23 | // dnssec-lookaside auto; |
25 | /* Path to ISC DLV key */ |
26 | /*bindkeys-file"/etc/named.iscdlv.key"; |
28 | managed-keys-directory"/var/named/dynamic"; |
33 | channel default_debug { |
44 | include"/etc/named.rfc1912.zones"; |
45 | include "/etc/named.root.key"; |
配置主区域文件:只是在文件尾部添加正向区域
1 | # vim /etc/named.rfc1912.zones |
配置正向区域解析库文件:
这里让客户端查询http服务器时能轮换查询到两台web服务器。
01 | # vim/var/named/stu31.com.zone |
04 | @ IN SOA ns.stu31.com. root.stu31.com. ( |
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 |
启动DNS服务:
2 | Generating/etc/rndc.key: [ OK ] |
测试全部区域解析:
01 | # dig -taxfr stu31.com @172.16.31.30 |
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 |
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服务器在web1和web2上的实现
httpd的安装同时在web1和web2上安装:
将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 |
3 | # ./configure--prefix=/usr/local/apr |
编译安装apr-util
1 | # tar xf apr-util-1.5.3.tar.bz2 |
3 | # ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr |
编译安装httpd-2.4.10
1 | # tar xf httpd-2.4.10.tar.bz2 |
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 |
Apache服务脚本创建:
复制一个系统上原有的httpd的脚本更改如下:
#cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
加入系统服务:
1 | #chkconfig –add httpd24 |
启动httpd服务:
1 | # servicehttpd24 restart |
Web服务器基础部分搭建完成,只需要后续虚拟主机配置与PHP结合。
三. MariaDB数据库服务器安装
MariaDB服务器的DNS指向172.16.31.30
开发环境配置:
1 | # yum groupinstall Development Tools |
2 | # yum -y install pcre-devel openssl-devel |
XFS文件系统支持:
服务器数据库数据文件存储考虑到安全性,我将创建一个LVM进行数据库数据文件的存储,并采用新型文件系统XFS来提高数据库服务器的性能。
格式化磁盘:
1 | # echo -n -e"n\np\n3\n\n+10G\nt\n3\n8e\n\w\n" |fdisk /dev/sda |
创建LVM:
2 | # vgcreate myvg/dev/sda3 |
3 | # lvcreate -L 10G -n mylv myvg |
创建xfs文件系统:
1 | # mkfs -t xfs /dev/myvg/mylv |
自动挂载,在/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 |
创建数据库数据文件存储目录:
并给予mysql用户数据库数据文件存储目录管理权限:
1 | # chown -R mysql:mysql /mydata/data/ |
解压数据库二进制源码包:
1 | # tar xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/ |
创建软链接:
1 | # ln -s mariadb-10.0.10-linux-x86_64/ mysql |
初始化安装MariaDB:
1 | # scripts/mysql_install_db --user=mysql--datadir=/mydata/data |
mariadb配置文件创建及更改,有模版
安装系统的时候,/etc/路径下有一个my.cnf的,这里换个路径
05 | datadir = /mydata/data |
07 | socket = /tmp/mysql .sock |
09 | key_buffer_size = 384M |
10 | max_allowed_packet = 1M |
11 | table_open_cache = 512 |
14 | read_rnd_buffer_size = 8M |
15 | myisam_sort_buffer_size = 64M |
17 | query_cache_size = 32M |
18 | innodb_file_per_table = on |
20 | thread_concurrency = 8 |
mariadb服务脚本创建
1 | # cp support-files/mysql.server /etc/rc.d/init.d/mysqld |
2 | # chkconfig --add mysqld |
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 |
测试客户端启动:
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 |
06 | Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. |
08 | Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. |
10 | MariaDB [(none)]> select version(); |
11 | +---------------------+ |
13 | +---------------------+ |
14 | | 10.0.10-MariaDB-log | |
15 | +---------------------+ |
16 | 1 row in set (0.00 sec) |
给数据库设置一个密码。
1 | # mysqladmin -u root 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 |
安装:
为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 |
为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 |
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 |
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 |
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软件是否安装:
2 | nfs-utils-1.2.3-54.el6.x86_64 |
NFS服务的配置文件为/etc/exports,这个文件是NFS的主要配置文件,不过系统并没有默认值,所以这个文件不一定会存在,可能要使用vim手动建立,然后在文件里面写入配置内容。
2 | /web/blog 172.16.31.30(rw,async,no_root_squash)172.16.31.31(rw,async,no_root_squash) |
# 配置共享目录为可读写,客户端root用户权限不压缩
/etc/exports文件内容格式:
<输出目录> [客户端1 选项(访问权限,用户映射,其他)] [客户端2 选项(访问权限,用户映射,其他)]
开启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文件系统建立完成。
六. 在web1和web2上挂载NFS文件系统到本地目录
NFS客户端配置
这里的客户端就是前端的2台Web服务器,先挂载共享目录,然后测试其读写功能
在客户机上执行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 |
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"> |
注意:
A.需要在nfs共享文件目录中创建日志文件目录logs
#mkdir/web/blog/logs/
B.web服务器的静态资源请求是到nfs共享文件目录/web/blog中返回结果,而涉及到动态资源的请求是反向代理到php服务器上的网站目录/www/blog中执行后返回结果。
C.前端2台web服务器都需要配置好虚拟主机。
2.在NFS共享服务器上安装wordpress博客系统
在php服务器上创建动态资源存放目录:
#mkdir /www/blog
解压wordpress博客程序:
# unzip wordpress-3.2.1-zh_CN.zip
移动程序到NFS文件共享目录:
# mv wordpress/* /web/blog/
3.配置wordpress博客系统与数据库结合
创建wordpress的配置文件:
2 | # cp wp-config-sample.php wp-config.php |
写入数据库名称,用户名,密码及数据库服务器IP地址:
02 | // **MySQL 设置 - 具体信息来自您正在使用的主机 ** // |
03 | /**WordPress 数据库的名称 */ |
04 | define('DB_NAME','wpdb'); |
07 | define('DB_USER','wpadmin'); |
10 | define('DB_PASSWORD','oracle'); |
13 | define('DB_HOST','172.16.31.33'); |
16 | define('DB_CHARSET','utf8'); |
18 | /** 数据库整理类型。如不确定请勿更改 */ |
19 | define('DB_COLLATE', ''); |
切换到数据库服务器,在数据库添加库,授权,添加授权密码
01 | [root@mysqlmysql]# mysql -u root -p |
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 |
07 | Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. |
09 | Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement. |
11 | MariaDB [(none)]> create schema wpdb; |
12 | Query OK, 1 row affected (0.04 sec) |
14 | MariaDB [(none)]> grant all on wpdb.* to 'wpadmin'@'172.16.%.%'identified by 'oracle'; |
15 | Query OK, 0 rows affected (0.05 sec) |
17 | MariaDB [(none)]> flush privileges; |
18 | Query OK, 0 rows affected (0.00 sec) |
4.重新启动httpd服务
1 | # servicehttpd24 restart |
八. 实现测试
我们通过浏览器访问博客网站,我这里是一个在虚拟机上访问,一个在实体机上访问:
上图的访问是在web1完成的
下图的访问是在web2完成的
结果非常完美哦!o(∩_∩)o
九.我们在此基础上安装Drupal网站
实现创建drupal网站:
DNS服务器需要添加域名解析:
01 | [root@web1 ~]# vim/var/named/stu31.com.zone |
04 | @ IN SOA ns.stu31.com. root.stu31.com. ( |
17 | mail IN A 172.16.31.30 |
重启named服务:
1 | [root@web1 ~]# service named restart |
测试解析:
01 | [root@web2 ~]# dig -t A web.stu31.com@172.16.31.30 |
03 | ; <<>> DiG9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> -t A web.stu31.com@172.16.31.30 |
04 | ;; global options: +cmd |
06 | ;; ->>HEADER<<- opcode: QUERY,status: NOERROR, id: 60232 |
07 | ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2,AUTHORITY: 1, ADDITIONAL: 1 |
13 | web.stu31.com. 600 IN A 172.16.31.30 |
14 | web.stu31.com. 600 IN A 172.16.31.31 |
17 | stu31.com. 600 IN NS ns.stu31.com. |
19 | ;; ADDITIONAL SECTION: |
20 | ns.stu31.com. 600 IN A 172.16.31.30 |
23 | ;; SERVER: 172.16.31.30#53(172.16.31.30) |
24 | ;; WHEN: Wed Dec 24 08:16:36 2014 |
在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程序包:包含中文语言包
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 |
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"> |
测试配置文件语法:
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 |
web2的虚拟主机配置:注意只需要改变一下虚拟主机的地址即可了!
01 | [root@web2 ~]# mkdir /web/drupal |
02 | < VirtualHost 172.16.31.31:80> |
03 | DocumentRoot "/web/drupal" |
04 | ServerName web.stu31.com |
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"> |
虚拟主机配置完成!
切换到数据库服务器为drupal网站创建数据库及数据库管理用户及密码:
01 | [root@mysql ~]# mysql -uroot -p |
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 |
07 | Copyright (c) 2000, 2014, Oracle, SkySQL Aband others. |
09 | Type 'help;' or '\h' for help. Type '\c' toclear the current input statement. |
11 | MariaDB [(none)]> create databasedrupal; |
12 | Query OK, 1 row affected (0.00 sec) |
14 | MariaDB [(none)]> show databases; |
15 | +--------------------+ |
17 | +--------------------+ |
19 | | information_schema | |
21 | | performance_schema | |
24 | +--------------------+ |
25 | 6 rows in set (0.02 sec) |
27 | MariaDB [(none)]> grant all on drupal.*to 'drupal'@'172.16.%.%' identified by 'oracle'; |
28 | Query OK, 0 rows affected (0.03 sec) |
30 | MariaDB [(none)]> flush privileges; |
31 | Query OK, 0 rows affected (0.01 sec) |
重启httpd服务:
1 | [root@web1 ~]# service httpd24 restart |
5 | [root@web2 ~]# service httpd24 restart |
开始去客户端安装drupal:
输入web.stu31.com访问drupal网站:
选择标准安装:
选择简体中文:
检查安装条件是否通过:
出现不可写,需要对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/ |
再次刷新安装成功进入下一步:
设置数据库,填入我们在上面设置的数据库名称和用户名及密码
安装模块:
设置网站:
完成安装:
进入网站首页:
安装完成后将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