本文共 6941 字,大约阅读时间需要 23 分钟。
规划如图:
分析如下:
实验环境准备:
操作步骤:
Step1 DNS
a) 安装bind(dns)服务器
1 | yum -y install bind |
b) 配置cache only的dns服务器
i) 在 vim /etc/named/named.conf 中输入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | options { directory "/var/named" ; dump- file "/var/named/data/cache_dump.db" ; statistics- file "/var/named/data/named_stats.txt" ;\ allow-query { any; }; # 允许任意客户端查询 recursion yes ; rrset order { random; }; # dns轮询解析 } logging { channel default_debug { file "data/named.run" ; severity dynamic; }; }; zone "." IN { type hint; file "named.ca" ; }; include "/etc/named.rfc1912.zones" ; |
ii) 在 vim /etc/named.rfc1912.zones 中输入以下内容
1 2 3 4 5 6 7 8 | zone "king.com" IN { type master; file "king.com.zone" ; #正向解析配置文件 }; zone "43.16.172.in-addr.arpa" IN { type master; file "172.16.43.zone" ; #反向解析配置文件 }; |
iii) 在 vim /var/named/king.com.zone 中输入以下内容
1 2 3 4 5 6 7 8 9 10 11 | $TTL 600 @ IN SOA dns.king.com. admin.king.com. ( 2014032401 1H 5M 3D 12H ) IN NS dns dns IN A 172.16.43.1 www IN A 172.16.43.2 www IN A 172.16.43.3 |
iv) 在 vim /var/named/172.16.43.zone 中输入以下内容
1 2 3 4 5 6 7 8 9 10 11 | $TTL 600 @ IN SOA dns.king.com. admin.king.com. ( 2014032401 1H 5M 3D 12H ) IN NS dns.king.com. 1 IN PTR dns.king.com. 2 IN PTR www.king.com. 3 IN PTR www.king.com. |
v) 更改iii,iv步的权限及属主属组
1 2 3 | chown root:named /var/named/ *.zone chmod 640 /var/named/ *.zone service named start |
vi) 测试:
1 2 | # vim /etc/resolv.conf 更改 DNS1=172.16.43.1 dig -t A www.king.com |
客户端查询,更改物理机DNS
测试如下:
反解查询:
1 | dig -t PTR -x 172.16.43.2 |
step2 apache
a) 为安装准备环境
1 2 3 4 | rpm -e httpd --nodeps rm -rf /etc/httpd rm -rf /usr/lib64/httpd yum -y install pcre-devel |
b) 其余手动安装配置
i) 配置安装apr-1.5.0
1 2 3 4 | tar xf apr-1.5.0. tar .bz2 cd apr-1.5.0 . /configure --prefix= /usr/local/apr make && make install |
ii) 配置安装apr-util-1.5.3
1 2 3 4 | tar xf apr-util-1.5.3. tar .bz2 cd apr-util-1.5.3 . /configure --prefix= /usr/local/apr-util --with-apr= /usr/local/apr make && make install |
iii) 配置安装httpd-2.4.9
1 2 3 4 5 6 7 | tar xf httpd-2.4.9. tar .bz2 cd httpd-2.4.9 . /configure --prefix= /usr/local/apache --sysconfdir= /etc/httpd -- enable -so -- enable -ssl -- enable -cgi -- enable -rewrite --with-zlib --with-pcre --with- apr= /usr/local/apr --with-apr-util= /usr/local/apr-util -- enable -modules=most -- enable -mpms-shared=all --with-mpm=event make && make install |
c) 配置开机服务及环境变量
在 vim /etc/rc.d/init.d/httpd 编辑此项
请参考 http://apprentice.blog.51cto.com/2214645/1380490
在 vim /etc/httpd/httpd.conf 添加此项
1 | PidFile "/var/run/httpd.pid" |
# 导出环境变量
1 | echo "PATH=/usr/local/apache/bin:$PATH" > /etc/profile .d /httpd .sh |
# 重载环境变量
1 | . /etc/profile .d /httpd .sh |
# 启动/添加开机服务
1 2 3 | chkconfig --add httpd chkconfig httpd on service httpd start |
d) 测试前3台机器是否工作正常
step3 nfs,php-fpm
a) 安装nfs工具
# 如果机器内核没有编译nfs则需要安装
1 | yum -y install nfs-utils |
1 | mkdir /nfsshared |
在 vim /etc/exports 编辑此项
# 为172.16.43.0/24此段开放加载nfs网络文件功能
1 | /nfsshared 172.16.43.0 /24 (rw,async,no_root_squash) |
# 添加客户端准备操作的账户,防止nobody属组文件出现
1 | useradd -r -s /sbin/nologin daemon |
# 导出所有挂载分区
1 2 | exportfs -a service nfs restart |
b) 客户端测试挂载
1 | showmount -e 172.16.43.4 |
1 | mkdir /share |
# 挂载网络文件系统
1 | mount -t nfs 172.16.43.4: /nfsshared /share |
# 开机挂载可编辑 /etc/fstab
1 | 172.16.43.4: /nfsshared /share ext4 |
# 测试nfs, 在/nfsshared中touch文件,观察2个客户端(web1,web2)
c) 安装php-fpm
i) 解决php安装依赖
1 2 3 | yum -y groupinstall "Desktop Platform Development" yum -y install libmcrypt-devel yum -y install bzip2 -devel |
ii) 安装php with fpm
1 2 3 4 5 6 7 8 | tar xf php-5.4.19. tar .bz2 cd php-5.4.19 . /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 -- enable -xml -- enable -sockets -- enable -fpm --with-mcrypt --with-config- file - path= /etc --with-config- file -scan- dir = /etc/php .d --with-bz2 make && make install |
iii) 为php提供配置文件:
1 | cp php.ini-production /etc/php .ini |
iv) 配置php-fpm
为php-fpm提供SysV init脚本,并将其添加至服务列表:
1 2 3 4 | cp sapi /fpm/init .d.php-fpm /etc/rc .d /init .d /php-fpm chmod +x /etc/rc .d /init .d /php-fpm chkconfig --add php-fpm chkconfig php-fpm on |
为php-fpm提供配置文件:
1 | cp /usr/local/php/etc/php-fpm .conf.default /usr/local/php/etc/php-fpm .conf |
编辑php-fpm的配置文件:vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
1 2 | pid = /usr/local/php/var/run/php-fpm .pid listen = 172.16.43.4:9000 |
vi) 编辑apache为运行php后端程序做准备
# 分别编辑 172.16.43.2/3中的 vim /etc/httpd/httpd.conf
1 2 | DocumentRoot "/share" <Directory "/share" > |
# 开启fcgi转发
1 2 | LoadModule proxy_module modules /mod_proxy .so LoadModule proxy_fcgi_module modules /mod_proxy_fcgi .so |
# 禁止apache正向代理,转而实现反向代理后端的php-fpm
1 2 | ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi: //172 .16.43.4:9000 /nfsshared |
# 添加apache识别php文件
1 2 | AddType application /x-httpd-php .php AddType application /x-httpd-php-source .phps |
# 定位至DirectoryIndex
1 | DirectoryIndex index.php index.html |
d) 安装配置Discuz在 /nfsshared
1 | cd /nfsshared |
# 下载Discuz最新版本到此目录
1 2 3 4 | unzip Discuz_X3.1_SC_UTF8.zip rm -rf Discuz_X3.1_SC_UTF8.zip readme/ utility/ mv . /upload/ * ./ rm -rf upload/ |
e) 测试 php页面解析
安装discuz需要将 config , data , uc_client , uc_server 的权限设置为777
step4 mysql
i) 创建mysql的数据目录
1 2 3 4 | mkdir /data groupadd -r mysql useradd -g mysql -r -s /sbin/nologin -M -d /data mysql chown -R mysql:mysql /data |
ii) 安装二进制mysql
1 2 3 4 5 6 7 | tar xf mysql-5.5.33-linux2.6-x86_64. tar .gz -C /usr/local cd /usr/local ln -sv mysql-5.5.33-linux2.6-x86_64 mysql cd mysql chown -R mysql:mysql . mysql /scripts/mysql_install_db --user=mysql --datadir= /data chown -R root . |
# 提供mysql的配置文件
1 | cp support-files /my-large .cnf /etc/my .cnf |
# 需要添加如下行指定mysql数据文件的存放位置:
1 | datadir = /mydata/data |
iii) 为mysql提供sysv服务脚本:
1 2 3 | cd /usr/local/mysql cp support-files /mysql .server /etc/rc .d /init .d /mysqld chmod +x /etc/rc .d /init .d /mysqld |
添加至服务列表:
1 2 3 4 | chkconfig --add mysqld chkconfig mysqld on echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile .d /mysql .sh . /etc/profile .d /mysql .sh |
iv) 启动服务并授权php服务器账号访问
1 2 3 4 | service mysqld restart mysql grant all on *.* to 'root' @ '172.16.43.4' identified by '123456' ; flush privileges; |
v) 继续Step3 e)的安装过程,安装完成后
vi) 继续测试由172.16.43.2上传静态文件测试172.16.43.3是否能共享此静态文件
vii) 查看文件情况
Step5 xache
i) 安装xcache
1 2 3 4 5 | tar xf xcache-3.0.3. tar .bz2 cd xcache-3.0.3 /usr/local/php/bin/phpize . /configure -- enable -xcache --with-php-config= /usr/local/php/bin/php-config make && make install |
# 安装结束时,会出现类似如下行, 将后半句复制
1 | Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/ |
ii) 编辑php.ini,整合php和xcache:
# 首先将xcache提供的样例配置导入php.ini
1 | mkdir /etc/php .d |
# xcache.ini文件在xcache的源码目录中。
1 | cp xcache.ini /etc/php .d |
# 接下来编辑/etc/php.d/xcache.ini 修改为如下:
1 | extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache .so |
# 启动php-fpm服务
1 | service php-fpm restart |
iii) 在 /nfsshared 中建立 testxcache.php 文件测试xcache的启用情况
本文转自My_King1 51CTO博客,原文链接:http://blog.51cto.com/apprentice/1385584,如需转载请自行联系原作者