设为首页 收藏本站
查看: 1051|回复: 1

[经验分享] Apache2.4.29+Tomcat 8.5.29负载均衡群集最强解析

[复制链接]

尚未签到

发表于 2018-11-17 13:10:24 | 显示全部楼层 |阅读模式
  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.3、https://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
  报错如下图
DSC0000.jpg DSC0001.jpg

  网上的方法: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,之后再重新编译。
DSC0002.jpg

  成功会有以下提示
  ----------------------------------------------------------------------
  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'
  至于为什么要安装这些东西,请看官方文档
DSC0003.jpg

  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
  官网的解释如下
DSC0004.jpg

  编译参数--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)>  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
DSC0005.jpg

  [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
DSC0006.jpg [root@cheng native]# make && make install

  编译后红箭头的文件变大,这是我自己发现的,哈哈哦

  [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

  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>  刷新变量使其生效source /etc/profile
  至此搞一段落,基础软件已安装完毕。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-636259-1-1.html 上篇帖子: Apache虚拟主机配置详解 下篇帖子: 基于centOS7,快速搭建LAMP(Linux+Apache+MySQL/MariaDB)环境

尚未签到

发表于 2018-11-17 14:12:43 | 显示全部楼层
这些配置写好过后,后面有怎么处理尼

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表