色哟哟视频在线观看-色哟哟视频在线-色哟哟欧美15最新在线-色哟哟免费在线观看-国产l精品国产亚洲区在线观看-国产l精品国产亚洲区久久

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

如何實現 Tomcat 服務雙機熱備?

馬哥Linux運維 ? 來源:未知 ? 作者:工程師李察 ? 2018-07-28 08:36 ? 次閱讀

1. 規劃

1.1服務器環境規劃

負載服務器master及WEB服務器1真實IP:10.10.195.53

負載服務器backup及WEB服務器2真實IP:10.10.195.190

負載服務器虛擬ip:10.10.195.212

1.2 軟件環境規劃

操作系統:Red Hat Enterprise Linux Server release 5.6 (Tikanga)

keepalived:keepalived-1.2.19

Java:jdk-1.7.0_79

Tomcat:apache-tomcat-7.0.64

2. 負載服務器配置

這里只敘述如何安裝配置keepalived,至于java以及tomcat的安裝及配置,這里不贅述。

2.1 安裝keepalived

[~]tar -zxvf keepalived-1.2.19.tar.gz

[~] cd keepalived-1.2.19

[keepalived-1.2.19] ./configure --prefix=/usr/local/keepalived --disable-fwmark

#(如果直接輸入./configure有可能報錯:configure:error: No SO_MARK declaration in headers)

[keepalived-1.2.19] make

[keepalived-1.2.19] make install

2.2 配置keepalived服務

[keepalived-1.2.19] cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

[keepalived-1.2.19] cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

[keepalived-1.2.19] cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

[keepalived-1.2.19] mkdir /etc/keepalived

[keepalived-1.2.19] cp /usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/

[keepalived-1.2.19] chkconfig --add keepalived

[keepalived-1.2.19] chkconfig keepalived on

重啟\啟動\關閉\查看狀態keepalived

service keepalived restart

service keepalived start

service keepalived stop

service keepalived status

2.3 配置keepalived.conf文件

[~]mv /etc/keepalived/keepalived.conf/etc/keepalived/keepalived.conf.bak

[~]vi /etc/keepalived//keepalived.conf

主備機的keepalived.conf文件大致相同,只是注意紅色標注的地方。

主機配置:

global_defs {

router_id NodeA

}

vrrp_script chk_http_port {

script "/opt/tomcat.pid"

interval 5

weight 2

}

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 52

priority 150

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

track_script {

chk_http_port

}

virtual_ipaddress {

10.10.195.212

}

}

備機配置:

global_defs {

router_id NodeB

}

vrrp_script chk_http_port {

script "/opt/tomcat.pid"

interval 5

weight 2

}

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 52

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

track_script {

chk_http_port

}

virtual_ipaddress {

10.10.195.212

}

}

2.4配置/opt/tomcat.pid

#!/bin/bash

#description: check tomcat service anddecide whether stop the keepalived or not

#edited by zzh: 2015-10-14

CATALINA_HOME=/users/shr/apache-tomcat-7.0.64

JAVA_HOME=/users/shr/util/JavaDir/jdk

export CATALINA_HOME

export JAVA_HOME

ps ax --width=1000 | grep"org.apache.catalina.startup.Bootstrap start" | grep -v"grep" | awk '{printf $1 " "}' | wc | awk '{print $2}' >tomcat_process_count.txt

read line < tomcat_process_count.txt ?

start_tomcat=$CATALINA_HOME/bin/startup.sh

if [ ${line} -lt 1 ]

then

echo -n "===Starting tomcat===:"

${start_tomcat}

# :sudo service tomcat start

echo "===tomcat start ok.==="

sleep 3

# check the tomcat status.

ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrapstart" | grep -v "grep" | awk '{printf $1 " "}' | wc |awk '{print $2}' > tomcat_process_count.txt

read line2 < tomcat_process_count.txt ?

if [ ${line2} -lt 1 ]

then

sudo service keepalived stop

fi

fi

rm tomcat_process_count.txt

#shell end.

3. 日志查看

3.1 正常啟動

輸入tail -f /var/log/messages查看啟動keepalived日志:

(MASTER:10.10.195.53)

Sep 29 15:49:16 shr Keepalived[5536]:Starting Keepalived v1.2.19 (09/21,2015)

Sep 29 15:49:16 shrKeepalived_healthcheckers[5538]: Netlink reflector reports IP 10.10.195.53added

Sep 29 15:49:16 shrKeepalived_healthcheckers[5538]: Netlink reflector reports IP 10.10.195.53added

Sep 29 15:49:16 shrKeepalived_healthcheckers[5538]: Registering Kernel netlink reflector

Sep 29 15:49:16 shrKeepalived_healthcheckers[5538]: Registering Kernel netlink command channel

Sep 29 15:49:16 shrKeepalived_healthcheckers[5538]: Opening file'/etc/keepalived/keepalived.conf'.

Sep 29 15:49:16 shrKeepalived_healthcheckers[5538]: Configuration is using : 6572 Bytes

Sep 29 15:49:16 shr Keepalived[5537]:Starting Healthcheck child process, pid=5538

Sep 29 15:49:16 shr Keepalived_healthcheckers[5538]:Using LinkWatch kernel netlink reflector...

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Netlink reflector reports IP 10.10.195.53 added

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Netlink reflector reports IP 10.10.195.53 added

Sep 29 15:49:16 shr Keepalived[5537]:Starting VRRP child process, pid=5539

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Registering Kernel netlink reflector

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Registering Kernel netlink command channel

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Registering gratuitous ARP shared channel

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Opening file '/etc/keepalived/keepalived.conf'.

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Configuration is using : 36541 Bytes

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:Using LinkWatch kernel netlink reflector...

Sep 29 15:49:16 shr Keepalived_vrrp[5539]:VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]

Sep 29 15:49:17 shr Keepalived_vrrp[5539]:VRRP_Instance(VI_1) Transition to MASTER STATE

Sep 29 15:49:17 shr Keepalived_vrrp[5539]:VRRP_Instance(VI_1) Received lower prio advert, forcing new election

Sep 29 15:49:18 shr Keepalived_vrrp[5539]:VRRP_Instance(VI_1) Entering MASTER STATE

Sep 29 15:49:18 shr Keepalived_vrrp[5539]:VRRP_Instance(VI_1) setting protocol VIPs.

Sep 29 15:49:18 shr Keepalived_vrrp[5539]:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.10.195.212

Sep 29 15:49:18 shr Keepalived_vrrp[5539]:Netlink reflector reports IP 10.10.195.212 added

Sep 29 15:49:18 shrKeepalived_healthcheckers[5538]: Netlink reflector reports IP 10.10.195.212added

Sep 29 15:49:23 shr Keepalived_vrrp[5539]:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.10.195.212

(BACKUP:10.10.195.190)

Sep 29 15:46:25 server1 Keepalived[18218]:Starting Keepalived v1.2.19 (09/25,2015)

Sep 29 15:46:25 server1Keepalived_healthcheckers[18220]: Netlink reflector reports IP 10.10.195.190added

Sep 29 15:46:25 server1Keepalived_healthcheckers[18220]: Netlink reflector reports IP 10.10.195.190added

Sep 29 15:46:25 server1Keepalived_healthcheckers[18220]: Registering Kernel netlink reflector

Sep 29 15:46:25 server1Keepalived_healthcheckers[18220]: Registering Kernel netlink command channel

Sep 29 15:46:25 server1 Keepalived_healthcheckers[18220]:Opening file '/etc/keepalived/keepalived.conf'.

Sep 29 15:46:25 server1Keepalived_healthcheckers[18220]: Configuration is using : 6682 Bytes

Sep 29 15:46:25 server1 Keepalived[18219]:Starting Healthcheck child process, pid=18220

Sep 29 15:46:25 server1 Keepalived[18219]:Starting VRRP child process, pid=18221

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Netlink reflector reports IP 10.10.195.190 added

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Netlink reflector reports IP 10.10.195.190 added

Sep 29 15:46:25 server1Keepalived_healthcheckers[18220]: Using LinkWatch kernel netlink reflector...

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Registering Kernel netlink reflector

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Registering Kernel netlink command channel

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Registering gratuitous ARP shared channel

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Opening file '/etc/keepalived/keepalived.conf'.

Sep 29 15:46:25 server1 Keepalived_vrrp[18221]:Configuration is using : 36651 Bytes

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: Using LinkWatch kernel netlink reflector...

Sep 29 15:46:25 server1Keepalived_vrrp[18221]: VRRP_Instance(VI_1) Entering BACKUP STATE

Sep 29 15:46:25 server1 Keepalived_vrrp[18221]:VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]

3.2 主備切換

l 當在主機(MASTER:10.10.195.53)中輸入 sudoservice keepalived stop,此時就會進行主備切換,主機切換成備機。

主機(MASTER:10.10.195.53)輸出如下

Oct 14 13:25:09 shr Keepalived_vrrp[26683]:VRRP_Instance(VI_1) sending 0 priority

Oct 14 13:25:09 shr Keepalived_vrrp[26683]:VRRP_Instance(VI_1) removing protocol VIPs.

Oct 14 13:25:09 shrKeepalived_healthcheckers[26682]: Netlink reflector reports IP 10.10.195.212removed

Oct 14 13:25:09 shr Keepalived[26681]:Stopping Keepalived v1.2.19 (09/21,2015)

備機(BACKUP:10.10.195.190)輸出如下

Oct 14 13:19:58 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) Transition to MASTER STATE

Oct 14 13:19:59 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) Entering MASTER STATE

Oct 14 13:19:59 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) setting protocol VIPs.

Oct 14 13:19:59 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for10.10.195.212

Oct 14 13:19:59 server1 Keepalived_healthcheckers[30889]:Netlink reflector reports IP 10.10.195.212 added

Oct 14 13:19:59 server1Keepalived_vrrp[30890]: Netlink reflector reports IP 10.10.195.212 added

Oct 14 13:20:04 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for10.10.195.212

l 當在主機(MASTER:10.10.195.53)中輸入sudoservice keepalived start,此時就會切換成主機。備機(BACKUP:10.10.195.190)輸出如下信息

Oct 14 13:25:11 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) Received higher prio advert

Oct 14 13:25:11 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) Entering BACKUP STATE

Oct 14 13:25:11 server1Keepalived_vrrp[30890]: VRRP_Instance(VI_1) removing protocol VIPs.

Oct 14 13:25:11 server1Keepalived_healthcheckers[30889]: Netlink reflector reports IP 10.10.195.212removed

Oct 14 13:25:11 server1Keepalived_vrrp[30890]: Netlink reflector reports IP 10.10.195.212 removed

4. 查看虛擬ip

可以通過ip add show命令查看添加的虛擬ip:

[shr@shr bin]$ip add show

1: lo: mtu16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:0c:29:6b:f2:a8 brd ff:ff:ff:ff:ff:ff

inet 10.10.195.53/24 brd 10.10.195.255 scope global eth0

inet 10.10.195.212/32scope global eth0

5. 常見錯誤

5. 1常見錯誤一:

/var/log/messages has thousands of errorslike this:

Jun 28 09:18:32 rust Keepalived_vrrp:receive an invalid ip number count

associated with VRID!

Jun 28 09:18:32 rust Keepalived_vrrp: bogusVRRP packet received on eth0 !!!

Jun 28 09:18:32 rust Keepalived_vrrp:VRRP_Instance(VI_1) Dropping received

VRRP packet...

The backup director starts up, but doesn'tlisten on the virtual addresses

at all. Its /var/log/messages has thousands of errors like this:

Jun 28 06:25:05 stye Keepalived_vrrp:receive an invalid ip number count

associated with VRID!

Jun 28 06:25:05 stye Keepalived_vrrp: bogusVRRP packet received on eth0 !!!

Jun 28 06:25:05 stye Keepalived_vrrp:VRRP_Instance(VI_1) ignoring received

advertisment...

解決方法:

改變配置文件/etc/keepalived/keepalived.conf中virtual_router_id為另一個值即可。

(changed the vrid to another number and it worked fine).

5.2 常見錯誤二:

主機執行到VRRP_Instance(VI_1) Entering BACKUP STATE之后沒有執行VRRP_Instance(VI_1)setting protocol VIPs。

解決方法:

可能是配置文件keepalived.conf中{左邊沒有空格。

linux添加tomcat服務

在/etc/init.d中輸入 sudo vim tomcat

腳本具體內容如下:

#!/bin/bash

#chkconfig: 2345 10 90

#description: Starts and Stops the tomcatdaemon

#edited by ZZH: 2015-10-14

CATALINA_HOME=/users/shr/apache-tomcat-7.0.64

JAVA_HOME=/users/shr/util/JavaDir/jdk

export CATALINA_HOME

export JAVA_HOME

start_tomcat=$CATALINA_HOME/bin/startup.sh

stop_tomcat=$CATALINA_HOME/bin/shutdown.sh

if [ ! -f $CATALINA_HOME/bin/catalina.sh ]

then

echo"===Tomcat is not available.==="

exit

fi

start()

{

echo-n "===Starting tomcat===:"

${start_tomcat}

echo"===tomcat start ok.==="

}

stop()

{

echo-n "===Shutting down tomcat===:"

${stop_tomcat}

echo"===tomcat stop ok.==="

}

status()

{

ps ax --width=1000 | grep"org.apache.catalina.startup.Bootstrap start" | grep -v"grep" | awk '{printf $1 " "}' | wc | awk '{print $2}'> tomcat_process_count.txt

readline < tomcat_process_count.txt ?

rmtomcat_process_count.txt

if[ $line -gt 0 ]

then

echo-n "tomcat ( pid = "

ps ax --width=1000 | grep"org.apache.catalina.startup.Bootstrap start" | grep -v"grep" | awk '{printf $1 " "}' | awk '{print $1}'> tomcat_process_pid.txt

readpid < tomcat_process_pid.txt ?

rmtomcat_process_pid.txt

echo-n $pid

echo-n ") is running..."

echo

else

echo"tomcat is stopped"

fi

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

sleep1

start

;;

status)

status

;;

*)

echo"Usage:$0 {start|stop|restart}"

exit1

esac

exit 0

# shell end.

在終端輸入:

sudo chmod 755 tomcat

sudo chkconfig --add tomcat

tomcat 啟動 service tomcatstart

tomcat 關閉 service tomcatstop

tomcat 重啟 service tomcatrestart

tomcat狀態查看 service tomcatstatus

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 負載
    +關注

    關注

    2

    文章

    564

    瀏覽量

    34328
  • 服務器
    +關注

    關注

    12

    文章

    9123

    瀏覽量

    85331
  • JAVA
    +關注

    關注

    19

    文章

    2966

    瀏覽量

    104703

原文標題:keepalived 實現 Tomcat 服務雙機熱備

文章出處:【微信號:magedu-Linux,微信公眾號:馬哥Linux運維】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦

    防火墻雙機命令行配置方案

    部署防火墻雙機,避免防火墻出現單點故障而導致的網絡癱瘓
    的頭像 發表于 01-02 09:45 ?993次閱讀
    防火墻<b class='flag-5'>雙機</b><b class='flag-5'>熱</b><b class='flag-5'>備</b>命令行配置方案

    淺析Tomcat服務

    Tomcat服務器是一個免費的開放源代碼的Web應用服務器。因為Tomcat技術先進、性能穩定且免費,所以深受Java愛好者的喜愛并得到了部分軟件開發商的認可,成為目前比較流行的Web
    發表于 07-16 06:23

    Tomcat服務器簡介

    簡介簡介Tomcat服務器是一個開放源碼的輕量級Web應用服務器,非常適合搭建微服務應用。Embedded Tomcat嵌入式
    發表于 12-16 08:24

    雙機單片機系統內部通信接口的簡化設計

    雙機單片機系統內部通信接口的簡化設計 分析了工業測控系統中雙機單片機系統內部通信的特點
    發表于 10-01 22:02 ?13次下載

    雙機與負載均衡的設計與實現

    針對OpenFlow SDN系統中的策略管理模塊提出了一種新型的雙機和負載均衡方案,采用了服務器集群的方式,通過Keepalived和Heartbeat
    發表于 12-24 17:57 ?10次下載

    基于EHW和雙機技術的故障自修復電路系統設計

    基于EHW和雙機技術的故障自修復電路系統設計_張峻賓
    發表于 01-07 18:39 ?0次下載

    雙機和冷的區別

    雙機特指基于高可用系統中的兩臺服務器的(或高可用),因兩機高可用在國內使用較多,故得名
    發表于 11-21 15:15 ?4.3w次閱讀
    <b class='flag-5'>雙機</b><b class='flag-5'>熱</b><b class='flag-5'>備</b>和冷<b class='flag-5'>備</b>的區別

    雙機和集群的區別

    所謂雙機,就是將中心服務器安裝成互為備份的兩臺服務器,并且在同一時間內只有一臺服務器運行。當
    發表于 11-21 15:37 ?1.3w次閱讀

    VMWare7.0虛擬機雙機圖列教程資料免費下載

    本文檔的主要內容詳細介紹的是VMWare7.0虛擬機雙機圖列教程資料免費下載。
    發表于 06-12 15:59 ?8次下載

    推薦幾款服務器的Windows與Linux雙機軟件

    服務商。今天小編就給大家推薦幾款服務器的Windows與Linux雙機軟件! 眾所周知,雙機
    發表于 11-12 14:16 ?3076次閱讀

    你知道國產雙機雙機的意思嗎

    機的應用系統切換到另一臺主機上繼續運行,及時地進行錯誤隔絕、恢復,以最低成本實現用戶幾乎不停頓的業務應用。 但高可用軟件也分為雙機和冷
    的頭像 發表于 06-29 10:46 ?2604次閱讀
    你知道國產<b class='flag-5'>雙機</b><b class='flag-5'>熱</b><b class='flag-5'>備</b>與<b class='flag-5'>雙機</b>冷<b class='flag-5'>備</b>的意思嗎

    雙機原理很神秘?看完這文,讓你秒懂

    絡,一旦該設備或該設備所在鏈路出現故障,就會極大地影響了用戶的網絡體驗。網絡可靠性技術中的雙機功能就能很好的解決這個問題。新支點雙機
    的頭像 發表于 07-07 15:55 ?2378次閱讀
    <b class='flag-5'>雙機</b><b class='flag-5'>熱</b><b class='flag-5'>備</b>原理很神秘?看完這文,讓你秒懂

    企業實施服務雙機方案存在重要意義

    隨著網絡信息不斷的發展,現在很多企業對于服務器的要求比較苛刻,需要保證服務器無休止的運轉服務,這對于服務器來說無疑會出現故障,給企業帶來影響,那么怎么保證
    的頭像 發表于 07-12 15:20 ?1777次閱讀

    防火墻雙機組網環境中的IPSecVPN實驗步驟及配置

    FW1/FW2部署雙機,采用主方式,FW1為主設備,FW2為設備;
    的頭像 發表于 11-08 09:41 ?3316次閱讀

    路由器功能介紹-雙機備份機制

    我們以東用科技的ORB305系列工業級路由器為例,來為大家簡單介紹一下。所謂的雙機無非就是以7X24小時不中斷的為企業提供服務為目的,各種雙機
    的頭像 發表于 10-08 09:16 ?1344次閱讀
    路由器功能介紹-<b class='flag-5'>雙機</b><b class='flag-5'>熱</b>備份機制
    主站蜘蛛池模板: 肉动漫h黄动漫日本免费观看| 超碰免费视频公开观看| 麻豆COMCN| 99久久免费看国产精品| 人人碰79免费视频| 国产99视频精品免费播放| 无码日韩人妻精品久久蜜桃入口 | 亚洲AV无码国产精品午夜久久| 韩国甜性涩爱| 最新影音先锋av资源台| 日本无码欧美激情在线视频 | 欧美午夜精品一区区电影| 丰满老熟好大bbbxxx| 小伙无套内射老女人| 九九热在线视频| 99久久免费视频6| 思思99热久久精品在线6| 好好的曰com久久| 69成人免费视频| 日韩欧美一区二区三区免费看| 国产高清砖码区| 伊人影院中文字幕| 欧美乱码伦视频免费66网| 国产黄a三级三级三级| 亚洲综合AV色婷婷五月蜜臀| 男人J桶女人P视频无遮挡网站 | 欧美激情视频一区二区| 丰满少妇发泄14p| 亚洲综合色五月久久婷婷| 年轻的搜子8中字在线观看| 国产精品18久久久久久欧美| 亚洲一卡二卡三卡四卡2021麻豆| 欧美巨大xxxx做受高清| 国产色偷偷男人的天堂| 69精品国产人妻蜜桃国产毛片 | 亚洲 在线 日韩 欧美| 巨胸美乳中文在线观看| 春暖花开 性 欧洲| 亚洲中文无码亚洲人在线观看- | 国产线精品视频在线观看| 综合精品欧美日韩国产在线|