HA+LB+NAS:三层架构实现群集高可用和高性能
这篇博客就算是小编前两篇有关服务器群集技术的结合,HA+LB+NAS来实现群集的高可用、高并发(主要是针对web服务器),HA和LB相信读者都很清楚啦,那什么是NAS呢,网络存储技术,简单的说就是讲服务器的文件存储转移到一个专门做存储的介质上,改介质是由瘦OS和大容量硬盘组成的,当前端服务器需要数据时直接从后端介质拿就是了,写数据也是直接写到后端,目前做NAS的硬件有很多啦,做瘦OS的小编觉得OPENFILER比较好用,当然还有freeNAS,之所以叫瘦OS(实质是小linux)是因为它不需要太强大的功能,只需要将数据共享出去就是了,比如说NFS,SAMBA,CIFS等等啦,但是其亮点是有友好的界面管理啦,小编这里直接使用LINUX下的NFS来做NAS啦。。
整体结构图
1.NFS服务器配置
1.1.预装wordpress
注:后端存储需要数据库的支持,所以先安装MySql
# tar –zxvf mysql-5.5.15-linux2.6-i686.tar.gz –C /usr/local/
方便打开mysql目录,给解压目录建立软连接
# cd /usr/local
# ln -s mysql-5.5.15-linux2.6-i686 mysql
安装可以参考/usr/local/INSTALL-BINARY文件
78 shell> groupadd mysql
79 shell> useradd -r -g mysql mysql
80 shell> cd /usr/local
81 shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
82 shell> ln -s full-path-to-mysql-VERSION-OS mysql
83 shell> cd mysql
84 shell> chown -R mysql .
85 shell> chgrp -R mysql .
86 shell> scripts/mysql_install_db --user=mysql
87 shell> chown -R root .
88 shell> chown -R mysql data
89 # Next command is optional
90 shell> cp support-files/my-medium.cnf /etc/my.cnf
91 shell> bin/mysqld_safe --user=mysql &
92 # Next command is optional
93 shell> cp support-files/mysql.server /etc/init.d/mysql.server
# groupadd -r mysql
# useradd -r -g mysql mysql –M
# chown -R mysql .
# chogrp -R mysql .
# scripts/mysql_install_db --user=mysql
# chown -R root .
# chgrp -R mysql data
# cp support-files/my-medium.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
更改mysqld的权限
# chmod a+x /etc/init.d/mysqld
# chkconfig –add mysqld
配置mysql的环境变量
# vim /etc/profile
44 PATH=$PATH:/usr/local/mysql/bin
# . /etc/profile(.后面加空格)
创建mysql.conf文件并添加库文件路径
# vim /etc/ld.so.conf.d/mysql.conf
(添加下面内容)
/usr/local/mysql/lib
# ldconfig
为头文件建立连接
# cd /usr/local/mysql
# ln -s include /usr/include/mysql
给root用户密码
# mysqladmin -u root -p password '123456'
# service mysqld restart
注:其实就是将wordpress的站点文件展开就是了,真正的配置可以在前端的web服务器上完成
# unzip wordpress-3.0.5-zh_CN.zip
# cdwordpress-3.0.5-zh_CN
# mv wordpress /usr/local/nginx/html/website
创建mybbs数据库
# mysql–u root –p
Enter password:
mysql>create database mybbs;
mysql>grant all on mybbs to ‘root’@’192.168.110.10’identified by ‘123456’;
mysql>grant all on mybbs to ‘root’@’192.168.110.12’identified by ‘123456’;
mysql>grant all on mybbs to ‘root’@’192.168.110.13’identified by ‘123456’;
mysql>flush privileges;
在/usr/local/nginx/html/website下创建一个隐藏的.test.html用于director对服务器的监控时反馈信息
# cd/usr/local/nginx/html/website
# echo ‘ok’ .test.html
动态网站搭建完成
1.2.服务器端配置
确保服务器端已经安装以下有关nfs的软件包
# rpm -qa |grep nfs
nfs-utils-lib-1.0.8-7.6.el5
nfs-utils-1.0.9-42.el5
查看rpc工作状态
# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 653 status
100024 1 tcp 656 status
100011 1 udp 663 rquotad
100011 2 udp 663 rquotad
100011 1 tcp 666 rquotad
100011 2 tcp 666 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 38515 nlockmgr
100021 3 udp 38515 nlockmgr
100021 4 udp 38515 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 tcp 34341 nlockmgr
100021 3 tcp 34341 nlockmgr
100021 4 tcp 34341 nlockmgr
100005 1 udp 677 mountd
100005 1 tcp 680 mountd
100005 2 udp 677 mountd
100005 2 tcp 680 mountd
100005 3 udp 677 mountd
100005 3 tcp 680 mountd
把/usr/local/nginx/html/website并修改权限
# chmod o+wt /usr/local/nginx/html/website
编辑共享清单信息
# vim /etc/exports
/usr/local/nginx/html/website 192.168.110.0/28(rw,sync)(给192.168.110.0/28网段的用户对/usr/local/nginx/html/website有读写权限)
# exportfs –r (刷新共享清单)
# service nfs restart
2.web服务器配置
2.1.web服务器1配置
2.1.1.LAMP环境的搭建
搭建前准备工作
下载一下安装包:
httpd-2.4.4
apr-1.4.6
apr-util-1.5.1
pcre采用光盘镜像的rpm安装包
mysql-5.6.10
php-5.4.13
phpMyAdmin-3.5.8-all-languages
ZendOptimizer-3.3.0a-linux-glibc21-i386
确保搭建的平台有以下开发组件
Development Libraries
Development Tools
Legacy Software Development
X Software Development
安装apache
源码安装httpd:
安装使用httpd我们必须先安装apr和它的工具apr-util
解压apr和apr-util并进入解压后的目录进行编译安装
#tar –zxvf apr-1.4.6.tar.gz –C /usr/local/src/
#tar –zxvf apr-util-1.5.1.tar.gz –C /usr/local/src/
# cd/usr/local/src/ apr-1.4.6
# ./configure –prefix=/usr/local/apr
# make&& make install
# cd /usr/local/src/ apr-util-1.5.1
# ./configure --with-apr=/usr/local/apr/bin/apr-1-config
# make&& make install
yum安装pcre和pcre-devel
# yum install pcre
# yum install pcre-devel
解压httpd并编译安装
# tar –jxvf httpd.2.4.4.tar.bz2 –C /usr/local/src/
# cd/usr/local/src/ httpd.2.4.4
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-pcre --with-z --enable-mpms-shared=all
# make&& make install
为头文件目录建一个链接,方便用户能够访问到include文件
# ln -s /usr/local/apache/include /usr/include/apache
方便启动关闭重启apache服务建立httpd控制脚本
# vim /etc/init.d/httpd
#!/bin/sh
#set -x
#description:http server
#chkconfig:2345 88 60
HTTPD='/usr/local/apache/bin/httpd'
CONFFILE='/etc/httpd/httpd.conf'
start(){
[ -f /var/lock/subsys/httpd ] && echo "apache is started" && exit
echo -n "starting apache......."
sleep 1
$HTTPD -f $CONFFILE && RETVAL=0 ||RETVAL=1
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/httpd && echo "ok" || echo "fail"
}
stop(){
[ ! -f /var/lock/subsys/httpd ]&& echo "httpd is stoped......" && exit
echo -n "stoping httpd......"
sleep 1
/bin/rm -rf /var/lock/subsys/httpd
$HTTPD -k stop && RETVAL=0 || RETVAL=1
[ $RETVAL -eq 0 ] && rm -rf /var/lock/subsys/httpd && echo "ok" || echo "fail"
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "start|stop|restart"
;;
Esac
# service httpd start
starting apache.......ok
安装mysql
# tar -zxvf mysql-5.6.10.tar.gz -C /usr/local/src/
安装mysql需要cmake,Cmake它相当于./configure
安装cmake
# tar -zxvf cmake-2.8.10.2.tar.gz -C /usr/local/src/
# cd/usr/local/src/ cmake-2.8.10.2
# ./configure --prefix=/usr/local/cmake
执行make && make install
Cmake的可执行文件在/usr/local/cmake/bin目录下为了方便使用cmake,更改/etc/profile文件内容,添加一条PATH值,能直接使用cmke
# vim /etc/profile
45 PATH=$PATH:/usr/local/cmake/bin
安装mysql
# cd/usr/local/src/ mysql-5.6.10
# cmake .
# make&& make install
Mysql默认安装到/usr/local/下,增加mysql组创建用户并更改mysql目录下的所属者和所属组
# cd /usr/local/mysql
# groupadd mysql
# useradd -r -g mysql mysql
# chown -R mysql .
# chgrp -R mysql .
初始化mysql
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql
进行权限更改
# chown -R root .
# chown -R mysql data
拷贝/mysql/ support-files目录下配置文件到/etc/my.cnf作为新的配置文件
# cd /usr/local/mysql/ support-files
# cp my-default.cnf /etc/my.cnf
拷贝mysql.server文件到/etc/init.d/mysqld作为新的控制文件,并给它执行权
# cp mysql.server /etc/init.d/mysqld
# chmod a+x /etc/init.d/mysqld
为直接使用mysql命令添加mysql环境变量
# vim /etc/profile
45 PATH=$PATH:/usr/local/cmake/bin:/usr/local/mysql/bin
给数据库创建用户和密码
# mysqladmin -u root -p password 123456
登录
# mysql -u root –p
Enter password:
使系统能够正确找到lib文件,我们需要给它指定正确的lib路径,创建一个mysql.conf在里面写入lib的路径/usr/local/mysql/bin,并对ld.so.cache文件刷新
# vim /etc/ld.so.conf.d/mysql.conf
加入下面内容
/usr/local/mysql/bin
# ldconfig(刷新)
再给头文件做一个链接
# ln -s /usr/local/mysql/include /usr/include/mysql
安装php
# tar -jxvf php-5.4.13.tar.bz2 -C /usr/local/src/
# cd /usr/local/src/ php-5.4.13
# ./configure --prefix=/usr/local/php --sysconfdir=/etc --with-apxs2=/usr/local/apache/bin/apxs --with-zlib --with-gd --with-jpeg-dir --with-png-dir --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --disable-xml --with-freetype-dir --enable-xml
# Make && make install
添加php的环境路径:
# vim /etc/profile
指定php的lib文件路径
# vim /etc/ld.so.conf.d/php.conf
加入以下内容
/usr/local/php/lib
# ldconfig(更新)
为头文件建立链接
# cd /usr/local/php
# ln -s include /usr/include/php
为了让apache能够处理一些php网页,我们要加入一些模块,向httpd.conf文件内加入语句
# vim /etc/httpd/httpd.conf
147 LoadModule php5_module modules/libphp5.so
148 AddType application/x-httpd-php .php .phtml
246 <IfModule dir_module>
247 DirectoryIndex index.html index.php
248 </IfModule>
更改web主站点路径到挂载目录,并创建虚拟主机头
213 DocumentRoot "/var/www/website"
514 <Virtualhost 192.168.110.12:80>
515 DocumentRoot /var/www/website
516 ServerName www.zzdx.com
517 ErrorLog logs/tec_error_log
518 CustomLog logs/tec_access_log combined
519 </VirtualHost>
# service httpd restart
stoping httpd......ok
starting apache.......ok
2.1.2.Zend加速php
# tar -zxvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
# cd ZendOptimizer-3.3.0a-linux-glibc21-i386
# ./install
安装过程(如图2-1-2-1至图2-1-2-7)
图2-1-2-1
图2-1-2-2
图2-1-2-3
指定zend的安装路径
图2-1-2-4
指定zend配置文件安装路径
图2-1-2-5
图2-1-2-6
指定apachectl的路径
图2-1-2-7