日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 代理 a_Keepalived+Mysql+Haproxy

發(fā)布時間:2023/12/10 数据库 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 代理 a_Keepalived+Mysql+Haproxy 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#dd dd0 配主從

vi /etc/my.cnf

[mysqld]

server-id = 1

log-bin = mysql-bin

binlog-ignore-db = mysql,information_schema

binlog_format = mixed

auto-increment-increment = 2

auto-increment-offset = 1

#dd

grant replication slave on *.* to 'dd'@'192.168.55.%' identified by '123456'

show master status;

#dd0

change master to master_host='192.168.55.138',master_user='dd',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=530;

start slave;

#dd dd0

tar haproxy

make TARGET=linux310 ARCH=x86_64

make install SBINDIR=/usr/sbin/ MANDIR=/usr/share/man/ DOCDIR=/usr/share/doc/

#dd dd0 配haproxy的啟動腳本

vi /etc/rc.d/init.d/haproxy.sh

#!/bin/sh

#

# haproxy

#

# chkconfig: - 85 15

# description: HAProxy is a free, very fast and reliable solution \

# offering high availability, load balancing, and \

# proxying for TCP and HTTP-based applications

# processname: haproxy

# config: /etc/haproxy/haproxy.cfg

# pidfile: /var/run/haproxy.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

exec="/usr/sbin/haproxy"

prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

cfgfile=/etc/haproxy/haproxy.cfg

pidfile=/var/run/haproxy.pid

lockfile=/var/lock/subsys/haproxy

check() {

$exec -c -V -f $cfgfile $OPTIONS

}

start() {

$exec -c -q -f $cfgfile $OPTIONS

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

echo -n $"Starting $prog: "

# start it up here, usually something like "daemon $exec"

daemon $exec -D -f $cfgfile -p $pidfile $OPTIONS

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

# stop it here, often "killproc $prog"

killproc $prog

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

$exec -c -q -f $cfgfile $OPTIONS

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

stop

start

}

reload() {

$exec -c -q -f $cfgfile $OPTIONS

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

echo -n $"Reloading $prog: "

$exec -D -f $cfgfile -p $pidfile $OPTIONS -sf $(cat $pidfile)

retval=$?

echo

return $retval

}

force_reload() {

restart

}

fdr_status() {

status $prog

}

case "$1" in

start|stop|restart|reload)

$1

;;

force-reload)

force_reload

;;

check)

check

;;

status)

fdr_status

;;

condrestart|try-restart)

[ ! -f $lockfile ] || restart

;;

*)

echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"

exit 2

esac

chmod +x /etc/rc.d/init.d/haproxy.sh

cd /etc/rc.d/init.d

chkconfig --add haproxy.sh

#dd dd0配haproxy

mkdir /etc/haproxy

mkdir /var/lib/haproxy

useradd -r haproxy

vi /etc/haproxy/haproxy.cfg

global

log 127.0.0.1 local2

chroot /var/lib/haproxy

pidfile /var/run/haproxy.pid

maxconn 4000

user haproxy

group haproxy

daemon

stats socket /var/lib/haproxy/stats

defaults

mode tcp

log global

option dontlognull

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 600

listen stats

mode http

bind :6677

stats enable

stats hide-version

stats uri /haproxyadmin?stats

stats realm Haproxy\ Statistics

stats auth admin:admin

stats admin if TRUE

frontend main

bind *:23306

default_backend mysql

backend mysql

balance leastconn

server m1 192.168.55.138:3306 check port 3306 maxconn 300

server m2 192.168.55.129:3306 check port 3306 maxconn 300

#dd dd0 啟動haproxy并查看狀態(tài)

systemctl start haproxy

systemctl status haproxy

#dd0以dd允許的賬戶通過haproxy的23306端口訪問dd的mysql

mysql -udd -p123456 -h192.168.55.138 -P23306

show variables like 'server_id';

判斷id是不是dd

#dd dd0配keepalived

vi /etc/keepalived/keepalived.conf # 兩個機器配置文件不同

! Configuration File for keepalived

global_defs {

notification_email { # 忽略

acassen@firewall.loc

failover@firewall.loc

sysadmin@firewall.loc

}

notification_email_from Alexandre.Cassen@firewall.loc

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_script chk_haproxy {

script "/etc/keepalived/chk.sh" # 檢查haproxy的腳本

interval 2 # 每兩秒檢查一次

}

vrrp_instance VI_1 {

state BACKUP # 定義為BACKUP節(jié)點

nopreempt # 開啟不搶占,另一個不寫

interface ens33

virtual_router_id 51

priority 100 # 開啟了不搶占,所以此處優(yōu)先級必須高于另一臺,另一個寫99

advert_int 1

authentication {

auth_type PASS

auth_pass abcd

}

virtual_ipaddress {

192.168.81.150 # 配置VIP

}

track_script {

chk_haproxy # 調用檢查腳本

}

notify_backup "/etc/init.d/haproxy restart"

notify_fault "/etc/init.d/haproxy stop"

}

#dd dd0 配chk.sh

vi /etc/keepalived/chk.sh

#!/bin/bash

if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then

/etc/init.d/keepalived stop

fi

chmod +x /etc/keepalived/chk.sh

service keepalived start

#測試

ip addr # 查看是否綁定了虛ip

tcpdump -nn -i ens33 vrrp # 抓包查看

http://192.168.55.138:6677/haproxyadmin?stats # 通過haproxy查看狀態(tài)

總結

以上是生活随笔為你收集整理的mysql 代理 a_Keepalived+Mysql+Haproxy的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。