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.pswp.cn/news/529233.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/529233.shtml
英文地址,請注明出處:http://en.pswp.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 …