实验的拓扑图:
实验方案:
我们先在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
我们打开浏览器进行验证:
这时,我们在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主机上,进行配置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
评论列表(2条)
写的非常不错,实战理论并肩,图文并茂,详图得当,赞
@stanley:多谢夸奖