1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| - 创建目录 data run conf log # cd /usr/local/mysq-router # mkdir data run conf log # cp share/doc/mysqlrouter/sample_mysqlrouter.conf conf/mysqlrouter.conf # useradd -M -s /sbin/nologin mysql # chown -R mysql:mysql data
# vim /usr/local/mysq-router/conf/mysqlrouter.conf [DEFAULT] logging_folder = /usr/local/mysq-router/log plugin_folder = /usr/local/mysq-router/lib/mysqlrouter config_folder = /usr/local/mysq-router/conf runtime_folder = /usr/local/mysq-router/run data_folder = /usr/local/mysq-router/data #keyring_path = /var/lib/keyring-data #master_key_path = /var/lib/keyring-key max_total_connections = 10240 thread_stack_size=512
[logger] level = INFO filename = mysqlrouter.log timestamp_precision = second
# 主节点故障转移配置 [routing:basic_failover] bind_address=192.168.64.33 bind_port=6002 mode=read-write # 主节点地址:默认情况下第一台主数据库为写主库,当第一台主数据库DOWN机后,第二台数据库被提升为主库 destinations=192.168.64.32:3306,192.168.64.33:3306
# 从节点负载均衡配置 [routing:balancing] bind_address=192.168.64.33 bind_port=6001 # 连接超时时间 connect_timeout = 3 # 最大连接数 max_connections = 4000 max_Connect_Errors = 1000000 mode=read-only # 后端服务器地址 destinations=192.168.64.33:3306,192.168.64.34:3306
[keepalive] interval = 60
[http_server] port=1806 [http_auth_realm:default_auth_realm] backend=default_auth_backend method=basic name=default_realm [rest_router] require_realm=default_auth_realm [rest_api] [http_auth_backend:default_auth_backend] backend=file filename=/usr/local/mysq-router/pwd/mysqlrouter.pwd [rest_routing] require_realm=default_auth_realm [rest_metadata_cache] require_realm=default_auth_realm
# 启动MySQL Router # mysqlrouter -c /usr/local/mysq-router/conf/mysqlrouter.conf # nohup mysqlrouter -c /usr/local/mysq-router/conf/mysqlrouter.conf & # 查看日志 # tail -f /usr/local/mysq-router/log/mysqlrouter.log
# 配置启动文件 # cat /usr/lib/systemd/system/mysqlrouter.service [Unit] Description=MySQL Router After=syslog.target After=network.target [Service] Type=simple User=mysql Group=mysql ExecStart=/usr/local/mysq-router/bin/mysqlrouter -c /usr/local/mysq-router/conf/mysqlrouter.conf PrivateTmp=true Restart=on-failure LimitNOFILE=102400 [Install] WantedBy=multi-user.target
# systemctl enable mysqlrouter # systemctl start mysqlrouter
|