Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目。它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上,修改了大量bug,添加了很多功能特性。目前该项目在360公司内部得到了广泛应用,很多MySQL业务已经接入了Atlas平台,每天承载的读写请求数达几十亿条。同时,有超过50家公司在生产环境中部署了Atlas,超过800人已加入了我们的开发者交流群,并且这些数字还在不断增加。
官方链接:https://github.com/Qihoo360/Atlas
1.读写分离
2.从库负载均衡
3.IP过滤
4.自动分表
5.DBA可平滑上下线DB
6.自动摘除宕机的DB
接下来将测试验证以上功能。。。。。。
]# rpm -ivh Atlas-2.1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:Atlas ########################################### [100%]
Atlas运行需要依赖一个配置文件(test.cnf)。在运行Atlas之前,需要对该文件进行配置。Atlas的安装目录是/usr/local/mysql-proxy,进入安装目录下的conf目录,可以看到已经有一个名为test.cnf的默认配置文件,我们只需要修改里面的某些配置项,不需要从头写一个配置文件。
]# pwd
/usr/local/mysql-proxy/conf
]# vim test.cnf
[mysql-proxy]
#带#号的为非必需的配置项目
#管理接口的用户名
admin-username = user
#管理接口的密码
admin-password = pwd
#注:使用的主从环境:Master:192.168.1.100,Slave:192.168.1.200
#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses = 192.168.1.100:3306
#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
proxy-read-only-backend-addresses = 192.168.1.200:3306
#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!
pwds = root:5AaUuB6tXYU=
#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true
daemon = true
#设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为false时只有worker,没有monitor,一般开发调试时设为false,线上运行时设为true
keepalive = true
#工作线程数,对Atlas的性能有很大影响,可根据情况适当设置
event-threads = 1
#日志级别,分为message、warning、critical、error、debug五个级别
log-level = message
#日志存放的路径
log-path = /usr/local/mysql-proxy/log
#SQL日志的开关,可设置为OFF、ON、REALTIME,OFF代表不记录SQL日志,ON代表记录SQL日志,REALTIME代表记录SQL日志且实时写入磁盘,默认为OFF
sql-log = REALTIME
#实例名称,用于同一台机器上多个Atlas实例间的区分
instance = test
#Atlas监听的工作接口IP和端口
proxy-address = 0.0.0.0:1234
#Atlas监听的管理接口IP和端口
admin-address = 0.0.0.0:2345
#分表设置,此例中person为库名,mt为表名,id为分表字段,3为子表数量,可设置多项,以逗号分隔,若不分表则不需要设置该项
#tables = person.mt.id.3
#默认字符集,设置该项后客户端不再需要执行SET NAMES语句
charset = utf8
#允许连接Atlas的客户端的IP,可以是精确IP,也可以是IP段,以逗号分隔,若不设置该项则允许所有IP连接,否则只允许列表中的IP连接
#client-ips = 127.0.0.1, 192.168.1
#Atlas前面挂接的LVS的物理网卡的IP(注意不是虚IP),若有LVS且设置了client-ips则此项必须设置,否则可以不设置
#lvs-ips = 192.168.1.1
关于配置文件参数详细说明可以参考:
https://github.com/Qihoo360/Atlas/wiki/Atlas%E7%9A%84%E5%AE%89%E8%A3%85
]# /usr/local/mysql-proxy/bin/mysql-proxyd test start
OK: MySQL-Proxy of test is started
注意:
(1). 运行文件是:mysql-proxyd(不是mysql-proxy)。
(2). test是conf目录下配置文件的名字,也是配置文件里instance项的名字,三者需要统一。
]# ps -ef | grep mysql-proxy|grep -v grep
root 7186 1 0 14:28 ? 00:00:00 /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/test.cnf
root 7187 7186 0 14:28 ? 00:00:00 /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/test.cnf
]# mysql -P2345 -uuser -ppwd -h 127.0.0.1
……
mysql> select * from t;
ERROR 1105 (07000): use 'SELECT * FROM help' to see the supported commands
mysql> SELECT * FROM help;
+----------------------------+---------------------------------------------------------+
| command | description |
+----------------------------+---------------------------------------------------------+
| SELECT * FROM help | shows this help |
| SELECT * FROM backends | lists the backends and their state |
| SET OFFLINE $backend_id | offline backend server, $backend_id is backend_ndx's id |
| SET ONLINE $backend_id | online backend server, ... |
| ADD MASTER $backend | example: "add master 127.0.0.1:3306", ... |
| ADD SLAVE $backend | example: "add slave 127.0.0.1:3306", ... |
| REMOVE BACKEND $backend_id | example: "remove backend 1", ... |
+----------------------------+---------------------------------------------------------+
7 rows in set (0.00 sec)
mysql> select * FROM backends;
#可以看到1.100为rw,1.200为ro
#连接Atlas,进行增删改查,查看sql_log日志
#注意如果atlas和mysql处于同一台机器,连接atlas时必须指定-h 127.0.0.1或者机器的IP
因为不指定-h的时候mysql连接走的unix socket连接,此时-P参数无效,-P后面指定任意端口都是连到的本机的mysql实例
~]# mysql -P1234 -uroot -pyougou -h192.168.1.200
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1827336327
Server version: 5.0.81-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show tables;
+------------------+
| Tables_in_yougou |
+------------------+
| t |
+------------------+
1 row in set (0.00 sec)
mysql> select * from t;
+------+
| x |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+------+
5 rows in set (0.01 sec)
mysql> delete from t where x=5;
Query OK, 1 row affected (0.05 sec)
mysql> insert into t select 5;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> update t set x=8 where x=5;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t;
+------+
| x |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 8 |
+------+
5 rows in set (0.00 sec)
mysql> create table y(y int);
Query OK, 0 rows affected (0.61 sec)
mysql> drop table y;
Query OK, 0 rows affected (0.28 sec)
#对应的sql_log日志:
~]# tail -f /usr/local/mysql-proxy/log/sql_test.log
#可以看到所有的增删改查操作都去master上,select去slave上
Master 192.168.1.100:3306
Slave 192.168.1.200:3306, 192.168.1.200:3307, 192.168.1.200:3308
#此处实验环境资源有限,使用的mysqld_multi启动多个mysql实例,关于mysqld_multi的使用参考:http://blog.itpub.net/27000195/viewspace-1419251/
#其他参数与上面一致,主要修改proxy-read-only-backend-addresses为:
~]# /usr/local/mysql-proxy/bin/mysql-proxyd test restart
OK: MySQL-Proxy of test is stopped
OK: MySQL-Proxy of test is started
#在1.200上连接1.200的atlas,进行数据库操作,查看atlas的sql_log日志
~]# tail -f /usr/local/mysql-proxy/log/sql_test.log
可以看到读得操作都是在(slave)1.200上,并且3306端口会联系读2次(配置了3306@2权重为2),才轮到3307和3308端口,从而实现了读负载均衡和读写分离
通过配置client-ips来限制允许连接Atlas的客户端的IP,可以是精确IP,也可以是IP段,以逗号分隔,若不设置该项则允许所有IP连接,否则只允许列表中的IP连接
client-ips = 127.0.0.1, 192.168.1
]# /usr/local/mysql-proxy/bin/mysql-proxyd test restart
OK: MySQL-Proxy of test is stopped
OK: MySQL-Proxy of test is started
#本机连接正常
#使用1.100连接1.200的atlas,被拒绝
从而实现了客户端IP过滤功能
#此处将数据库yougou下的表parttable按照字段ID分位10张表
重启atlas使配置生效
#yougoyu数据库中创建parttable_0….10共10张子表
#本来打算使用procedure插入测试数据,但是报错,如下:
create procedure insertparttable()
begin
declare i int;
set i=0;
while i<100 do
insert into parttable values(i,i*100);
set i=i+1;
end while;
end;//
mysql> call insertparttable();
ERROR 1146 (42S02): Table 'yougou.parttable' doesn't exist
所以只有写明ID列位int数字,来生成:
~]# vim insertparttable.sql
insert into parttable values(1,100);
insert into parttable values(i,i*100);
0<=i<=100
……
#插入数据
mysql> source insertparttable.sql
#监控sql_log,发现atlas自动将id%10的结果插入到对应的子表中
#查询数据
#对应的sql_log
如上验证了atlas的简单分表功能,感觉目前可用性较差
#上线
#下线
#正常状态
#将3308端口的mysql停止
#连接atlas,执行查询,并且查看log
可以看到atlas的log提示标记为down,sql_log中发现不在去3308端口读
#此时通过atlas管理环境查看状态,发现3308的state为down
Mysql主从:一主三从
Atlas:2个节点做HA
Keepalived:提供VIP防止Atlas单点故障
省略……
http://www.keepalived.org/download.html 下载url
#安装keepalived
tar zxvf keepalived-1.2.13.tar -C /opt/
cd /opt/keepalived-1.2.13
./configure --prefix=/usr/local/keeplived
make;makeinstall 或 make && makeinstall
#编译keepalived时报错
++++++++++++++++++++++++++++++++++++++++
configure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files. !!!
++++++++++++++++++++++++++++++++++++++++
解决方法:
rpm -ivh e2fsprogs-devel-1.39-23.el5.x86_64.rpm
rpm -ivh keyutils-libs-devel-1.2-1.el5.x86_64.rpm
rpm -ivh libsepol-devel-1.15.2-2.el5.x86_64.rpm
rpm -ivh libselinux-devel-1.33.4-5.5.el5.x86_64.rpm
rpm -ivh krb5-devel-1.6.1-36.el5.x86_64.rpm
rpm -ivh zlib-devel-1.2.3-3.x86_64.rpm
rpm -ivh openssl-devel-0.9.8e-12.el5.x86_64.rpm
==============================================
#新建一个配置文件,默认情况下keepalived启动时会去/etc/keepalived
]# mkdir -p /etc/keepalived
]# cp -p /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
#Atlas1(1.100)上
~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id Atlas_ha
}
vrrp_instance Atlas_ha{
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.254
}
}
virtual_server 192.168.1.254 1234{
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.1.100 1234{
weight 3
notify_down /usr/local/mysql-proxy/bin/Atlas.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 1234
}
}
#Atlas2(1.200)与atlas1几乎一致,如下:
~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id Atlas_ha
}
vrrp_instance Atlas_ha{
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.254
}
}
virtual_server 192.168.1.254 1234{
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.1.200 1234{
weight 3
notify_down /usr/local/mysql-proxy/bin/Atlas.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 1234
}
}
}
~]# cat /usr/local/mysql-proxy/bin/Atlas.sh
#!/bin/sh
pkill keepalived
~]# chmod +x /usr/local/mysql-proxy/bin/Atlas.sh
~]# /usr/local/keepalived/sbin/keepalived –D
~]#ps aux | grep keepalived
使用客户端连接VIP(1.254):1234,假设VIP此时绑定在atlas A节点上
查看atlas A节点上altlas的log可以看到用户在使用当前atlas A连接数据库,关闭此节点上的atlas
发现VIP切换到另外一个节点atlas B,并且在atlas B上查看atlas的log,发现此时客户端已经切换到atlas B上从而实现了Atlas的HA功能
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27000195/viewspace-1421262/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27000195/viewspace-1421262/
文章浏览阅读3.8k次,点赞9次,收藏28次。直接上一个工作中碰到的问题,另外一个系统开启多线程调用我这边的接口,然后我这边会开启多线程批量查询第三方接口并且返回给调用方。使用的是两三年前别人遗留下来的方法,放到线上后发现确实是可以正常取到结果,但是一旦调用,CPU占用就直接100%(部署环境是win server服务器)。因此查看了下相关的老代码并使用JProfiler查看发现是在某个while循环的时候有问题。具体项目代码就不贴了,类似于下面这段代码。while(flag) {//your code;}这里的flag._main函数使用while(1)循环cpu占用99
文章浏览阅读347次。idea shift f6 快捷键无效_idea shift +f6快捷键不生效
文章浏览阅读135次。Ecmacript 中没有DOM 和 BOM核心模块Node为JavaScript提供了很多服务器级别,这些API绝大多数都被包装到了一个具名和核心模块中了,例如文件操作的 fs 核心模块 ,http服务构建的http 模块 path 路径操作模块 os 操作系统信息模块// 用来获取机器信息的var os = require('os')// 用来操作路径的var path = require('path')// 获取当前机器的 CPU 信息console.log(os.cpus._node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是
文章浏览阅读10w+次,点赞435次,收藏3.4k次。SPSS 22 下载安装过程7.6 方差分析与回归分析的SPSS实现7.6.1 SPSS软件概述1 SPSS版本与安装2 SPSS界面3 SPSS特点4 SPSS数据7.6.2 SPSS与方差分析1 单因素方差分析2 双因素方差分析7.6.3 SPSS与回归分析SPSS回归分析过程牙膏价格问题的回归分析_化工数学模型数据回归软件
文章浏览阅读7.5k次。如何利用hutool工具包实现邮件发送功能呢?1、首先引入hutool依赖<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.19</version></dependency>2、编写邮件发送工具类package com.pc.c..._hutool发送邮件
文章浏览阅读867次,点赞2次,收藏2次。docker安装elasticsearch,elasticsearch-head,kibana,ik分词器安装方式基本有两种,一种是pull的方式,一种是Dockerfile的方式,由于pull的方式pull下来后还需配置许多东西且不便于复用,个人比较喜欢使用Dockerfile的方式所有docker支持的镜像基本都在https://hub.docker.com/docker的官网上能找到合..._docker安装kibana连接elasticsearch并且elasticsearch有密码
文章浏览阅读1.3w次,点赞57次,收藏92次。整理 | 郑丽媛出品 | CSDN(ID:CSDNnews)近年来,随着机器学习的兴起,有一门编程语言逐渐变得火热——Python。得益于其针对机器学习提供了大量开源框架和第三方模块,内置..._beeware
文章浏览阅读7.9k次。//// ViewController.swift// Day_10_Timer//// Created by dongqiangfei on 2018/10/15.// Copyright 2018年 飞飞. All rights reserved.//import UIKitclass ViewController: UIViewController { ..._swift timer 暂停
文章浏览阅读986次,点赞2次,收藏2次。1.硬性等待让当前线程暂停执行,应用场景:代码执行速度太快了,但是UI元素没有立马加载出来,造成两者不同步,这时候就可以让代码等待一下,再去执行找元素的动作线程休眠,强制等待 Thread.sleep(long mills)package com.example.demo;import org.junit.jupiter.api.Test;import org.openqa.selenium.By;import org.openqa.selenium.firefox.Firefox.._元素三大等待
文章浏览阅读3k次,点赞4次,收藏14次。Java软件工程师职位分析_java岗位分析
文章浏览阅读2k次。Java:Unreachable code的解决方法_java unreachable code
文章浏览阅读1w次。1、html中设置标签data-*的值 标题 11111 222222、点击获取当前标签的data-url的值$('dd').on('click', function() { var urlVal = $(this).data('ur_如何根据data-*属性获取对应的标签对象