[LINUX]高可用PHP网页空间负载均衡服务器配置(一)

主讲apache、php、keepalived、ipvsadm配置

近期需求:个人网页空间,允许用户直接上传页面文件到家目录下wwwroot文件夹中即可通过浏览器访问网页。

环境:Centos 7 + Apache (Userdir+vhost)+ Mysql (主从复制) + php5.6.22 + keepalive + rsync(如果有双活存储可以忽略rsync直接使用同一个存储即可) + iptables + ipvsadm

主节点IP:192.168.1.125

从节点IP:192.168.1.126

虚拟IP:192.168.1.124

配置:

一、安装Apche


yum -y install httpd httpd-devel
systemctl enable httpd
iptables -A INPUT -t tcp --dport 80 -j ACCEPT
iptables -A INPUT -t tcp --dport 443 -j ACCEPT
service iptables save

安装httpd-devel是为了给下面安装PHP使用,否则系统中没有apxs,无法编译php的apache依赖。

编辑httpd配置文件添加如下内容,否则安装PHP后无法使用PHP。


vim /etc/httpd/conf/httpd.conf

IncludeOptional conf/vhost/*.conf

<FilesMatch ".+\.ph(p[345]?|t|tml)$">  
    SetHandler application/x-httpd-php  
</FilesMatch>  
<FilesMatch ".+\.phps$">  
    SetHandler application/x-httpd-php-source  
    # Deny access to raw php sources by default  
    # To re-enable it's recommended to enable access to the files  
    # only in specific virtual host or directory  
    Order Deny,Allow  
    Deny from all  
</FilesMatch>  
# Deny access to files without filename (e.g. '.php')  
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">  
    Order Deny,Allow  
    Deny from all  
</FilesMatch>  
  
# Running PHP scripts in user directories is disabled by default  
#   
# To re-enable PHP in user directories comment the following lines  
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it  
# prevents .htaccess files from disabling it.  
<IfModule mod_userdir.c>  
    <Directory /home/*/public_html>  
        php_admin_flag engine Off  
    </Directory>  
</IfModule>  


修改httpd的userdir配置文件,否则使用用户家目录下的文件夹做网页根目录会出现权限问题,本文使用了部分userdir的功能,主要还是使用vhost做域名访问控制。


vim /etc/httpd/conf.d/userdir.conf


没有包含配置中的注释,下面是全部配置文件


<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disabled

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disabled" line above, and uncomment
    # the following line instead:
    # 
    UserDir wwwroot
</IfModule>

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/home/*/wwwroot">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
</Directory>



二、安装PHP

因为epel源中提供的PHP是5.4版本的,而现在多数使用到的PHP 版本是5.6,所以需要通过源码编译安装PHP。

下面是安装过程:


 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-iconv-dir=/root/lnmp1.3-full/src/php-5.6.22/ext/iconv/ --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-intl --with-xsl --with-apxs2=/usr/bin/apxs
make -j4 && make install
systemctl start httpd


三、一个添加用户的脚本

相关目录(没带sh的都是目录,为了后续添加别的脚本需要的模板文件创建的):

[root@personal ~]# ls /root/maintaintools/
adduser.sh  templates  vhostconf


#/bin/bash
read -p "Input user name:" USERNAME
echo $USERNAME
useradd $USERNAME
mkdir /home/$USERNAME/wwwroot
chmod -R 755 /home/$USERNAME
read -p "Input domain:" DOMAIN
yes | cp /root/maintaintools/templates/vhost.conf /root/maintaintools/vhostconf/$DOMAIN.conf
echo $DOMAIN $USERNAME
cat /root/maintaintools/templates/vhost.conf | sed "s/DOMAIN/$DOMAIN/" > /root/maintaintools/vhostconf/$DOMAIN.conf.tmp
cat /root/maintaintools/vhostconf/$DOMAIN.conf.tmp | sed "s/USERNAME/$USERNAME/" > /root/maintaintools/vhostconf/$DOMAIN.conf
rm -f /root/maintaintools/vhostconf/$DOMAIN.conf.tmp
yes | mv /root/maintaintools/vhostconf/$DOMAIN.conf  /etc/httpd/conf/vhost/
systemctl restart httpd



四、安装keepalive

此时需要克隆一个虚拟机出来,然后修改相关网络配置及host名。

修改keepalived文件,配置为轮询模式即做负载均衡又做高可用集群。

vim /etc/keepalived/keepalived.conf

邮件通知的部分请自行设置。

主节点配置:


vrrp_instance VI_1 {
    state MASTER
    interface 主节点网卡名
    virtual_router_id 125 
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 你的密码
    }
    virtual_ipaddress {
        你对外提供服务的VIP
    }
}



从节点配置:


vrrp_instance VI_1 {
    state SLAVE
    interface 从节点网卡名
    virtual_router_id 126
    priority 50 
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 你的密码
    }
    virtual_ipaddress {
        你对外提供服务的VIP
    }
}


通用配置(放在主从配置下面):


virtual_server 192.168.1.124 80 {
    delay_loop 6
    lb_algo wlc #rr为轮询算法,wlc为最小连接算法
    lb_kind DR #直联模式
    protocol TCP #协议TCP

    real_server 192.168.1.125 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.1.126 80 {
        weight 50 #从节点的权重必须低于主节点
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

}


添加自启并启用keepalived服务:


systemctl enable keepalived
systemctl start keepalived
五、安装监控服务ipvsadm


通过ipvsadm可以查看当前节点在线的节点、权重、激活连接数、未激活连接数;


yum -y install ipvsadm
ipvsadm -ln


版权所有:《Hoiwan's 》 => 《[LINUX]高可用PHP网页空间负载均衡服务器配置(一)
本文地址:http://ihoiwan.com/?post=43
除非注明,文章均为 《Hoiwan's 》 原创,欢迎转载!转载请注明本文地址,谢谢。

评论:

nknjseGew
2017-08-02 01:54
clistere di acqua salata per perdere peso http://cigopweight.space/2-3zu37-t9n8.html gyakorlatok a lábak és a has fogyás videó http://cigopweight.space/3epd58915967n5-mc1.html ciò pietra indossare dimagrimento http://cigopweight.space/jsux7ta2yp-uoh21.html come perdere peso velocemente su di tè e caffè http://cigopweight.space/e2duk3n35qt6s18a1o.html Senf als Mittel zur Gewichtsabnahme http://cigopweight.space/6uh6k894o9g8s8ezol6.html turmixok fogyás otthon egy turmixgép http://cigopweight.space/rpplb6-ik88o1.html ez lehet kizárni, hogy néhány, a japán étrend http://cigopweight.space/8shiymcb1mfiz8-x62j.html aminosavak fogyás http://cigopweight.space/y8iegd6771dk55tg.html mi ha aiutato pillole http://cigopweight.space/12w44q-am878i796.html über Gewichtsverlust Anzeigen auf TNT http://cigopweight.space/gb6d-d4t27n-2.html wie man Gewicht im Bauchbereich Forum zu verlieren http://cigopweight.space/lu5373v9b74.html pillole per la dieta di droga http://cigopweight.space/641qrv-5595182zkt.html su come si può perdere peso con l'aiuto di tè per la perdita di peso http://cigopweight.space/5b544yd821j98c-cc-qr.html obesità 1 grado nelle donne trattate http://cigopweight.space/3g8ues1b76az844.html Guarda gettato fuori a guardare in sovrappeso Stagione 1 http://cigopweight.space/h6-1s97b663.html dopo cesareo da quanto si può perdere peso e come http://cigopweight.space/i-9ga8-a-rz9z8824.html come perdere peso nello stomaco senza dieta per una settimana http://cigopweight.space/fk271fr-b-sx828l3f8m5a.html kunfuchay per la perdita di peso dove acquistare http://cigopweight.space/5m-s8m45pb337-z7w85.html jóga a fogyás videó http://cigopweight.space/24384637e4a5xixz5l-p4.html 11 Rezepte für Gewichtsverlust http://cigopweight.space/26y1pys99ab86drb.html quando mangiare polenta in acqua, si può perdere peso http://cigopweight.space/4-xc48-75kzxk-6xa6y3pp.html biscotti di farina d'avena casalinghi nella dieta http://cigopweight.space/6-g2tx-3835z2.html Perdita di peso campo di Crimea http://cigopweight.space/t77578374oxph4s-1.html gyógynövények fogyás http://cigopweight.space/2a3ked538f8-n4-82x3m73.html fogyni segítségével létrák http://cigopweight.space/lselklk86-ny2b-gcbp.html su come si può perdere peso se si dispone di 3 giorni ad alcune mele http://cigopweight.space/9ra1l-ce54-a.html míg fogyókúra év http://cigopweight.space/c5gxd9q61al.html Preparazione porridge di mais per la perdita di peso http://cigopweight.space/1h61686k3k725fqz9p.html Slimmerbelt Preise Sauna http://cigopweight.space/781x259uhhh-4t.html lehetséges az, hogy lefogy a mézes masszázs http://cigopweight.space/r-n7fx29158swbi9ju-d3.html Diéta 5 evőkanál fotó lefogyott előtt és után http://cigopweight.space/7evjleo3-eq3.html zsírt éget nem izom http://cigopweight.space/6-2p2-as-8v54xl69cpy.html uborka diéta 3 napig http://cigopweight.space/282961wb7a83x96qv3.html jogging zsírt éget a has http://cigopweight.space/76b5hwp5u9.html blog sulla perdita di peso http://cigopweight.space/n4174-v6-2gp87.html Gewicht zu verlieren, nachdem Tests http://cigopweight.space/q-txjxro6r93uj8v52.html fogyás égett izmok http://cigopweight.space/n2-623ma4a8leq48kucj.html History fogyókúra 2016. táplálkozás http://cigopweight.space/gzxw572436r2f.html Backpulver für die Gewichtsabnahme Forum http://cigopweight.space/p8g2gp87fp7hk1-o718-4d.html omega 3 perdita di peso http://cigopweight.space/jo29g6-c-w1t5ussakgp92.html hogyan kell fogyni a testmozgás http://cigopweight.space/35f78-km-9ij-9.html glyukofazh 750 recensioni di Long dimagranti forum http://cigopweight.space/5lq-l6bl2d4c19rq.html pasti dividere giuste per recensioni di perdita di peso http://cigopweight.space/jan-ty9396c5pidlj9v4a.html Gewicht und Übergewicht http://cigopweight.space/as2r5bb-eb66b6u.html È la migliore dieta del mondo http://cigopweight.space/24shimap9k2hg5-122.html tiroxina Guida di dimagrimento http://cigopweight.space/56-6xcsl5v6.html Diät auf grünem Tee und Reis, und die Ergebnisse der Bewertungen http://cigopweight.space/6cc4sf6j-my8r4x35ag.html Carnation Milchdiät http://cigopweight.space/68pgfw34975-abu.html teljes képzést fogyás http://cigopweight.space/4g-6qpm2d9oi874.html Folyamatosan álmos túlsúlyos http://cigopweight.space/133w6clv1-lnu74.html 3 diéta csoport menü napján vér http://cigopweight.space/a2h9c28-q9kn.html einige zu Fuß zur Gewichtsreduktion http://cigopweight.space/5nmo-wtz3h238.html Diät für Darmdysbiose Menü für eine Woche Ärzte Empfehlungen http://cigopweight.space/yl6-8vuh24-7y.html come utilizzare una dieta del riso per la perdita di peso http://cigopweight.space/o-lad7y4qg57jqr4611.html einer für alle STB über Gewichtsverlust http://cigopweight.space/f367-hk4q5-5y.html ábra korrekció Norbekov ingyenesen letölthető http://cigopweight.space/w3i73g2z-7-8hs1.html Diät auf Perlovka besser als Buchweizen http://cigopweight.space/b4mm5p6-5686.html ballare il video dimagrante per adulti http://cigopweight.space/949kd261rtw1-g2627-p1.html Brüste nach der Wiederherstellung Schlankheits Volumen http://cigopweight.space/15h-c48oh83gnmes.html Weg, um Gewicht zu verlieren, mit Chrom http://cigopweight.space/y71-suyh5o-572894.html diéta 2 hetes terhesség http://cigopweight.space/7asf2x573nti32.html medico Bubnovsky di perdere peso http://cigopweight.space/taga3u2-2m565a-u9iw3a.html Dr. Gavrilova dimagrante http://cigopweight.space/jlbn4-gjndi33-4.html Slimming Capsule migliori recensioni Slim http://cigopweight.space/mqqx2y-12bfq.html dieta giorni cioccolato http://cigopweight.space/15xo-aw72w-i86hu-4.html Video Bodyflex dimagrante gratis http://cigopweight.space/zc9ja95d982wr.html fahéj fogyókúra 8 kg http://cigopweight.space/7hxwvw-2752i-zvh-m668.html tipo di dieta giapponese http://cigopweight.space/2-s39r4584hb-3247oa8.html cerotto dimagrante pancia mymi http://cigopweight.space/suc9-xc2h2-218n7gxm.html Mindkét veszi fogyókúra lenolaj
nxrmsrGew
2017-08-02 05:09
toprj28n8y</br>
payday advance loans</br>
<a href="http://paydayloans2017.com"> payday loans online no credit check</a> </br>
&lt;a href=&quot;http://cashadvances2017.com&quot;&gt; payday loans online&lt;/a&gt; </br>
[url=http://paydayloans2017.com]online payday loans[/url] </br>
payday loans bad credit
nwbsoyGew
2017-08-03 02:12
topkj50l8c</br>
ace payday loans</br>
<a href="http://cashadvances2017.com"> payday loans no credit check</a> </br>
&lt;a href=&quot;http://cashadvances2017.com&quot;&gt; payday loan online&lt;/a&gt; </br>
[url=http://cashadvances2017.com]legitimate payday loans online no credit check[/url] </br>
payday loans bad credit

发表评论: