您好,登錄后才能下訂單哦!
apache+tomcat
http版本2.4
1.http+tomcat通信了解:
http和tomcat通信通過ajp,http,https協議進行通信
http與tomcat基于mod_jd和mod_proxy實現負載均衡
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的環境 (a).配置httpd服務啟動文件 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).導出頭文件 ln -sv /usr/local/httpd/include /usr/include/httpd (c).導出幫助文件 vim /etc/man.config MANPATH /usr/local/htppd/man (d).修改環境變量 vim /etc/profile.d/httpd export PATH=/usr/local/httpd/bin:$PATH 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
2.基于mod_proxy實現httd+tomcat
a.基于ajp協議
ProxyVia off ProxyRequests offProxyPreserveHost off<Proxy *> Require all granted</Proxy>ProxyPass / ajp://192.168.100.34:8009/ProxyPa***everse / ajp://192.168.100.34:8009/<Location /> Require all granted</Location>12345678910111234567891011
b.基于http協議
ProxyVia OffProxyRequests OffProxyPass / http://192.168.100.34:8080/ProxyPa***everse / http://192.168.100.34:8080/<Proxy *> Require all granted</Proxy><Location />Require all granted</Location>1234567891012345678910
c.參數詳解
ProxyVia {On|Off|Full|Block}:用于控制http首部是否時喲您Via,主要用于多級代理中控制代理請求的流向,Full表示每個請求報文都會添加apache服務器的版本號信息,Block表示每個代理報文中Via都將被清除。 ProxyPreserveHost {On|Off}:啟用此功能,代理會將用戶請求報文中的Host行發送給后端服務器,而不使用Proxy_pass指定的服務器地址,如果在反向代理中支持虛擬主機,則需要開啟此項。 ProxyRequests {On|Off}:是否開啟正向代理,如果設置proxy_pass這個必須設置為OffProxyPass path url [key=value key=value..];將后端服務器url和本地某虛擬路徑關聯起來作為提供服務的;路徑,path是當前服務器上的某虛擬路徑,如果path以/結尾,這url也必須以/結尾。 常用key如下: min:連接池的最小容量,初始化時的容量。 max:連接池的最大容量, loadfactor:用于負載均衡集群配置中,定義對應后端服務器的權重 retry:apache在后端服務器得到錯誤響應時,多長時間之后在重試,單位為秒,若一致沒有響應,則會移除,重新上線以后會添加進來 ProxyPa***everse:用于讓apache調整HTTP重定向響應報文中的Location,Context-Location及URL標簽所對應的URL,在反向代理中必須使用此指令,防止重定向報文繞過proxy服務器1234567891012345678910
d.測試
3.基于mod_jk實現http+tomcat
a.編譯安裝mod_jk
1.下載: http://mirror.bit.edu.cn/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.42-src.tar.gz2.安裝: >tar -xzf tomcat-connectors-1.2.42-src.tar.gz >cd tomcat-connectors-/native/ >./configure --with-apxs=/usr/local/http/bin/apxs(如果http是yum安裝,請安裝httpd-devel,rpm -ql httpd-devel找到apxs路徑) >make && make install12345671234567
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 //設置workers文件JkLogFile logs/mod_jk.log //定義日志文件JkLogLevel debug //日志級別JkMount /* TomcatA //根下面的所有路徑都轉發給tomcatAJkMount /status/ stat1 //查看狀態頁面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 //狀態頁面12345678910111213141234567891011121314
c.workers.properties詳解:
格式 worker.list = worker.name worker.nameworker.worer_name.property =valueproperty: host:tomcat實例所在主機 port:所在端口 connection_pool_minsize:最少保持在連接池中鏈接的個數 connection_pool_timeout:連接池中鏈接超時時長 retries:錯誤發生時重試次數 socket_timeout:mod_jk等待worker響應時長,默認偽0,無限等待 socket_keepalive:是否啟動長鏈接,1表示啟用 lbfactor:worker的權重 type:指定類型,值偽status表示狀態信息,ajp13表示當前worker偽運行的一個實例,lb表示使用負載均衡1234567891011121312345678910111213
d.測試結果
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。