Apache2.4.29+Tomcat 8.5.29負載均衡羣集搭建


Apache2.4.29+Tomcat 8.5.29負載均衡羣集搭建

公司是做電商的,線上的應用服務器大多都是Apache+Tomcat或者Nginx+Tomcat ,雖然之前也對Apache和Nginx的配置文件熟悉,可對這種負載均衡羣集配置還不是太熟悉,而日常工作經常需要搞這些東西,所以下決心搞明白哈哈哦。結合公司的線上配置,結合官方的文檔說明,特整理如下,方便以後查閱,畢竟好記性不如爛筆頭。

一:本文涉及的相關環境和軟件版本

IP :192.168.86.129/24 ,通過NAT模式同宿主機相連

CentOS-7.4-minimal、http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso

Apache/2.4.29 (Unix)、http://httpd.apache.org/download.cgi#apache24

Apr/1.6.3https://apr.apache.org/download.cgi#aprutil1

Apr-util/1.6.1、https://apr.apache.org/download.cgi#aprutil1

Tomcat/8.5.29、https://tomcat.apache.org/download-80.cgi

jdk-8u161-linux-x64、http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

tomcat-connectors-1.2.43 http://tomcat.apache.org/download-connectors.cgi

二:安裝基礎環境(本文安裝包均提前下載放在/opt下)

[root@cheng opt]# yum -y install wget unzip lrzsz openssl openssl-devel autoconf libtool gcc*

執行yum命令時若出現這個錯誤:Error: database disk image is malformed

這是說明yum的緩存出錯,需要清理緩存,執行yum clean dbcache命令即可

配置環境時configure的主要工作就是生成Makefile,編譯源碼時的make命令就是根據Makefile來進行編譯

1.安裝apr/apr-util/pcre

[root@cheng opt]# rpm -q apr

apr-1.4.8-3.el7_4.1.x86_64

[root@cheng opt]# rpm -q apr-util

apr-util-1.5.2-6.el7.x86_64

[root@cheng opt]# rpm -e apr --nodeps

[root@cheng opt]# rpm -e apr-util --nodeps

[root@cheng opt]# tar zxvf apr-1.6.3.tar.gz

[root@cheng opt]# cd apr-1.6.3

[root@cheng apr-1.6.3]# ./configure --prefix=/usr/local/apr

報錯如下圖

blob.png

網上的方法:https://my.oschina.net/u/146514/blog/196168$RM "$cfgfile這一行註釋,在configure文件30976行

[root@cheng apr-1.6.3]# make && make install

成功會有以下提示

/usr/bin/install -c -m 755 /opt/apr-1.6.3/build/mkdir.sh /usr/local/apr/build-1

for f in make_exports.awk make_var_export.awk; do \

/usr/bin/install -c -m 644 /opt/apr-1.6.3/build/${f} /usr/local/apr/build-1; \

done

/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk

/usr/bin/install -c -m 644 /opt/apr-1.6.3/build/apr_common.m4 /usr/local/apr/build-1

/usr/bin/install -c -m 644 /opt/apr-1.6.3/build/find_apr.m4 /usr/local/apr/build-1

/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config

這時候/usr/local下就會有apr的目錄文件

[root@cheng apr-1.6.3]# cd ../

[root@cheng opt]# tar zxvf apr-util-1.6.1.tar.gz

[root@cheng opt]# cd apr-util-1.61

[root@cheng apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/

[root@cheng apr-util-1.6.1]# make && make install

發現報錯fatal error: expat.h: No such file or directory

解決辦法:根據提示安裝expat包,yum -y install expat-devel,之後再重新編譯。

blob.png

成功會有以下提示

----------------------------------------------------------------------

Libraries have been installed in:

/usr/local/apr-util//lib

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the '-LLIBDIR'

flag during linking and do at least one of the following:

- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable

during execution

- add LIBDIR to the 'LD_RUN_PATH' environment variable

during linking

- use the '-Wl,-rpath -Wl,LIBDIR' linker flag

- have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util//lib

/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util//bin/apu-1-config

[root@cheng apr-util-1.6.1]# cd ..

[root@cheng opt]# cd pcre-8.41

[root@cheng pcre-8.41]# ./configure --prefix=/usr/local/pcre

[root@cheng pcre-8.41]# make  && make install

成功會有以下提示

ln -sf pcre_get_substring_list.3 /usr/local/pcre/share/man/man3/pcre32_get_substring_list.3

ln -sf pcre_jit_exec.3 /usr/local/pcre/share/man/man3/pcre32_jit_exec.3

ln -sf pcre_jit_stack_alloc.3 /usr/local/pcre/share/man/man3/pcre32_jit_stack_alloc.3

ln -sf pcre_jit_stack_free.3 /usr/local/pcre/share/man/man3/pcre32_jit_stack_free.3

ln -sf pcre_maketables.3 /usr/local/pcre/share/man/man3/pcre32_maketables.3

ln -sf pcre_pattern_to_host_byte_order.3 /usr/local/pcre/share/man/man3/pcre32_pattern_to_host_byte_order.3

ln -sf pcre_refcount.3 /usr/local/pcre/share/man/man3/pcre32_refcount.3

ln -sf pcre_study.3 /usr/local/pcre/share/man/man3/pcre32_study.3

ln -sf pcre_utf32_to_host_byte_order.3 /usr/local/pcre/share/man/man3/pcre32_utf32_to_host_byte_order.3

ln -sf pcre_version.3 /usr/local/pcre/share/man/man3/pcre32_version.3

make[3]: Leaving directory `/opt/pcre-8.41'

make[2]: Leaving directory `/opt/pcre-8.41'

make[1]: Leaving directory `/opt/pcre-8.41'

至於爲什麼要安裝這些東西,請看官方文檔

blob.png

2.安裝apache

最好以root安裝和啓動Apache,以root運行之後,apache就會把它的派生進程切換到非root用戶

[root@cheng pcre-8.41]# cd ..

[root@cheng opt]# tar zxvf httpd-2.4.29.tar.gz

[root@cheng opt]# cd httpd-2.4.29ith-apr=

[root@cheng httpd-2.4.29]# ./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-ssl --enable-rewrite --enable-proxy --enable-proxy-http --enable-proxy-ajp --enable-proxy-banlancer --with-zlib --w/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl=/etc/pki/tls  --enable-mods-shared=all --enable-mpms-shared=all --with-mpm=event --with-pcre=/usr/local/pcre

簡單解釋如下

--prefix=/usr/local/httpd 安裝到此文件夾

--sysconfdir=/etc/httpd2.4  指定配置文件路徑       

--enable-so  啓動模塊動態裝卸載        

--enable-ssl 編譯ssl模塊        

--enable-cgi 支持cgi機制(能夠讓靜態web服務器能夠解析動態請求的一個協議)        

--enable-rewrite  支持url重寫            

--with-zlib  支持數據包壓縮              

--with-pcre  支持正則表達式        

--with-apr=/usr/local/apr  指明依賴的apr所在目錄        

--with-apr-util=/usr/local/apr-util/  指明依賴的apr-util所在的目錄        

--enable-modules=most      用most可以將一些不常用的,不在缺省常用模塊中的模塊編譯進來

--enable-mods-shared=all 意思是動態加載所有模塊,如果去掉-shared話,是靜態加載所有模塊        

--enable-mpms-shared=all   以共享方式編譯的模塊        

--with-mpm=event        指明httpd的工作方式爲event

查看apache有那幾個mpm

# ./configure --help|grep mpm

查看apache可以加載那些模塊

./configure --help|grep enable

官網的解釋如下

blob.png

編譯參數--with-ssl可以指明路徑也可以不指,如果要指,可以通過下面命令openssl version -a查看

編譯爲三種都支持:--enable-mpms-shared=all,這樣在編譯的時候會在modules目錄下自動編譯出三個MPM文件的so,然後通過修改httpd.conf配置文件更改MPM(去掉LoadModule mpm_event_module modules/mod_mpm_*.so相應的模塊註釋)

在apache的早期版本2.0默認prefork,2.2版本是worker,2.4版本是event

[root@cheng ~]# openssl version -a

OpenSSL 1.0.2k-fips  26 Jan 2017

built on: reproducible build, date unspecified

platform: linux-x86_64

options:  bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx)

compiler: gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM

OPENSSLDIR: "/etc/pki/tls"

engines:  rdrand dynamic

blob.png

[root@cheng httpd-2.4.29]# make && make install

成功會有如下提示

mkdir /usr/local/httpd/icons

mkdir /usr/local/httpd/logs

Installing CGIs

mkdir /usr/local/httpd/cgi-bin

Installing header files

mkdir /usr/local/httpd/include

Installing build system files

mkdir /usr/local/httpd/build

Installing man pages and online manual

mkdir /usr/local/httpd/man

mkdir /usr/local/httpd/man/man1

mkdir /usr/local/httpd/man/man8

mkdir /usr/local/httpd/manual

make[1]: Leaving directory `/opt/httpd-2.4.29'

3.安裝connectors

[root@cheng opt]# tar zxvf tomcat-connectors-1.2.43-src.tar.gz

[root@cheng opt]# cp -ar tomcat-connectors-1.2.43-src /usr/local/

[root@cheng opt]# cd /usr.local/tomcat-connectors-1.2.43-src

[root@cheng tomcat-connectors-1.2.43-src]# cd native/

[root@cheng native]# ./buildconf.sh

buildconf: checking installation...

buildconf: autoconf version 2.69 (ok)

buildconf: libtool  version 2.4.2 (ok)

buildconf: libtoolize --automake --copy

buildconf: aclocal

buildconf: autoheader

buildconf: automake -a --foreign --copy

buildconf: autoconf

[root@cheng native]# ./configure --with-apxs=/usr/local/httpd/bin/apxs

[root@cheng native]# make && make install

編譯後紅箭頭的文件變大,這是我自己發現的,哈哈哦

blob.png

[root@cheng native]# cd apache-2.0/

[root@cheng apache-2.0]# ls

bldjk54.qclsrc  config.m4  Makefile.apxs     Makefile.in  mod_jk.a  mod_jk.la  mod_jk.o   NWGNUmakefile

bldjk.qclsrc    Makefile   Makefile.apxs.in  Makefile.vc  mod_jk.c  mod_jk.lo  mod_jk.so

[root@cheng apache-2.0]# cp mod_jk.so /usr/local/httpd/modules/

cp: overwrite ‘/usr/local/httpd/modules/mod_jk.so’? y

blob.png

4.安裝tomcat/jdk

[root@cheng apache-2.0]# cd /opt

[root@cheng opt]# tar zxvf apache-tomcat-8.5.29.tar.gz

[root@cheng opt]# cp -ar apache-tomcat-8.5.29 /usr/local/apache-tomcat8

[root@cheng opt]# tar zxvf jdk-8u161-linux-x64.tar.gz

[root@cheng opt]# cp -ar jdk1.8.0_161/ /usr/local/

配置全局環境變量 vi /etc/profile

export JAVA_HOME=/usr/local/jdk1.8.0_161

export JRE_HOME=/usr/local/jdk1.8.0_161/jre

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/jdk1.8.0_161/bin

export CLASSPATH=./:/usr/local/jdk1.8.0_161/lib:/usr/local/jdk1.8.0_161/jre/lib

刷新變量使其生效source /etc/profile

至此搞一段落,基礎軟件已安裝完畢。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章