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
下一篇 2015-10-27

相关推荐

  • 基于ssl的mysql的主从复制

    实验环境: system:CentOS Linux release 7.2.1511 (Core) mariadb server:mariadb-server-5.5.44-2.el7.centos.x86_64 master server:10.1.51.20/16 slave serv…

    2016-11-22
  • keepalived相关配置示例(二)

    虚拟服务器配置实验: 两台centos6主机为web service系统为CentOS6.8 n1:172.16.253.87 n2:172.16.252.5都安装httpd yum install -y httpd[root@n1 ~]#vim /var/www/html/index.html<h1>Real Server 1</h1&g…

    Linux干货 2017-06-28
  • 马哥教育网络班21期+第三周课程练习

    列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登陆多次,只显示一次即可。 ~]# who|cut -d" " -f1|sort -u 2  取出最后登录当前系统的用户的相关信息。    ~]# id `last|head&nbs…

    Linux干货 2016-07-29
  • yum初步入门

                             yum工具是为提高RPM软件安装性而开发的一种软件包管理器,是由pyt…

    Linux干货 2015-04-01
  • 2017全球运维技术大会第二届12大技术专场等你来!

    去年9月,InfoQ在北京主办了第二届CNUTCon全球容器技术大会,大会邀请了来自Netflix、CoreOS、Docker公司、Mesosphere、阿里巴巴、腾讯、百度、京东、携程、搜狗等公司的技术负责人,共同探讨容器相关的应用场景、技术方案以及架构演进,得到了社区的一致好评。 到今年,CNUTCon已经是第三年了,前两年我们的方向是容器,随着技术的发…

    2017-06-20
  • httpd及https

    1、建立httpd服务,要求: (1) 提供两个基于名称的虚拟主机:     www1.stuX.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1/error_log,访问日志为/var/log/httpd/www1/access_log;   &nbs…

    2017-06-05

评论列表(2条)

  • stanley
    stanley 2015-10-22 09:18

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

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

      @stanley多谢夸奖