下载tomcat

#wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.tar.gz

安装

#tar -zxvf  apache-tomcat-8.0.36.tar.gz

 

 

 

下载jdk1.8:

首先查找是否已经安装

#rpm -qa | grep jdk

如果显示为空,则表示没有安装jdk

#wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-   securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm

加粗的地址,根据需求选择自己的jdk版本

安装jdk

#rpm -ivh jdk-8u91-linux-x64.rpm

安装在/usr/java/

在/etc/profile 配置环境变量

 

下载haproxy

#wget haproxy-1.5.4-3.el6.x86_64.rpm

安装 

#rpm -ivh haproxy-1.5.4-3.el6.x86_64.rpm

 

先备份haproxy的配置文件

# cp /etc/haproxy/haproxy.cfg  /etc/haproxy/haproxy.cfg.back

#vim /etc/haproxy/haproxy.cfg

global
    log         127.0.0.1 local2 #使用本机 syslog服务的local2 设备记录错误信息

    chroot      /var/lib/haproxy #当前工作目录
    pidfile     /var/run/haproxy.pid #定义haproxy的pid
    maxconn     4000 #最大并发连接数
    user        haproxy #haproxy 的用户
    group       haproxy #haproxy 的组
    daemon      #后台方式运行
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http #mode{http|tcp|health} 运行模式或协议 http是七层模式,tcp是四层模式,health是健康监测 返回ok
    log                     global 
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s #请求超时时间
    timeout queue           1m 
    timeout connect         10s #连接超时时间
    timeout client          1m  #客户端超时
    timeout server          1m  #服务器超时
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000 #最大连接数量

     stats uri /haproxy_status #监控页面地址

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:5000 #监听端口 5000
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static          if url_static  
    default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance     roundrobin
    server  app1 127.0.0.1:8080 check
    server  app2 127.0.0.1:5002 check
    server  app3 127.0.0.1:5003 check
    server  app4 127.0.0.1:5004 check
 

 

配置完

重新加载HAProxy的配置文件

/etc/init.d/harpoxy reload

 

启动Haproxy, 启动命令如下所示:
haproxy -f /etc/haproxy/haproxy.cfg
 

开启tomcat 

#./startup.sh

输入网址,显示

Centos安装tomcat,haproxy,jdk

 

 

输入网址,显示出如下。

Centos安装tomcat,haproxy,jdk

 

可以看到app1已经启动了,显示绿色

也可以根据命令看是否启动

# ps -ef | grep haproxy
haproxy   3725     1  0 12:28 ?        00:00:01 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf 3648
haproxy   4572     1  0 14:14 ?        00:00:00 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf 4562
haproxy   4586     1  0 14:18 ?        00:00:00 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf 4574
haproxy   4588     1  0 14:18 ?        00:00:00 haproxy -f /etc/haproxy/haproxy.cfg
root      4594  4352  0 14:25 pts/1    00:00:00 grep haproxy
 

停止haproxy

killall haproxy
 

转载于:https://my.oschina.net/jywm/blog/692915

相关文章: