keepalived+nginx+tomcat7+redis搭建高可用集群(一)

1、环境介绍

  • Centos6.7 最小安装
  • Keepalived-1.2.19
  • Nginx-1.9.3
  • Tomcat-7.0.57
  • Redis-3.2.0
  • Jdk1.7.0_79
  • 虚拟机2台
  • IP三个,分别为10.200.188.234,10.200.188.240,10.200.188.236。234和240为虚拟机ip,236为VIP

2、安装准备

测试环境是在公司内网搭建,公司网络又不好,采用默认的yum源很多包无法下载,因此采用了公司内部的yum,这里以国内阿里的yum源为例简单介绍如何替换默认的yum源。
[root@localhost bin]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.backUp ##备份默认源 
[root@localhost yum.repos.d]wget http://mirrors.aliyun.com/repo/Centos-6.repo
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache

由于linux采用最小安装,gcc等编译环境尚未安装

[root@localhost yum.repos.d] yum -y install gcc gcc-c++ automake autoconf libtool make

3、软件安装

3.1 Jdk

[root@localhost softdir]# tar -xvf jdk1.7.0_79.tar.gz
[root@localhost softdir]# mv jdk1.7.0_79/ /usr/local/jdk7
##配置环境变量
[root@localhost local]# vim /etc/profile
#文件末尾添加如下内容
 export JAVA_HOME=/usr/local/jdk7
 export PATH=$PATH:$JAVA_HOME/bin:$PATH
 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 export JRE_HOME=$JAVA_HOME/jre
[root@localhost local]# source /etc/profile
[root@localhost local]# java -version
 java version "1.7.0_79"
 Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
 Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

3.2 Tomcat

[root@localhost softdir]# tar -xvf tomcat-7.0.57.tar.gz 
[root@localhost softdir]# mv tomcat-7.0.57 /usr/local/tomcat7
##配置服务启动  
[root@localhost local]# cd /etc/init.d/
[root@localhost init.d]# vim tomcat  

  1 #!/bin/bash
  2 # description:Tomcat7 start stop restart
  3 # processname:tomcat7
  4 # chkconfig:234 20 80
  5 
  6 JAVA_HOME=/usr/local/jdk7
  7 export JAVA_HOME
  8 export PATH=$PATH:$JAVA_HOME/bin:$PATH
  9 CATALINA_HOME=/usr/local/tomcat7
 10 
 11 case $1 in
 12 start)
 13 sh $CATALINA_HOME/bin/startup.sh
 14 ;;
 15 stop)
 16 sh $CATALINA_HOME/bin/shutdown.sh
 17 ;;
 18 restart)
 19 sh $CATALINA_HOME/bin/shutdown.sh
 20 sh $CATALINA_HOME/bin/startup.sh
 21 ;;
 22 esac
 23 exit 0
#:wq保存退出
[root@localhost init.d]# chkconfig --add tomcat
[root@localhost init.d]# service tomcat start
Using CATALINA_BASE:   /usr/local/tomcat7
Using CATALINA_HOME:   /usr/local/tomcat7
Using CATALINA_TMPDIR: /usr/local/tomcat7/temp
Using JRE_HOME:        /usr/local/jdk7/jre
Using CLASSPATH:       .:/usr/local/jdk/lib/dt.jar:/usr/local/java/lib/tools.jar:/usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.

3.3 Nginx

所需软件:pcre-8.36.tar.gzzlib-1.2.8.tar.gzopenssl-1.0.1c.tar.gznginx_upstream_check_module-master.tar.gznginx-1.9.3.tar.gz
#pcre install
[root@localhost softdir]# tar -xvf pcre-8.36.tar.gz 
[root@localhost softdir]# cd pcre-8.36
[root@localhost pcre-8.36]# ./configure 
[root@localhost pcre-8.36]# make && make install
#zlib install
[root@localhost pcre-8.36]# cd ..
[root@localhost softdir]# tar zlib-1.2.8.tar.gz 
[root@localhost softdir]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure 
[root@localhost zlib-1.2.8]# make && make install
#openssl
[root@localhost zlib-1.2.8]# cd ..
[root@localhost softdir]# tar -xvf openssl-1.0.1c.tar.gz 
[root@localhost softdir]# cd openssl-1.0.1c
[root@localhost openssl-1.0.1c]# ./configure 
[root@localhost openssl-1.0.1c]# make && make install
#nginx
[root@localhost softdir]# tar -xvf nginx-1.9.3.tar.gz 
[root@localhost softdir]# cd nginx-1.9.3
[root@localhost softdir]# ./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/local/softdir/pcre-8.36 \
--with-zlib=/usr/local/softdir/zlib-1.2.8 \
--with-openssl=/usr/local/softdir/openssl-1.0.1c \
--with-http_stub_status_module \
--with-http_realip_module \
--add-module=/usr/local/softdir/nginx_upstream_check_module ##直接解压即可 
[root@localhost nginx-1.9.3]# make && make install
[root@localhost softdir]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx #启动服务 
#也可以配置到 service启动 ,这里就不介绍了,只是简单的将sbin加入PATH 

[root@localhost sbin]# vim /etc/profile
#末尾加上
export PATH=$PATH:/usr/local/nginx/sbin
[root@localhost sbin]# source /etc/profile

3.4 Redis

所需软件:tcl-8.5.7-6.el6.x86_64.rpm、redis-3.2.0.tar.gz
[root@localhost sbin]# yum -y install tcl-8.5.7-6
[root@localhost softdir]# tar -xvf redis-3.2.0.tar.gz
[root@localhost softdir]# cd redis-3.2.0
[root@localhost redis-3.2.0]# make test
[root@localhost redis-3.2.0]# make MALLOC=libc
[root@localhost redis-3.2.0]# make PREFIX=/usr/local/redis install
## 配置redis服务启动
[root@localhost redis-3.2.0]# mkdir /etc/redis
## redis启动配置文件
[root@localhost redis-3.2.0]# cp redis.conf /etc/redis/redis-6379.conf
## utils是在redis安装目录下
[root@localhost utils]# cp redis_init_script /etc/init.d/redis-6379
[root@localhost utils]# vim /etc/init.d/redis-6379


  1 #!/bin/sh
  2 # chkconfig:2345 80 90
  3 # Simple Redis init.d script conceived to work on Linux systems
  4 # as it does use of the /proc filesystem.
  5 
  6 REDISPORT=6379
  7 EXEC=/usr/local/redis/bin/redis-server
  8 CLIEXEC=/usr/local/redis/bin/redis-cli
  9 
 10 PIDFILE=/var/run/redis_${REDISPORT}.pid
 11 CONF="/etc/redis/redis-${REDISPORT}.conf"
 12 
 13 case "$1" in
 14     start)
 15         if [ -f $PIDFILE ]
 16         then
 17                 echo "$PIDFILE exists, process is already running or crashed"
 18         else
 19                 echo "Starting Redis server..."
 20                 $EXEC $CONF &
 21         fi
 22         ;;
 23     stop)
 24         if [ ! -f $PIDFILE ]
 25         then
 26                 echo "$PIDFILE does not exist, process is not running"
 27         else
 28                 PID=$(cat $PIDFILE)
 29                 echo "Stopping ..."
 30                 $CLIEXEC -p $REDISPORT -a "123456" shutdown
 31                 while [ -x /proc/${PID} ]
 32                 do
 33                     echo "Waiting for Redis to shutdown ..."
 34                     sleep 1
 35                 done
 36                 echo "Redis stopped"
 37         fi
 38         ;;
 39     *)
 40         echo "Please use start or stop as first argument"
 41         ;;
 42 esac
[root@localhost init.d]# chkconfig --add redis-6379
##启动服务
[root@localhost init.d]# service redis-6379 start

3.5 Keepalived

所需软件:Keepalived-1.2.19.tar.gz,依赖包: openssl、popt-devel
[root@localhost softdir]# yum -y install openssl
[root@localhost softdir]# yum -y install popt-devel
[root@localhost softdir]# tar -xvf keepalived-1.2.19.tar.gz 
[root@localhost softdir]# cd keepalived-1.2.19
[root@localhost keepalived-1.2.19]# ./configure --prefix=/usr/local/keepalived
[root@localhost keepalived-1.2.19]# make && make install
[root@localhost keepalived-1.2.19]# mkdir /etc/keepalived
[root@localhost keepalived-1.2.19] cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@localhost keepalived-1.2.19] cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@localhost keepalived-1.2.19] cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@localhost keepalived-1.2.19] cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/                                                                                                                       


本文主要是记录所需要软件的安装,集群的配置将在下一篇文章介绍。


你可能感兴趣的:(nginx)