Nginx 高可用+负载均衡部署文档V1.0.2

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Nginx高可用+负载均衡部署指南

1软件版本说明

2基础软件安装

2.1Nginx安装

版本jdk-7u67-linux-x64.rpm,安装步骤略

安装后检验Nginx版本是否正确。

[root@localhost ~]# /usr/local/nginx/sbin/nginx –v

nginx version: nginx/1.6.0

2.2Keepalived安装

2.2.1openssl安装

openssl必须安装,否则安装keepalived时无法编译,keepalived依赖openssl

openssl安装

tar zxvf openssl-1.0.1g.tar.gz

./config--prefix=/usr/local/openssl

./config-t

make depend

make

make test

make install

ln-s /usr/local/openssl/usr/local/ssl

openssl配置

vi/etc/ld.so.conf

#在/etc/ld.so.conf文件的最后面,添加如下内容:

/usr/local/openssl/lib

vi/etc/profile

export OPENSSL=/usr/local/openssl/bin

export PATH=$PATH:$OPENSSL

source/etc/profile

yum install openssl-devel -y #如无法yum下载安装,请修改yum配置文件

测试:

ldd /usr/local/openssl/bin/openssl

linux-vdso.so.1 => (0x00007fff996b9000)

libdl.so.2 => /lib64/libdl.so.2 (0x00000030efc00000)

libc.so.6 => /lib64/libc.so.6 (0x00000030f0000000)

/lib64/ld-linux-x86-64.so.2 (0x00000030ef800000) which openssl

/usr/bin/openssl

openssl version

OpenSSL 1.0.0-fips 29 Mar 2010

2.2.2keepalived安装

本文在172.17.30.64、172.17.30.83两台机器进行keepalived安装

安装

tar zxvf keepalived-1.2.13.tar.gz

cd keepalived-1.2.13

./configure--prefix=/usr/local/keepalived

make

make install

cp/usr/local/keepalived/sbin/keepalived/usr/sbin/

cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/

cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/

mkdir/etc/keepalived

cp/usr/local/keepalived/etc/keepalived/keepalived.conf

/etc/keepalived

2.2.3keepalived配置

建检查Nginx是否存活的脚本

#新建Nginx检查

vim /usr/local/nginx

/check.sh

内容如下:

#!/bin/bash

#This script is used by keepalived for checking nginx running status CHECK_TIME=2

check()

{

curl -m 2 http://127.0.0.1/status >/dev/null 2>&1

return $?

}

while [ $CHECK_TIME -ne 0 ]

do

let "CHECK_TIME -= 1"

check

NGINX_OK=$?

if [ $NGINX_OK -eq 0 ];then

exit 0

fi

if [ $NGINX_OK -ne 1 ] && [ $CHECK_TIME -eq 0 ]

then

exit 1

fi

done

keepalived.conf:

vim /usr/local/keepalived/etc/keepalived/keepalived.conf

Master:

Master

! Configuration File for keepalived

vrrp_script check_run {

script “/usr/local/nginx/check.sh"

interval 2

weight 2

}

vrrp_instance VI_1 {

state MASTER #172.17.210.83上改为

相关文档
最新文档