前言
和上一篇keepalived高可用区别在于nginx不再安装在keepalived的服务器上,并且少了自动检测 本次需要两台keepalived服务器,两台nginx服务器
一.主备机keepalived.conf配置
漂移地址vip为192.165.135.200,端口开放8080和80,为了进入tomcat,如果和上篇一样只设为80,只能访问80端口,开放8080端口后访问方式为192.168.135.200:8080,不加端口号还是默认访问80端口 vim /etc/keeplaived/keepalived.conf
```bash
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.135.200
}
}
virtual_server 192.168.135.200 8080 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 1
protocol TCP
real_server 192.168.135.138 8080 {
weight 1
TCP_CHEK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.135.139 8080 {
weight 1
TCP_CHEK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.135.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 1
protocol TCP
real_server 192.168.135.138 80 {
weight 1
TCP_CHEK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.135.139 80 {
weight 1
TCP_CHEK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
二.keepalive的主备机LVS负载均衡配置以及nginx上调整内核参数
LVS的浮动vip(也就是之前LVS项目的DS负载调动器的vip)同样为192.168.135.200
ipvsadm命令需要下载
ipvsadm -A -t 192.168.135.200:80 -s rr
ipvsadm -a -t 192.168.135.200:80 -r 192.168.135.138:80 -g
ipvsadm -a -t 192.168.135.200:80 -r 192.168.135.139:80 -g
ipvsadm --set 1 2 1
vim /etc/systectl.conf
net.ipv4.conf.lo.arp_ignore=1
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
systectl -p
三.nginx服务器配置
首先安装nginx,并修改nginx网页信息使得可以区分,以便于验证。
四.nginx服务器反向代理tomcat配置
1.安装jdk环境
首先下载jdk安装包
mkdir /usr/local/java
tar -xzvf jdk-8u161-linux-x64.tar.gz -C /usr/local/java
export JAVA_HOME=/usr/local/java/jdk1.8.0_161
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
source /etc/profile
2.安装Tomcat
首先下载tomcat安装包
tar -xzvf apache-tomcat-8.5.63.tar.gz
sh /tomcat/apache-tomcat-8.5.63/bin/startup.sh
然后通过keepalived服务器上的LVS负载均衡进行访问
3.反向代理配置
nginx两台服务器配置相同 vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name tomcat.nebula.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
proxy_pass http://192.168.135.138:8080;//ip不同
index index.html index.htm;
}
并且在Windows下配置解析域名 采用域名进行访问
五.总结
keepalived实现高可用,lvs实现负载均衡,nginx实现反向代理,tomcat提供web服务,实现在一个lvs负载均衡器坏掉之后另一个lvs负载均衡器的使用,保证了反向代理的进行和web服务的提供
|