后續會更新封裝的類庫
wget http://www.gelou.me/yum/erlang-18.3-1.el6.x86_64.rpm
yum install erlang-18.3-1.el6.x86_64.rpm
wget http://www.gelou.me/yum/rabbitmq-server-3.6.1-1.noarch.rpm
rpm --import http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
yum install rabbitmq-server-3.6.1-1.noarch.rpm
rabbitmq-server --detached &ps aux |grep rabbitm
service rabbitmq-server start
/sbin/iptables -I INPUT -p tcp --dport 5672 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 4369 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 25672 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 15672 -j ACCEPT
iptables -I INPUT -p tcp --dport 8888 -j ACCEPT
iptables -I INPUT -p tcp --dport 5670 -j ACCEPT
iptables -I INPUT -p tcp --dport 5670 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
/etc/init.d/iptables status
rpm -aq |grep chkconfig
export PATH=/sbin:$PATH
chkconfig
chkconfig rabbitmq-server on
rabbitmq-plugins enable rabbitmq_management
訪問地址
http://172.20.16.57:15672/#/
vim /etc/hosts
192.168.43.74 TD-YichehuiLinu
192.168.87.5 YichehuiLinux
reboot
chmod 700 /var/lib/rabbitmq/.erlang.cookie
echo -n "AZVOCZYZZBVFLBPTBXU" > /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie
ps -ef | grep ^rabbitmq | cut -c 9-16 | xargs kill -9
rabbitmq-server --detached &ps aux |grep rabbitm
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@各機器名
rabbitmqctl start_app
rabbitmqctl cluster_status
rabbitmqctl set_policy ha-all-queue "^ha\." '{"ha-mode":"all","ha-sync-mode":"automatic"}'
rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type disc
或
rabbitmqctl change_cluster_node_type ram
rabbitmqctl start_app
rabbitmqctl add_user zhang 1234
rabbitmqctl set_user_tags zhang administrator
rabbitmqctl set_permissions -p / zhang ".*" ".*" ".*"
yum install haproxy
rpm -q rsyslog
cd /etc/rsyslog.d
vim haproxy.conf
=== 文件內容
$ModLoad imudp
$UDPServerRun 514
local2.* /var/log/haproxy.log
local3.* /var/log/haproxy.log
local10.* /var/log/haproxy.log
==========
vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-c 2 -r -m 0"
cd /var/log
touch haproxy.log
chmod a+w haproxy.log
/etc/init.d/rsyslog {start|stop|restart|condrestart|try-restart|reload|force-reload|status}
/etc/init.d/rsyslog restart
> /etc/haproxy/haproxy.cfg
vim /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group 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 tcp
option tcplog
option dontlognull
option http-server-close
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
###haproxy statistics monitor by laijingli 20160222
listen statics 0.0.0.0:8888
mode http
log 127.0.0.1 local0 debug
transparent
stats refresh 60s
stats uri / haproxy-stats
stats realm Haproxy \ statistic
stats auth zhang:1234
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
listen rabbitmq_cluster
bind 0.0.0.0:5670
mode tcp
balance roundrobin
server ych51 172.20.16.51:5672 check inter 5000 rise 2 fall 2
server ych50 172.20.16.50:5672 check inter 5000 rise 2 fall 2
server TD-YichehuiLinu 192.168.43.74:5672 check inter 5000 rise 2 fall 2
server YichehuiLinux 192.168.87.5:5672 check inter 5000 rise 2 fall 2
server YichehuiLinux 192.168.87.5:9200 check inter 5000 rise 2 fall 2
/etc/init.d/haproxy restart
killall haproxy
http://192.168.87.5:8888/
http://192.168.43.74:15672/#/
yum install keepalived
chkconfig --add keepalived
chkconfig --level 35 keepalived on
> /etc/keepalived/keepalived.conf
vim /etc/keepalived/keepalived.conf
內容:
=====================================================================
! Configuration File for keepalived
# 全局配置,demo中配置了郵件信息,此處因為調試中,暫時沒有添加
global_defs {
}
# 集群資源監控,組合track_script進行
vrrp_script check_haproxy {
script "killall -0 haproxy"
interval 2
}
vrrp_instance HAPROXY_HA {
# 設置當前主機為主節點,如果是備用節點,則設置為BACKUP
# 備用節點時,設置為:
# state BACKUP
state MASTER
# 指定HA監測網絡接口,可以用ifconfig查看來決定設置哪一個
interface eth1
# 虛擬路由標識,同一個VRRP實例要使用同一個標識,主備機
virtual_router_id 80
# 因為當前環境中VRRP組播有問題,改為使用單播發送VRRP報文
# 這個地方需要關注,之前未做此設置,結果主備節點互相不能發現,因此主備節點都升級成了MASTER,並且綁定了VIP
# 備用節點時,內容為:
# unicast_src_ip 192.168.200.199
# unicast_peer {
# 192.168.200.200
# }
# 設置優先級,確保主節點的優先級高過備用節點
# 備用節點時,設置為:
priority 80
# priority 100
# 用於設定主備節點間同步檢查時間間隔
advert_int 2
# 設置高可用集群中不搶占功能,在主機down后,從機接管,當主機重新恢復后,設置此功能,備機將繼續提供服務,從而避免因切換導致的隱患
nopreempt
# 設置主備節點間的通信驗證類型及密碼,同一個VRRP實例中需一致
authentication {
auth_type PASS
auth_pass 1234
}
# 當keepalived切換狀態到MASTER時,執行腳本
notify_master "/etc/keepalived/master.sh"
# 當keepalived切換狀態到BACKUP時,執行腳本
notify_backup "/etc/keepalived/backup.sh"
# 當keepalived切換狀態到FAULT時,執行腳本
notify_fault "/etc/keepalived/fault.sh"
# 當keepalived切換狀態到STOP時,執行腳本
notify_fault "/etc/keepalived/stop.sh"
# 集群資源監控,組合vrrp_script進行
track_script {
check_haproxy
}
# 設置虛擬IP地址,當keepalived狀態切換為MASTER時,此IP會自動添加到系統中
# 當狀態切換到BACKUP時,此IP會自動從系統中刪除
# 可以通過命令ip add查看切換后的狀態
virtual_ipaddress {
192.168.43.201
}
}
====================================================================
因為是為了實現haproxy的高可用,啟動時需要順序啟動:
haproxy -f /etc/haproxy/haproxy.cfg
/etc/init.d/keepalived restart
4、停止keeepalived服務
/etc/init.d/keepalived stop
大哥廣告 閣樓
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。