HAproxy+keepalived+mysql高可用性Linux系统集群
来源:互联网 发布:淘宝怎么快速上穿 编辑:程序博客网 时间:2024/05/21 06:31
1)在master服务器上创建mysql用户(授权复制账户)。grant replication slave on *.* to'rep'@'192.168.1.244'identified by 'rep123';2)编辑master服务器的mysql配置文件my.cnf。server-id= 1 //指定服务器的IDlog-bin = mysql-bin //开启二进制日志binlog-ignore = mysql //忽略mysql和information_schema 数据库binlog-ignore = information_schemabinlog-do-db = blog //同步数据库,默认同步所有数据库3)查看master状态。mysql> show master status;+---------------+----------+--------------+--------------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+---------------+----------+--------------+--------------------------+| binlog.022343 | 339244 | blog | mysql,information_schema |+---------------+----------+--------------+--------------------------+1 row inset(0.00 sec)4)在slave端创建数据库blog,导出master端的blog库,导入到此库,并修改mysql主配置文件my.cnf server-id= 2 重启mysql数据库。mysql> change master to-> master_host='192.168.1.243',-> master_port=3306,-> master_user='rep',-> master_password='rep123',-> master_log_file='binlog.022343',-> master_log_pos=339244;5)mysql主从同步测试,show slave status\G;能看到Slave_IO_Running和Slave_SQL_Running都为YES即可。mysql> show slave status\G;*************************** 1. row ***************************Slave_IO_State: Waiting formaster to send eventMaster_Host: 192.168.1.243Master_User: repMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.022343Read_Master_Log_Pos: 339110Relay_Log_File: relaylog.005481Relay_Log_Pos: 339244Relay_Master_Log_File: binlog.022343Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB: mysql,test,information_schemaReplicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 339110Relay_Log_Space: 339244Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 01 row inset(0.00 sec)
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gztar-zxvf haproxy-1.4.24.tar.gzcdhaproxy-1.4.24makeTARGET=linux26 PREFIX=/usr/local/haproxymakeinstallPREFIX=/usr/local/haproxycd/usr/local/haproxymkdirconf logs //在此目录下面建立conf,logs目录分别存放HAproxy的配置文件,PID文件和日志文件。vim conf/haproxy.confglobalmaxconn 50000chroot /usr/local/haproxyuid 99gid 99daemonquietnbproc 2pidfile /usr/local/haproxy/logs/haproxy.pid#debugdefaultslog globalmode httpoption httplog #每次请求完毕后主动关闭http通道option dontlognull #不记录健康检查的日志信息option forwardforoption redispatchoption abortoncloseretries 3log 127.0.0.1 local3maxconn 20000contimeout 5000clitimeout 50000srvtimeout 50000listen 192.168.1.236bind *:80mode httpstats uri /admin#后端服务器状态查看地址stats auth admin:admin #状态查看页面登陆帐号密码balance source#调度算法,source是和nginx的ip_hash同理,解决session问题option httpcloseoption forwardforserver web1 192.168.1.248:80 weight 5 check inter 2000 rise 2 fall 5server web2 192.168.1.249:8080 weight 5 check inter 2000 rise 2 fall 5#启动Haproxy服务/usr/local/haproxy/sbin/haproxy-f haproxy.conf#haproxy启动脚本#!/bin/bashBASE_DIR="/usr/local/haproxy"ARGV="$@"start(){echo"START HAPoxy SERVERS"$BASE_DIR/sbin/haproxy-f $BASE_DIR/conf/haproxy.conf}stop(){echo"STOP HAPoxy Listen"kill-TTOU $(cat$BASE_DIR/logs/haproxy.pid)echo"STOP HAPoxy process"kill-USR1 $(cat$BASE_DIR/logs/haproxy.pid)}case$ARGV instart)startERROR=$?;;stop)stopERROR=$?;;restart)stopstartERROR=$?;;*)echo"hactl.sh [start|restart|stop]"esacexit$ERROR
vim /etc/syslog.conf#添加:local3.* /var/log/haproxy.loglocal0.* /var/log/haproxy.logvim /etc/sysconfig/syslog#修改:SYSLOGD_OPTIONS="-r -m 0"#重新启动syslog服务/etc/init.d/syslogrestart
wget http://www.keepalived.org/software/keepalived-1.2.5.tar.gzln-s /usr/src/kernels/2.6.18-164.el5-x86_64/ /usr/src/linuxtar-zxvf keepalived-1.2.5.tar.gzcdkeepalived-1.2.5./configure--prefix=/usr/local/keepalivedmake&& makeinstallcpkeepalived/etc/init.d/keepalived.rh.init /etc/init.d/keepalivedchmod+x /etc/init.d/keepalivedcpkeepalived/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalivedchkconfig --add keepalivedchkconfig --level 35 keepalived oncp/usr/local/keepalived/sbin/keepalived/bin/mkdir-p /etc/keepalivedcp/usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/#Haproxy master配置文件vim /etc/keepalived/keepalived.conf! Configuration File forkeepalivedglobal_defs {notification_email {shifeng_zhang88@163.com}notification_email_from shifeng_zhang88@163.comsmtp_server smtp.163.comsmtp_connect_timeout 30router_id LVS_Master}vrrp_script chk_http_port {script "/etc/keepalived/check_haproxy.sh"interval 5 #脚本执行间隔weight -5 #执行脚本后优先级变更:5表示优先级+5;-5则表示优先级-5}vrrp_instance VI_A {state MASTERinterface eth0virtual_router_id 50priority 100advert_int 1authentication {auth_type PASSauth_pass sfzhang1109}track_script {chk_http_port}virtual_ipaddress {192.168.1.236 #haproxy虚拟IP}}#Haproxy backup配置文件只需改变state和priority的值state BACKUPpriority 50#启动keepalived服务/etc/init.d/keepalivedstart
vim /etc/keepalived/check_haproxy.sh#!/bin/bashA=`ps-C haproxy --no-header |wc-l`if[ $A -eq0 ];then/etc/init.d/haproxyrestartecho"Start haproxy"&> /dev/nullsleep3if[ `ps-C haproxy --no-header |wc-l` -eq0 ];then/etc/init.d/keepalivedstopecho"Stop keepalived"&> /dev/nullfifi#chomd +x /etc/keepalived/check_haproxy.sh
1)Haproxy+Keepalived 高可用测试。
3)Haproxy+Keepalived 故障转移测试
0 0
- HAproxy+keepalived+mysql高可用性Linux系统集群
- HAproxy+keepalived+mysql高可用性Linux系统集群
- 高可用性之Keepalived+Mysql
- lvs集群高可用性keepalived配置
- Keepalived高可用性集群及原理介绍
- HaProxy+keepalived+mycat集群高可用配置
- MySQL高可用性之Keepalived+Mysql
- MySQL高可用性之Keepalived+Mysql
- keepalived+MySQL双主实现高可用性
- MySQL 高可用性之 Keepalived 双主热备
- Keepalived+MySQL双主单写实现高可用性
- MySQL 高可用性之 Keepalived 双主热备
- Mysql+Keepalived高可用性双主配置
- Rabbitmq集群及使用keepalived实现rabbitmq高可用性集群
- Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
- 如何快速构建高可用集群(Keepalived+Haproxy+Nginx)
- Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
- rabbitmq+haproxy+keepalived实现高可用集群搭建
- ubunut 用ln -s 将项目链接到lamp www/html目录
- 学习spring mvc 三
- static、final、static final 用法
- C# 判断网络是否连接
- Java中Servlet简介
- HAproxy+keepalived+mysql高可用性Linux系统集群
- CSS3的calc()使用
- cocos2d-js 网络请求(GET)
- PHP中include 和 require 引入的区别
- Ubuntu14.04部署CEPH
- python 批量添加的button 使用同一点击事件
- maven无法加载本地jar包以及maven项目打包后本地jar包没有打进项目的问题解决办法
- Boost.Asio和ACE之间关于Socket编程的比较
- linux下挂载(mount)光盘镜像文件、移动硬盘、U盘、Windows和NFS网络共享