mysql proxy yum_mysql 高可用架构 proxysql 之一 yum安装

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

安装依赖包

# yum install perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL

# cd /etc/yum.repos.d/

# cat <

[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说下配置。

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 =

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/529233.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

wpf 使用位图画图为什么断断续续_WPF的未来是微软WinUi!

WPF(Windows Presentation Foundation)是微软推出的基于Windows 的用户界面框架&#xff0c;属于.NET Framework 3.0的一部分。它提供了统一的编程模型、语言和框架&#xff0c;真正做到了分离界面设计人员与开发人员的工作&#xff1b;同时它提供了全新的多媒体交互用户图形界…

antd新增一行页码不正确_antd-Table@4.x对rowKey属性的重构

时间&#xff1a;2020/04/26 &#xff0c;转载请注明出处。写在前面antd团队于2020年2月发布了酝酿已久的antd4.0版本&#xff0c;对样式的调整、部分组件逻辑的重构都进行了较大改动&#xff0c;本文针对Table的rowKey属性重构作分析。由一个mistake带来的思考在数据治理模块的…

qt调用mysql调用了存储过_Qt调用Server SQL中的存储过程

Server SQL中的存储过程如下&#xff1a;CREATE procedure PINSERTPCpcnum int,pcname varchar(50),pctype int,ipaddress varchar(50),port int,pcid int outputas--declare pcid intif exists (select * from COMPUTERTABLE where PcNum pcnum)set pcid -1elsebegininser…

pandas mysql index_Pandas从入门到精通(3)- Pandas多级索引MultiIndex

首先了解一下什么是多级索引&#xff0c;以及它的作用&#xff0c;为什么要有这个玩意。多级索引也称为层次化索引(hierarchical indexing)&#xff0c;是指数据在一个轴上(行或者列)拥有多个(两个以上)索引级别。之所以引入多级索引&#xff0c;在于它可以使用户能以低维度形式…

tensorflow 启动多个session_Tensorflow源码解析7 -- TensorFlow分布式运行时

1 概述TensorFlow架构设计精巧&#xff0c;在后端运行时这一层&#xff0c;除了提供本地运行时外&#xff0c;还提供了分布式运行时。通过分布式训练&#xff0c;在多台机器上并行执行&#xff0c;大大提高了训练速度。前端用户通过session.run()启动系统执行时&#xff0c;tar…

shell swt 样式_SWT之路:SWT图像显示

简明现代魔法 -> Java编程语言 -> SWT之路&#xff1a;SWT图像显示SWT之路&#xff1a;SWT图像显示2009-10-03程序演示还是先用SWT Desiner创建界面程序。然后创建一个Display对象和Image对象&#xff0c;和一个GC对象。类org.eclipse.swt.graphics.GC是一个封装了所有可…

swool tcp mysql_swoole/mysql(异步)

# 异步Swoole\Mysql**(要求Workerman版本>3.3.6)**## 注意:此组件由swoole底层提供&#xff0c;由C语言编写&#xff0c;具有超高性能。## 安装&#xff1a;安装有swoole扩展即可## 示例&#xff1a;phprequire_once ../Autoloader.php;use Workerman\Worker;use \Swoole\My…

xamarin和mysql_Xamarin.Android 使用 SQLiteOpenHelper 进行数据库操作

一、前言在手机中进行网络连接不仅是耗时也是耗电的&#xff0c;而耗电却是致命的。所以我们就需要数据库帮助我们存储离线数据&#xff0c;以便在用户未使用网络的情况下也可以能够使用应用的部分功能&#xff0c;而在需要网络连接的功能上采用提示方式&#xff0c;让用户决定…

python 绝对值误差小于10-6_Python 被低估了的 10 个小技巧

hi&#xff0c;各位朋友们&#xff0c;小帅b回来啦&#xff0c;几日不见&#xff0c;想我了么&#xff1f;今天给大家分享几个我认为不错的 Python 小技巧&#xff0c;有些可能被你低估了哟&#xff0c;get 起来&#xff01;那么接下来就是&#xff1a;学习 Python 的正确姿势俗…

java bean验证_javaBean--登录验证

packagecom.JAVABean;importjava.util.HashMap;importjava.util.Map;publiccla***egister{privateStringname;privateStringage;privateStringemail;privateMaperrorsnull;//声明一个保存全部错误信息的map集合publicRegister(){//在构造方法中初始化属性this.name""…

java读取src xml文件路径_Java获取路径方法相对路径读取xml文件方法

(1)、request.getRealPath("/");//不推荐使用获取工程的根路径(2)、request.getRealPath(request.getRequestURI());//获取jsp的路径&#xff0c;这个方法比较好用&#xff0c;可以直接在servlet和jsp中使用(3)、request.getSession().getServletContext().getRealPa…

释放tcp连接的命令是_最实用的6个网络命令,网络故障不求人

很多弱电工程师朋友在项目中经常遇到一些网络故障&#xff0c;需要通过一些一些命令去检测、定位故障点&#xff0c;通过使用网络命令&#xff0c;故障解决的工作取得了事半功倍的效果。下面就一起温故而知新吧&#xff01;一、ping命令&#xff08;因特网包探索器&#xff09;…

airpods2怎么查正品 ios11系统_拼多多AirPods2开箱评测,4种办法教你验真假,10个AirPods技巧教你玩...

大家好&#xff0c;Apple今天给大家分享一下拼多多上车AirPods 2无线充电盒版的经验&#xff0c;顺便整理了一波AirPods使用技巧&#xff0c;希望你用得上。入手理由自从去年10月份入手了iPhone XR&#xff0c;其实就挺想入款无线耳机的&#xff0c;所以一直在等AirPods升级换代…

java中for break的用法_java break语句的使用方法

在switch语中,break语句用来终止switch语句的执行。使程序 switch语句后的第一个语句 开始执行。在Java中,可以为每个代码块加一个括号,一个代码块通常 用大括号{}括起来的一段 代码。加标号的格式break语句有两种形式&#xff1a;无标签和有标签。无标签的break语句用来跳出单…

windows文件保护_Windows系统下媲美时间机器的系统备份工具,统统免费

Windows和macOS系统谁更美&#xff1f;不同的人有不同的见解。但体验过macOS之后很多电脑玩家会感叹&#xff0c;TimeMachine时间机器太好用了&#xff0c;Windows下有没有同类功能呢&#xff1f;TimeMachine提供了全盘完整备份、增量备份、文件历史版本等功能。它们在Windows …

JAVA结课_一点心情,写java结课考试之前

突然发现&#xff0c;已经好久没有上来写blog了&#xff0c;本来还以为能够天天写&#xff0c;后来发现&#xff0c;确是心有余力而不足啊。学期进入中段&#xff0c;课业慢慢多了&#xff0c;各种各样的事情也接踵而来了。本学期的java课程也已经结课了&#xff0c;8周32个学时…

sql怎么撤回update_腾讯SQL“现役运动员”给你的实践小技巧

引言SQL的全称是Structured Query Language(结构化查询语言)&#xff0c;是一种古老而简洁的程序设计语言。看似平平无奇&#xff0c;一直被各种吐槽&#xff0c;但却有着众多语言所难得的漫长寿命&#xff0c;并展现出极好的拓展性&#xff0c;在不同时期衍生出不同的子语言。…

mysql 同一帐号多次登录_freeradius2.1.3 防止用户帐号重复登录

freeradius2.1.3 防止用户帐号重复登录一、修改 etc/raddb/sites-enabled 目录中的default 及inner-tunnel 这两个文件中的# Session database, used for checking Simultaneous-Use. Either the radutmp# or rlm_sql module can handle this.# The rlm_sql module is *much…

小程序input wxss_19. 教你零基础搭建小程序:wxss-尺寸单位

这章以后的四章都是介绍小程序样式文件——wxss 的使用&#xff0c;分为以下三个部分一、尺寸方案二、样式导入三、选择器这章先来讲wxss的尺寸单位—— rpxwxss的定义&#xff1a;WXSS( WeiXin Style Sheets )是⼀套样式语言&#xff0c;用于描述 WXML 的组件样式。与 CSS 相比…

java 最优算法_java 问题 求个最优算法

不知道是不是你要的package test;import java.util.Scanner;public class Number {/*** param args*/public static void main(String[] args) {int count 15;int val 5;Scanner input new Scanner(System.in);System.out.print("请输入开始数&#xff1a;");int …