mysql 高可用架构 proxysql 之一 yum安装-程序员宅基地

技术标签: proxysql  

os:centos 7.4
mysql: 5.7
proxysql: 1.4.10

ip 规划如下:

192.168.56.101 node1 (proxysql)

192.168.56.102 node2 (mysql master)
192.168.56.103 node3 (mysql slave)
192.168.56.104 node4 (mysql slave)

安装mysql 5.7

node2、node3、node4 安装 mysql 5.7 software
详细过称略,参考另外一篇博客。

初始化mysql 5.7,配置好master slave

node2、node3、node4 各个节点先初始化 mysql 5.7,再配置 master/slave

master 修改密码

mysql> set password for 'root'@'localhost'= password('2wsx3edc');
mysql> flush privileges;

master 创建复制用户

mysql> create user 'replicator'@'192.168.56.%' identified by '2wsx3edc';
mysql> grant replication slave on *.* to 'replicator'@'192.168.56.%';
mysql> flush privileges;

master 使用 mysqldump 出集合,再在slave端导入

# mysqldump -uroot -p --master-data=2 --single-transaction -R --triggers -A > mysql_all.sql

其中
–master-data=2代表备份时刻记录master的Binlog位置和Position,
–single-transaction意思是获取一致性快照,
-R意思是备份存储过程和函数,
–triggres的意思是备份触发器,
-A代表备份所有的库。

mysql> change master to
  master_host='192.168.56.102',
  master_user='replicator',
  master_password='2wsx3edc',
  master_port=3306,
  master_log_file='mysql-bin.000001',
  master_log_pos=154;
mysql> start slave;  

salve设置为 read only,从库对外提供读服务,只所以没有写进配置文件,是因为随时slave会提升为master。

mysql> set global read_only=1;
mysql> set global relay_log_purge=0;

至此,已经配置好了1master、2slave

配置本地免密登录

登录主机后,登录mysql需要输入密码,配置个密码文件。免得每次都需要输入密码。
node2、node3、node4节点都需要操作

# vi ~/.my.cnf

[client] 
host=localhost 
user='root' 
password='2wsx3edc'

# chmod 700 ~/.my.cnf

下载、安装 proxysql

node1 节点安装mysql 5.7 client,mysql 5.7 lib

# yum install mysql-community-client mysql-community-common mysql-community-devel mysql-community-libs mysql-community-libs-compat 

node1 节点安装 proxysql
下载地址如下:
https://github.com/sysown/ProxySQL
或者
https://www.percona.com/downloads/proxysql/

安装依赖包

# yum install perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL
# cd /etc/yum.repos.d/
# cat <<EOF | tee /etc/yum.repos.d/proxysql.repo
[proxysql_repo]
name= ProxySQL YUM repository
baseurl=http://repo.proxysql.com/ProxySQL/proxysql-1.4.x/centos/\$releasever
gpgcheck=1
gpgkey=http://repo.proxysql.com/ProxySQL/repo_pub_key
EOF
# yum install proxysql 
=======================================================================================================================================
 Package                        Arch                         Version                         Repository                           Size
=======================================================================================================================================
Installing:
 proxysql                       x86_64                       1.4.10-1                        proxysql_repo                       5.7 M

Transaction Summary
=======================================================================================================================================

查看 proxysql-1.4.10-1.x86_64 涉及到哪些文件

# rpm -ql proxysql-1.4.10-1.x86_64
/etc/init.d/proxysql
/etc/proxysql.cnf
/usr/bin/proxysql
/usr/share/proxysql/tools/proxysql_galera_checker.sh
/usr/share/proxysql/tools/proxysql_galera_writer.pl
# systemctl status proxysql.service 
● proxysql.service - LSB: High Performance Advanced Proxy for MySQL
   Loaded: loaded (/etc/rc.d/init.d/proxysql; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
# cat /etc/init.d/proxysql

/etc/init.d/proxysql 脚本涉及到如下目录、文件

OLDDATADIR="/var/run/proxysql"
DATADIR="/var/lib/proxysql"
OPTS="-c /etc/proxysql.cnf -D $DATADIR"
PIDFILE="$DATADIR/proxysql.pid"

/run/systemd/generator.late/proxysql.service

# more /run/systemd/generator.late/proxysql.service
# Automatically generated by systemd-sysv-generator

[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/proxysql
Description=LSB: High Performance Advanced Proxy for MySQL
Before=runlevel2.target
Before=runlevel3.target
Before=runlevel4.target
Before=runlevel5.target
Before=shutdown.target
After=network-online.target
Conflicts=shutdown.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/rc.d/init.d/proxysql start
ExecStop=/etc/rc.d/init.d/proxysql stop
ExecReload=/etc/rc.d/init.d/proxysql reload

配置文件 /etc/proxysql.cnf

检查版本

# which proxysql
/usr/bin/proxysql
# proxysql --version
ProxySQL version v1.4.10-1-g5eb0f3e, codename Truls

# proxysql --help
High Performance Advanced Proxy for MySQL

USAGE: proxysql [OPTIONS]

OPTIONS:

-c, --config ARG             Configuraton file
-D, --datadir ARG            Datadir
-e, --exit-on-error          Do not restart ProxySQL if crashes
-f, --foreground             Run in foreground
-h, -help, --help, --usage   Display usage instructions.
-M, --no-monitor             Do not start Monitor Module
-n, --no-start               Starts only the admin service
-r, --reuseport              Use SO_REUSEPORT
-S, --admin-socket ARG       Administration Unix Socket
-V, --version                Print version
--idle-threads               Create auxiliary threads to handle idle connections
--initial                    Rename/empty database file
--reload                     Merge config file into database file
--sqlite3-server             Enable SQLite3 Server


ProxySQL rev. v1.4.10-1-g5eb0f3e -- Tue Aug  7 12:31:55 2018
Copyright (C) 2013-2018 ProxySQL LLC
This program is free and without warranty

有 -c –config 的option,可以把参数全部导入到参数文件,易于管理。

配置proxysql.cnf

# cp /etc/proxysql.cnf /etc/proxysql.cnf.bak
# vi /etc/proxysql.cnf

配置文件只在第一次启动的时候读取进行初始化,后面只读取db文件。
所以还是先启动,然后再修改参数。

启动 proxysql

# service proxysql start
Starting ProxySQL: 2018-08-13 11:08:25 [INFO] Using config file /etc/proxysql.cnf
DONE!

# ps -ef|grep -i proxysql
root      7859     1  0 11:08 ?        00:00:00 proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
root      7860  7859  0 11:08 ?        00:00:00 proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql

# netstat -antp|grep -i 7859
# netstat -antp|grep -i 7860
tcp        0      0 0.0.0.0:6032            0.0.0.0:*               LISTEN      7860/proxysql       
tcp        0      0 0.0.0.0:6033            0.0.0.0:*               LISTEN      7860/proxysql 

根据 /etc/proxysql.cnf 文件内容,6032 是管理端口,6033 是 mysql 连接端口。

连接 proxysql 6032 管理端口

# mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
mysql: [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 1
Server version: 5.5.30 (ProxySQL Admin Module)

Copyright (c) 2000, 2018, 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.

Admin> 

proxysql 的安装先说的这里,下一篇blog说下配置。

参考:
http://www.proxysql.com/
http://www.proxysql.com/compare

https://www.percona.com/downloads/proxysql/

https://github.com/sysown/proxysql/releases
https://github.com/sysown/ProxySQL
https://github.com/sysown/proxysql/wiki

cat /etc/proxysql.cnf

#file proxysql.cfg

########################################################################################
# This config file is parsed using libconfig , and its grammar is described in:        
# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar 
# Grammar is also copied at the end of this file                                       
########################################################################################

########################################################################################
# IMPORTANT INFORMATION REGARDING THIS CONFIGURATION FILE:                             
########################################################################################
# On startup, ProxySQL reads its config file (if present) to determine its datadir. 
# What happens next depends on if the database file (disk) is present in the defined
# datadir (i.e. "/var/lib/proxysql/proxysql.db").
#
# If the database file is found, ProxySQL initializes its in-memory configuration from 
# the persisted on-disk database. So, disk configuration gets loaded into memory and 
# then propagated towards the runtime configuration. 
#
# If the database file is not found and a config file exists, the config file is parsed 
# and its content is loaded into the in-memory database, to then be both saved on-disk 
# database and loaded at runtime.
#
# IMPORTANT: If a database file is found, the config file is NOT parsed. In this case
#            ProxySQL initializes its in-memory configuration from the persisted on-disk
#            database ONLY. In other words, the configuration found in the proxysql.cnf
#            file is only used to initial the on-disk database read on the first startup.
#
# In order to FORCE a re-initialise of the on-disk database from the configuration file 
# the ProxySQL service should be started with "service proxysql initial".
#
########################################################################################

datadir="/var/lib/proxysql"

admin_variables=
{
    admin_credentials="admin:admin"
#   mysql_ifaces="127.0.0.1:6032;/tmp/proxysql_admin.sock"
    mysql_ifaces="0.0.0.0:6032"
#   refresh_interval=2000
#   debug=true
}

mysql_variables=
{
    threads=4
    max_connections=2048
    default_query_delay=0
    default_query_timeout=36000000
    have_compress=true
    poll_timeout=2000
#   interfaces="0.0.0.0:6033;/tmp/proxysql.sock"
    interfaces="0.0.0.0:6033"
    default_schema="information_schema"
    stacksize=1048576
    server_version="5.5.30"
    connect_timeout_server=3000
# make sure to configure monitor username and password
# https://github.com/sysown/proxysql/wiki/Global-variables#mysql-monitor_username-mysql-monitor_password
    monitor_username="monitor"
    monitor_password="monitor"
    monitor_history=600000
    monitor_connect_interval=60000
    monitor_ping_interval=10000
    monitor_read_only_interval=1500
    monitor_read_only_timeout=500
    ping_interval_server_msec=120000
    ping_timeout_server=500
    commands_stats=true
    sessions_sort=true
    connect_retries_on_failure=10
}


# defines all the MySQL servers
mysql_servers =
(
#   {
    
#       address = "127.0.0.1" # no default, required . If port is 0 , address is interpred as a Unix Socket Domain
#       port = 3306           # no default, required . If port is 0 , address is interpred as a Unix Socket Domain
#       hostgroup = 0           # no default, required
#       status = "ONLINE"     # default: ONLINE
#       weight = 1            # default: 1
#       compression = 0       # default: 0
#   max_replication_lag = 10  # default 0 . If greater than 0 and replication lag passes such threshold, the server is shunned
#   },
#   {
    
#       address = "/var/lib/mysql/mysql.sock"
#       port = 0
#       hostgroup = 0
#   },
#   {
    
#       address="127.0.0.1"
#       port=21891
#       hostgroup=0
#       max_connections=200
#   },
#   { address="127.0.0.2" , port=3306 , hostgroup=0, max_connections=5 },
#   { address="127.0.0.1" , port=21892 , hostgroup=1 },
#   { address="127.0.0.1" , port=21893 , hostgroup=1 }
#   { address="127.0.0.2" , port=3306 , hostgroup=1 },
#   { address="127.0.0.3" , port=3306 , hostgroup=1 },
#   { address="127.0.0.4" , port=3306 , hostgroup=1 },
#   { address="/var/lib/mysql/mysql.sock" , port=0 , hostgroup=1 }
)


# defines all the MySQL users
mysql_users:
(
#   {
    
#       username = "username" # no default , required
#       password = "password" # default: ''
#       default_hostgroup = 0 # default: 0
#       active = 1            # default: 1
#   },
#   {
    
#       username = "root"
#       password = ""
#       default_hostgroup = 0
#       max_connections=1000
#       default_schema="test"
#       active = 1
#   },
#   { username = "user1" , password = "password" , default_hostgroup = 0 , active = 0 }
)



#defines MySQL Query Rules
mysql_query_rules:
(
#   {
    
#       rule_id=1
#       active=1
#       match_pattern="^SELECT .* FOR UPDATE$"
#       destination_hostgroup=0
#       apply=1
#   },
#   {
    
#       rule_id=2
#       active=1
#       match_pattern="^SELECT"
#       destination_hostgroup=1
#       apply=1
#   }
)

scheduler=
(
#  {
    
#    id=1
#    active=0
#    interval_ms=10000
#    filename="/var/lib/proxysql/proxysql_galera_checker.sh"
#    arg1="0"
#    arg2="0"
#    arg3="0"
#    arg4="1"
#    arg5="/var/lib/proxysql/proxysql_galera_checker.log"
#  }
)


mysql_replication_hostgroups=
(
#        {
    
#                writer_hostgroup=30
#                reader_hostgroup=40
#                comment="test repl 1"
#       },
#       {
    
#                writer_hostgroup=50
#                reader_hostgroup=60
#                comment="test repl 2"
#        }
)




# http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-File-Grammar
#
# Below is the BNF grammar for configuration files. Comments and include directives are not part of the grammar, so they are not included here. 
#
# configuration = setting-list | empty
#
# setting-list = setting | setting-list setting
#     
# setting = name (":" | "=") value (";" | "," | empty)
#     
# value = scalar-value | array | list | group
#     
# value-list = value | value-list "," value
#     
# scalar-value = boolean | integer | integer64 | hex | hex64 | float
#                | string
#     
# scalar-value-list = scalar-value | scalar-value-list "," scalar-value
#     
# array = "[" (scalar-value-list | empty) "]"
#     
# list = "(" (value-list | empty) ")"
#     
# group = "{" (setting-list | empty) "}"
#     
# empty =
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ctypyb2002/article/details/81626763

智能推荐

matlab语言定义变量类型,matlab定义变量-MATLAB,变量-程序员宅基地

本教程分享:《matlab定义变量》,matlab中变量如何定义?可以用sym 或者 syms 定义变量。如果没有提前定义的话,可以在使用时可直接进行赋值使用。MATLAB中变量名以字母开头,后接字母、数字或下划线,最多63个字符;区分大小写;关键字和函数名不能作为变量名。扩展知识:Matlab变量的特点:不需事先声明,也不需指定变量类型,Matlab自动根据所赋予变量的值或对变量所进行的操作来..._matlab定义变量

大数据之Python实现每日钉钉数据自动推送_python 钉钉消息推送_热心市民楚先生的博客-程序员宅基地

大数据之Python实现每日钉钉数据自动推送最近有一个需求,领导们需要关注每日的一些指标。简单研究了一下,发现用python+impala+钉钉可以实现,最终敲定了两个方式python+钉钉python+邮件推送下面简单的记录一下实现第一种方案的:一,钉钉群内添加推送的小机器人在这里可以随意选择一种安全设置:我尝试了自定义的方式最后会生成一个Webhook,这个后面我们代码里面会用到二,代码实现from datetime import datetimeimport js_python 钉钉消息推送

局域网打印机怎么连接_怎么连接同事已共享的打印机?-程序员宅基地

  需要知道共享打印机的主机ip地址之后根据主机的ip地址链接已共享的打印机,先找同事共享的打印机,然后输入共享打印机的ip地址页面,输入主机ip地址之后点击下一步,最后就是等待链接即可。  1、打开【开始】菜单,点击【设置】按钮;然后打开设置页面中的【设备】;  2、点击设备页面左侧的【打印机和扫描仪】,点击设置页面的加号添加新的打印机;然后选择橙色字体的【我需要的打印机不在列表中】;  3、在..._怎么连接局域网内的打印机

引用dll报错:error C2491-不允许 dllimport 静态数据成员 的定义_不允许dllimport静态数据成员定义-程序员宅基地

问题创建一个QT的dll工程,生成lib、dll文件后,新建一个测试工程,将动态库的头文件、lib文件加入到该工程里,通过头文件引用dll的导出类.编译测试工程时报错:1>GeneratedFiles\Release\moc_TestDll.cpp(58): warning C4273: “TestDll::qt_static_metacall”: dll 链接不一致1>..._不允许dllimport静态数据成员定义

Python的最佳学习方式-程序员宅基地

作者 |GENEVIEVE CARLTON译者 | 姜松浩责编 |屠敏转载自 CSDN(ID:CSDNNews)25岁转行人工智能靠谱吗?https://edu.csdn.net/topic/ai30?utm_source=ai100_bw以下为译文:如今想要学习 Python 的人拥有比以往更多的资源。但是,这也可能使筛选书籍..._code academy: learn python

使用C语言写PostgreSQL函数_c语言操作pgsql-程序员宅基地

引言:使用C语言写PostgreSQL中的函数可以很方便的扩展PostgreSQL数据库的功能。由C语言写的函数,使用方法与PostgreSQL中内置的函数基本没有差别,性能基本也没有什么差别。本文一步一步教你如何使用C语言写PostgreSQL函数:1. 先根据一个简单函数的生成一个动态库,看PostgreSQL能否使用源文件为cfunc.c,内容如下:#includ_c语言操作pgsql

随便推点

HttpClient 多线程处理_httpclient多线程使用时需要生成多个请求对象嘛-程序员宅基地

为什么要使用单例HttpClient?在发出HTTP请求前,我们先创建了一个HttpClient对象。那么,在实际项目中,我们很可能在多处需要进行HTTP通信,这时候我们不需要为每个请求都创建一个新的HttpClient。因为HttpClient就像一个小型的浏览器,对于整个应用,我们只需要一个HttpClient就够了。看到这里,一定有人心里想,这有什么难的,用单例啊!!那么,哪里不对劲呢?或者说_httpclient多线程使用时需要生成多个请求对象嘛

Docx4j简单学习_deepDSM的博客-程序员宅基地

docx4j简单学习前言: 此文档简单记述在使用docx4j进行编程式生成文档元素的个人心得,故存在理解有误之处,还请指正!该项目是基于docx文档的xml结构,进行标签对象的赋值与取值,因此,当生成部分不常见元素时(比如无序项目编码时),可以参考xml文件中的属性,进行编码实现。比如文档中插入小标题,即文本添加导航功能:文档内容如下:对应解压文件document.xml 即文档xml结构内容,styles.xml即为样式文件document.xml内容val是style中的_docx4j

如何获取input中输入的值_获取input的输入值-程序员宅基地

提供两种方式,一种通过id获取,一种通过name获取:电话:function(){ var mobi = $("#phone").val(); var mobi = $('input[name="mobile"]').val();}以上两种方式都能获得input输入值。_获取input的输入值

Fastboot驱动及安装_我是亲民_新浪博客-程序员宅基地

手机可以进入Fastboot模式,开发板通过暂停启动,输入fastboot也可以进入fastboot模式。有些CPU是需要fastboot,有些不需要。首先我们需要了解哪些手机需要安装Fastboot驱动:小米、华为等厂商手机采用的高通、海思、英伟达处理器属于fastboot平台,需要安装Fastboot驱动(三星和酷派虽然隶属Fastboot平台,但需要安装专用驱动)。若使用的是联...

通过Wifi调试运行Android应用的IntelliJ/AndroidStudio插件:AndroidWiFiADB-程序员宅基地

IntelliJ and Android Studio 插件能够让你通过WiFi快速连接你的Android设备来安装,运行和调试你的应用而不需要USB连接。只要一个按纽搞定一切。IntelliJ and Android Studio plugin created to quickly connect your Android device over WiFi to instal

Java-数据结构与算法--单链表面试题(新浪,百度,腾讯)_java数据结构与算法--单链表常见面试题(新浪、百度、腾讯)-程序员宅基地

注:本文结合[单链表增删改查]使用 (点击前往)单链表常见面试题如下:1.求单链表中有效节点的个数2.查找单链表中的倒数第K个节点(新浪面试题)3.单链表的反转(腾讯面试题)4.从尾到头打印单链表(百度要求1,反转遍历 2,Stack栈)5,合并两个有序的单链表,合并之后的链表依然有序1.求单链表中有效节点的个数//方法:获取单链表的节点个数(如果是带头节点的链表,需求不统计头节点) //head链表的头节点 //return 返回的就是有效节点的个数 public _java数据结构与算法--单链表常见面试题(新浪、百度、腾讯)