现在服务器都往云方向发展,公司新配服务器全部为电信云服务器,系统为centos7,故而linux服务器配置也越来越多
跟着公司大牛学习,也来记录下安装配置经验
因为公司云服务器只对外开放了9090~9098这几个特定的端口,所以采用apache 监听这些端口并转发到相应的tomcat,实现软负载均衡
以下将主要涉及:apache服务器安装,tomcat安装配置脚本启动,tomcat-connectors,以及tomcat-native安装(OpenSSL升级),apache以及tomcat配置实现多端口监听以及集群负载
服务器环境: 三台centos7服务器,其中一台拥有公网ip:220.190.*.* ,另外两台处于内网,分别为:172.30.1.17,172.30.1.18 。
在公网220.190.*.*服务器上安装apache作为WEB入口,在172.30.1.17,172.30.1.18两台内网服务器上安装tomcat负责实际的业务处理。
[root@localhost ~]# wget http://apache.fayea.com/httpd/httpd-2.4.23.tar.gz
[root@localhost ~]# tar -zxvf httpd-2.4.23.tar.gz
[root@localhost ~]# cd httpd-2.4.23
编译安装
[root@localhost ~]# ./configure --prefix=/opt/servers/httpd24 \
--enable-mpms-shared=all \
--with-pcre=/opt/servers/common64 \
--enable-mods-shared=all \
--enable-ssl \
--with-ssl=yes \
--with-apr=/opt/servers/common64 \
--with-apr-util=/opt/servers/common64 \
--with-crypto
[root@localhost ~]# make
[root@localhost ~]# make install
[root@localhost ~]# cp /opt/servers/httpd24/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# chkconfig --add httpd
可能会提示httpd服务不支持chkconfig,需要编辑/etc/rc.d/init.d/httpd文件,添加以下注释信息:
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# vi /opt/servers/httpd24/conf/httpd.conf
[root@localhost ~]# service httpd start
[root@localhost local]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gz
[root@localhost local]# tar -zxvf apache-tomcat-7.0.70.tar.gz
[root@localhost local]# cp -r apache-tomcat-7.0.70 /opt/servers/
[root@localhost local]# cd /opt/servers/
[root@localhost servers]# mv apache-tomcat-7.0.70/ apache-tomcat-7.0.70-ts1
[root@localhost servers]# ln -s apache-tomcat-7.0.70-ts1 tomcat-ts1
[root@localhost servers]# vi /opt/servers/tomcat-ts1/bin/catalina.sh
# Copy CATALINA_BASE from CATALINA_HOME if not already set
[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"
# 设置pid。一定要加在CATALINA_BASE定义后面,要不然pid会生成到/下面
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
[root@localhost servers]# vi/usr/lib/systemd/system/tomcat-ts1.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/java/jdk1.8.0_101"
PIDFile=/opt/servers/apache-tomcat-7.0.70-ts1/tomcat.pid
ExecStart=/opt/servers/apache-tomcat-7.0.70-ts1/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意jdk的路径和tomcat的路径
[root@localhost servers]# systemctl daemon-reload
[root@localhost servers]# service tomcat-ts1 start
[root@localhost system]# systemctl status tomcat-ts1
提示如下:
[root@localhost local]# wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz
[root@localhost local]# tar -zxvf tomcat-connectors-1.2.41-src.tar.gz
[root@localhost local]# cd tomcat-connectors-1.2.41-src/native
[root@localhost native]# ./configure -with-apxs=/opt/servers/httpd24/bin/apxs
[root@localhost native]# make
[root@localhost native]# make install
[root@localhost local]# wget http://apache.fayea.com/tomcat/tomcat-connectors/native/1.2.8/source/tomcat-native-1.2.8-src.tar.gz
[root@localhost local]# tar -zxvf tomcat-native-1.2.8-src.tar.gz
[root@localhost local]# cd tomcat-native-1.2.8-src.tar/native
[root@localhostnative]# ./configure --prefix=/opt/servers/common64/ --with-ssl=yes --with-java-home=/usr/java/jdk1.8.0_101 --with-apr=/opt/servers/common64
[root@localhost native]# openssl version
提示为:
下载最新的openssl,编译安装
[root@localhost local]# wget https://www-origin.openssl.org/source/openssl-1.0.2h.tar.gz
[root@localhost local]# tar -zxvf openssl-1.0.2h.tar.gz
[root@localhost local]# cd openssl-1.0.2h
[root@localhost openssl-1.0.2h]# ./config shared zlib
[root@localhost openssl-1.0.2h]# make
[root@localhost openssl-1.0.2h]# make install
[root@localhost openssl-1.0.2h]# mv /usr/bin/openssl /usr/bin/openssl.old
[root@localhost openssl-1.0.2h]# mv /usr/include/openssl /usr/include/openssl.old
[root@localhost local]# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
[root@localhost local]# ln -s /usr/local/ssl/include/openssl /usr/include/openssl
[root@localhost local]# echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
[root@localhost local]# ldconfig -v
[root@localhost local]# openssl version
OpenSSL 1.0.2h 3 May 2016
[root@localhost local]# cd /usr/local/tomcat-native-1.2.8-src/native/
[root@localhost native]# ./configure --prefix=/opt/servers/common64/ --with-ssl=yes --with-java-home=/usr/java/jdk1.8.0_101 --with-apr=/opt/servers/common64
[root@localhost native]# make
[root@localhost native]# make install