lvs nat模型调度双http服务且http上布置discuz

实验的拓扑图:

X1(6((UGB{I}@N2EBB`SV$O.png实验方案:

我们先在real server上编译安装好http,然后,咋们切换到mysql服务器上安装mysql,在换到http主机上编译php的工作方式基于模块的,再把discuz资源放到http的资源访问目录下,且在双方http主机上布上rsync服务器,双反的主机也要加上inotify来实时关注http访问目录的资源变化,有变化就要数据的传输,最后,我们到dirctor上布上lvs就好了。

实验开始:

第一步:

编译http前,先解决软件的依赖关系,所以,要先编译apr apr-util:

tar xf apr-1.5.0.tar.bz2
cd apr-1.5.0
./configure --prefix=/usr/local/apr
make && make install

tar xf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util
make && make install

我们的编译软件包的依赖关系解决了,所以,我们需要编译http了:

tar xf httpd-2.4.9.tar.bz2
cd httpd-2.4.9
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr=/usr/local/apr-util --sysconfdir=/etc/httpd  --enable-so --enable-modules=most --enable-rewrite --with-z --with-libxml2 --with-mpm=event --enable-mpms-shared=all 
make && make install

我们的http服务器弄好了,同时,别忘了,给另一台real server编译http服务了,这里就不重复了,按照上面步骤就可以了,我们切换到mysql服务器上,给它布上mysql:

tar xf mariadb-10.0.10-linux-x86_64.tar.gz
mv mariadb-10.0.10-linux-x86_64 /usr/loca/mysql
mkdir -p /mysql/data
groupadd -r mysql
useradd mysql -r -g mysql
chown -R root:mysql /usr/local/mysql/*
chown -R mysql:mysql /mysql/data
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mysql/data --basedir=/usr/local/mysql
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
:wq
source /etc/profile.d/mysql.sh
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld 
service mysqld start
mysql
mysql>grant all on *.* to bwei@'172.16.100.%' identified by 'bwei';(建立http主机连接mysql的用户)
mysql>flush privileges;
mysql>\q

我们的mysql服务器就安装完成了,这时,我们又切换到real server 上把php编译安装完成:

tar xf php-5.4.26.tar.bz2
cd php-5.4.26
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-zlib-dir  --with-jpeg-dir --with-png-dir  --with-freetype-dir --enable-mbstring --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-sockets --with-libxml-dir=/usr --enable-maintainer-zts --with-mcrypt
make && make install
cp php.ini-production /etc/php.ini

vim /etc/httpd/httpd.conf 
DirectoryIndex index.html index.php

AddType Application/x-httpd-php .php
AddType Application/x-httpd-php-source .phps

:wq

建立测试页:
vim /usr/local/apache/htdocs/index.php
<?php

        $con=mysql_connect('172.16.100.3','bwei','bwei');
        if ($con)
        echo "ok!";
        else
        echo "false!";
        mysql_close();
        phpinfo();

?>
:wq

/usr/local/apache/bin/apachectl start

我们打开浏览器进行验证:

7T8XE(EJ`33@1}~[X%77698.png

这时,我们在real server上放置discuz资源:

unzip Discuz_7.2_FULL_SC_GBK.zip
cp -r upload /usr/local/apache/htdocs/discuz
chmod 777 -R /usr/local/apache/htdocs/discuz/*

这时,我们需要实现数据的同步,在服务器上弄rsyncd服务器和inotify:

yum install -y xinet
chkconfig --add rsync
chkconfig rsync on
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
max connections =10
strict modes = yes
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log

[share]
path = /usr/local/apache/htdocs
ignore errors = yes
read only = no
write only = no
hosts allow = 172.16.100.0/24
hosts deny = *
list false
uid = root
gid = root
auth users = bwei
secrets file = /etc/rsyncd.passwd

:wq

echo bwei:bwei > /etc/rsyncd.passwd

tar xf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure 
make && make install

给inotify提供脚本用到的对方密码的文件:
mkdir /password
echo bwei > /password/rsyncd.password

提供同步脚本:
vim rsyncd.sh
#!/bin/bash
SRC=/usr/local/apache/htdocs/
DEST=share
HOST=172.16.100.2
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $SRC | while read files;
do
        rsync -vzrtopg --delete --progress --password-file=/password/rsyncd.password $SRC bwei@$HOST::$DEST
done

上面的rsync服务器和inotify都要在另一个real server上准备一份,且另一台real server也需要提供同步脚本,这个脚本修改一下上面就行了!

启动http服务,然后,打开浏览器进行安装discuz,再用一个real server访问discuz发帖,访问另一个real server看帖是否还在:

lvs nat模型调度双http服务且http上布置discuzEB26E`ON89%57[P}T79E)J3.jpg

T%X[62H6H[[6XA%L1FF6)P5.png

我们需要到lvs主机上,进行配置ipvs规则:

yum install ipvsadm -y
ipvsadm -A -t 192.168.100.1:80 -s rr 
ipvsadm -a -t 192.168.100.1:80 -r 172.16.100.1 -m 
ipvsadm -a -t 192.168.100.1:80 -r 172.16.100.2 -m

我们的ipvs规则配置好了,这时,我们可以进行real server的调度了,可以使用 watch ipvsadm -L -n 进行监控,查看调度到那个节点上。

实验完毕!

原创文章,作者:13-广州-杨过,如若转载,请注明出处:http://www.178linux.com/8878

(0)
13-广州-杨过13-广州-杨过
上一篇 2015-10-22 09:13
下一篇 2015-10-27 23:12

相关推荐

  • 马哥教育网络班21期+第15周课程练习

    1、总结sed和awk的详细用法; sed 流编辑器,处理一行数据到模式空间(p),不匹配条件话就输出源行,匹配条件且有处理话,就输出处理过后的行和源行, 匹配条件且没有处理动作的话,只输出p空间的行;保持空间(h)用来存放模式空间的临时处理结果 [root@centos ~]# sed ''&nb…

    Linux干货 2016-08-30
  • 用户,管理,权限

    主要是介绍一些 关于创建用户 ,更改用户信息及密码 ,还有权限管理等等。可能介绍的不全还请大佬们多多关照新人!

    Linux干货 2017-11-24
  • 重定向与管道

         本次内容    1.三种I/O设备    2.把I/O从定向入文件    3.命令tr    4.使用管道链接命令    5.tee   我们都知道程序是由:指令+数据    &n…

    2017-07-23
  • 配置epl时,出现“time out”错误,解决办法

    一:配置环境、网络环境及出现的故障 1:配置环境 本机在配置epel仓库时,配置文件所在路径为/etc/yum/repos.d/centos7.repo.以下为配置文件的的详细内容 [base]name=centos 7.3baseurl=file:///misc/cdgpgkey=file:///misc/cd/RPM-GPG-KEY-Centos-7 […

    2017-06-10
  • yum安装 源码安装实例

     yum安装 源码安装实例 §·源码安装 http 2.2.29实例 1     1.下载源码包。 1     2.配置系统需要的编译环境。 2     3 ./configure ; make  ;…

    Linux干货 2016-08-24
  • Linux启动和内核管理

                                        Linux启动和内核管理 本章内容: centos5和centos6的启动流程 服务管理 grub…

    系统运维 2016-09-21

评论列表(2条)

  • stanley
    stanley 2015-10-22 09:18

    写的非常不错,实战理论并肩,图文并茂,详图得当,赞

    • 杨过
      杨过 2015-10-23 16:02

      @stanley多谢夸奖