實驗的拓撲圖:
實驗方案:
我們先在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.www58058.com/8878
寫的非常不錯,實戰理論并肩,圖文并茂,詳圖得當,贊
@stanley:多謝夸獎