本文是生产环境中的一个案例,主要是为了通过反向代理实现多条线路容灾。在原有的基础上升级了openssl,openssh,nginx,通过一些模块来实现我们的需求。
正常情况下,反向代理会去请求online下面的主机,使用sticky模块实现session粘连。如果online的下面的主机全部挂掉了,这个时候,它会去出502报错(或404,具体与你的环境有关),此时它会启用下failover下面的主机,以实现线路容灾。具体的容灾方式,你可以选择多个。比如使用backup来进行标识。使用了nginx_upstream_check_module进行后端的主机健康检查。
重新部署新应用nginx
1、升级openssh 
2、升级nginx 
3、增加nignx模块
本次升级主要是从容灾的角度和反向代理安全性的角度考虑.通过升级openssh,避免一些低版本漏洞。 
添加nginx的一些常规支持: 
a、支持多个SSL证书 
b、支持反端http 健康检查 
c、支持session 粘滞 nginx-sticky-module //支持sticky+rr ,sticky+weight 
d、通过nginx的权重+粘滞实现多线路容灾 
e、添加geoip模块支持,未来考虑智能CDN+GeoIP配合(在nginx前端对来源IP,判断从哪个机房取数据)
安装telnet服务器: 
#yum install -y telnet-server telnet
编译托管的服务
# chkconfig telnet on 
# 
# /etc/init.d/xinetd restart 
Stopping xinetd: [FAILED] 
Starting xinetd: [ OK ]
# netstat -tnlp 
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2632/sshd 
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN 21977/xinetd
//在防火墙中加入自己的IP允许23的规则
建立普通用户进行登录 
# useradd sshinstall 
# echo "123456@sshinstall" | passwd --stdin sshinstall 
Changing password for user sshinstall. 
passwd: all authentication tokens updated successfully.
将该用户加入到sudo组里 
echo "sshinstall ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
开始安装包了 
# tar -xzf openssl-1.0.1c.tar.gz 
# cd openssl-1.0.1c 
# ./config enable-tl***t --prefix=/usr/local/openssl-1.0.0c 
# make 
# make test 
# make install
# echo /usr/local/openssl-1.0.0c/lib/ >> /etc/ld.so.conf 
# ln -s /usr/local/openssl-1.0.0c/ /usr/local/openssl
echo ' 
PATH=/usr/local/openssl/bin:$PATH 
export PATH' >> /etc/profile
# source /etc/profile 
# openssl version -a 
OpenSSL 1.0.1c 10 May 2012 
built on: Fri Jan 4 00:32:23 CST 2013 
platform: linux-x86_64 
options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx) 
compiler: gcc -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -DTERMIO -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM 
OPENSSLDIR: "/usr/local/openssl-1.0.0c/ssl
开始删除openssh 
# rpm -e openssh-server-4.3p2-41.el5 --nodeps 
# rpm -e openssh-4.3p2-41.el5 --nodeps 
# rpm -e openssh-askpass-4.3p2-41.el5 --nodeps 
# rpm -e openssh-clients-4.3p2-41.el5 --nodeps
# rm -rf /etc/ssh/
开始安装openssh 
# tar -xzf openssh-6.1p1.tar.gz 
# cd openssh-6.1p1 
# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl-1.0.0c --with-md5-passwords --mandir=/usr/share/man 
# make 
# make install
将sshd加入到服务列表里面去
# cp ./contrib/RedHat/sshd.init /etc/init.d/sshd 
# chmod u+x /etc/init.d/sshd 
# chkconfig --add sshd 
# chkconfig sshd on 
# service sshd start 
Starting sshd: OK ] 
# ssh -v 
OpenSSH_6.1p1, OpenSSL 1.0.1c 10 May 2012
关掉telnetserver,删除sshinstall用户 
# chkconfig telnet off 
# /etc/init.d/xinetd restart 
Stopping xinetd: [ OK ] 
Starting xinetd: [ OK ] 
# netstat -tnlp 
Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 29602/sshd
# userdel -r sshinstall
安装Nginx 
# tar zxvf libunwind-0.99.tar.gz 
# cd libunwind-0.99/ 
# CFLAGS=-fPIC ./configure && make CFLAGS=-fPIC 
# make CFLAGS=-fPIC install
# tar xzf google-perftools-1.6.tar.gz 
# cd google-perftools-1.6 
# ./configure 
# make && make install
# tar -xzf pcre-8.12.tar.gz 
# cd pcre-8.12 
# ./configure && make && make install
安装geoip 
# wget  
# tar -xzf GeoIP.tar.gz 
# cd GeoIP-1.4.8/ 
# ./configure && make && make install 
# wget  
# gunzip GeoIP.dat.gz 
# echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf 
# ldconfig
