重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
apache+tomcat
http版本2.4
1.http+tomcat通信了解:
http和tomcat通信通過ajp,http,https協(xié)議進(jìn)行通信
http與tomcat基于mod_jd和mod_proxy實(shí)現(xiàn)負(fù)載均衡
1.安裝http
a.下載: apache http:http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.25.tar.gz arp:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz arp-util:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz b.編譯安裝1.先安裝pcre-devel yum install pcre-devel2.先安裝arp >tar -xzf apr-1.5.2.tar.gz >cd apr-1.5.2 >./configure --prefix=/usr/local/apr >make && make install3.安裝arp-util >tar -xzf apr-util-1.5.4.tar.gz >cd apr-util-1.5.4 >./configure --prefix=/usr/local/apt-util --with-apr=/usr/local/apr >make && make insatll4.安裝httpd >tar -xzf httpd-2.4.25.tar.gz >cd httpd-2.4. >./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable--ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modeles=most --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-balencer >make && make install5.配置httpd的環(huán)境 (a).配置httpd服務(wù)啟動(dòng)文件 vim /etc/init.d/http . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi HTTPD_LANG=${HTTPD_LANG-"C"} INITLOG_ARGS="" apachectl=/usr/sbin/httpd/bin/apachectl httpd=/usr/local/httpd/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { status -p ${pidfile} $httpd > /dev/null if [[ $? = 0 ]]; then echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd else echo -n $"Stopping $prog: " success fi RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else # Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } case "$1" in start) start;; stop) stop;; status) status -p ${pidfile} $httpd RETVAL=$?;; restart) stop start;; condrestart|try-restart) if status -p ${pidfile} $httpd >&/dev/null; then stop start fi;; force-reload|reload) reload;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$?;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|forc e-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac exit $RETVAL (b).導(dǎo)出頭文件 ln -sv /usr/local/httpd/include /usr/include/httpd (c).導(dǎo)出幫助文件 vim /etc/man.config MANPATH /usr/local/htppd/man (d).修改環(huán)境變量 vim /etc/profile.d/httpd export PATH=/usr/local/httpd/bin:$PATH 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
2.基于mod_proxy實(shí)現(xiàn)httd+tomcat
a.基于ajp協(xié)議
b.基于http協(xié)議
ProxyVia OffProxyRequests OffProxyPass / http://192.168.100.34:8080/ProxyPa***everse / http://192.168.100.34:8080/c.參數(shù)詳解
ProxyVia {On|Off|Full|Block}:用于控制http首部是否時(shí)喲您Via,主要用于多級(jí)代理中控制代理請(qǐng)求的流向,F(xiàn)ull表示每個(gè)請(qǐng)求報(bào)文都會(huì)添加apache服務(wù)器的版本號(hào)信息,Block表示每個(gè)代理報(bào)文中Via都將被清除。 ProxyPreserveHost {On|Off}:啟用此功能,代理會(huì)將用戶請(qǐng)求報(bào)文中的Host行發(fā)送給后端服務(wù)器,而不使用Proxy_pass指定的服務(wù)器地址,如果在反向代理中支持虛擬主機(jī),則需要開啟此項(xiàng)。 ProxyRequests {On|Off}:是否開啟正向代理,如果設(shè)置proxy_pass這個(gè)必須設(shè)置為OffProxyPass path url [key=value key=value..];將后端服務(wù)器url和本地某虛擬路徑關(guān)聯(lián)起來作為提供服務(wù)的;路徑,path是當(dāng)前服務(wù)器上的某虛擬路徑,如果path以/結(jié)尾,這url也必須以/結(jié)尾。 常用key如下: min:連接池的最小容量,初始化時(shí)的容量。 max:連接池的大容量, loadfactor:用于負(fù)載均衡集群配置中,定義對(duì)應(yīng)后端服務(wù)器的權(quán)重 retry:apache在后端服務(wù)器得到錯(cuò)誤響應(yīng)時(shí),多長(zhǎng)時(shí)間之后在重試,單位為秒,若一致沒有響應(yīng),則會(huì)移除,重新上線以后會(huì)添加進(jìn)來 ProxyPa***everse:用于讓apache調(diào)整HTTP重定向響應(yīng)報(bào)文中的Location,Context-Location及URL標(biāo)簽所對(duì)應(yīng)的URL,在反向代理中必須使用此指令,防止重定向報(bào)文繞過proxy服務(wù)器1234567891012345678910d.測(cè)試
3.基于mod_jk實(shí)現(xiàn)http+tomcat
a.編譯安裝mod_jk
b.配置/etc/httpd.d/httpd.conf
1.vim /etc/httpd.d/httpd.conf LoadModule jk_module modules/mod_jk.so //裝載模塊JkWorkersFile /etc/httpd/extra/workers.properties //設(shè)置workers文件JkLogFile logs/mod_jk.log //定義日志文件JkLogLevel debug //日志級(jí)別JkMount /* TomcatA //根下面的所有路徑都轉(zhuǎn)發(fā)給tomcatAJkMount /status/ stat1 //查看狀態(tài)頁面2.vim /etc/httpd/extra/workers.properties worker.list=TomcatA,stat1 worker.TomcatA.port=8009worker.TomcatA.host=192.168.100.34worker.TomcatA.type=ajp13 worker.TomcatA.lbfactor=1worker.stat1.type=status //狀態(tài)頁面12345678910111213141234567891011121314c.workers.properties詳解:
格式 worker.list = worker.name worker.nameworker.worer_name.property =valueproperty: host:tomcat實(shí)例所在主機(jī) port:所在端口 connection_pool_minsize:最少保持在連接池中鏈接的個(gè)數(shù) connection_pool_timeout:連接池中鏈接超時(shí)時(shí)長(zhǎng) retries:錯(cuò)誤發(fā)生時(shí)重試次數(shù) socket_timeout:mod_jk等待worker響應(yīng)時(shí)長(zhǎng),默認(rèn)偽0,無限等待 socket_keepalive:是否啟動(dòng)長(zhǎng)鏈接,1表示啟用 lbfactor:worker的權(quán)重 type:指定類型,值偽status表示狀態(tài)信息,ajp13表示當(dāng)前worker偽運(yùn)行的一個(gè)實(shí)例,lb表示使用負(fù)載均衡1234567891011121312345678910111213d.測(cè)試結(jié)果
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。