更新时间:2024-11-28 GMT+08:00
分享

Mysql配置示例

结合配置项说明,在配置文件或配置信息添加故障注入相关配置。

  • 配置文件示例config_mysql_chaos.yaml
props:
  version: v1
  appId: xxx
  monitorId: xxxx
  databaseName: xxxx
etcd:
  address: xxx.xxx.xxx.xxx:xxxx
  apiVersion: v3
  username: xxxx
  password: xxxx
  httpsEnable: false
# require
datasource:
  ds0:
    url: tcp(xxx.xxx.xxx.xxx:xxxx)/ds0
    username: xxxx
    password: xxxx
  ds0-slave0:
    url: tcp(xxx.xxx.xxx.xxx:xxxx)/ds0-slave0
    username: xxxx
    password: xxxx
  ds0-slave1:
    url: tcp(xxx.xxx.xxx.xxx:xxxx)/ds0-slave1
    username: xxxx
    password: xxxx
  ds1:
    url: tcp(xxx.xxx.xxx.xxx:xxxx)/ds1
    username: xxxx
    password: xxxx
  ds1-slave0:
    url: tcp(xxx.xxx.xxx.xxx:xxxx)/ds1-slave0
    username: xxxx
    password: xxxx
  ds1-slave1:
    url: tcp(xxx.xxx.xxx.xxx:xxxx)/ds1-slave1
    username: xxxx
    password: xxxx
# require
router:
  active: c0
  routeAlgorithm: single-read-write
  retry:
    times: 10
    delay: 50# ms
  nodes:
    c0:
      master: ds0
      loadBalance: RANDOM
      slaves:
        - ds0-slave0
        - ds0-slave1
    c1:
      master: ds1
      loadBalance: ROUND_ROBIN
      slaves:
        - ds1-slave0
        - ds1-slave1
chaos:
  active: true# 全局开关 默认false
  duration: 20
  interval: 100
  percentage: 100
  delayInjection:
    active: true
    percentage: 75
    timeMs: 1000
    jitterMs: 500
  errorInjection:
    active: true
    percentage: 20
  • 配置信息
func mysqlConfiguration() *config.ClusterConfiguration {
    return &config.ClusterConfiguration{
        Props: &mas.PropertiesConfiguration{
            Version: "v1",
            AppID: "xxx",
            MonitorID: "xxxx",
            DatabaseName: "xxx",
        },
        EtcdConfig: &etcd.EtcdConfiguration{
            Address: "xxx.xxx.xxx.xxx:xxxx",
            APIVersion: "v3",
            Username: "xxxx",
            Password: "xxxx",
            HTTPSEnable: false,
        },
        RouterConfig: &config.RouterConfiguration{
            Nodes: map[string]*config.NodeConfiguration{
              "dc0": {
                    Master: "ds0",
                    LoadBalance: "RANDOM",
                    Slaves: []string{"ds0-slave0","ds0-slave1"},
                },
            "dc1": {
                    Master: "ds1",
                    LoadBalance: "ROUND_ROBIN",
                    Slaves: []string{"ds1-slave0","ds1-slave1"},
                },
            },
            Active: "dc0",
            Retry: &config.RetryConfiguration{
                Times: "10",
                Delay: "50",
            },
            RouteAlgorithm: "single-read-write",
        },
        DataSource: map[string]*config.DataSourceConfiguration{
            "ds0": {
                URL:      "tcp(xxx.xxx.xxx.xxx:xxxx)/ds0",
                Username: "xxxx",
                Password: "xxxx",
            },
            "ds0-slave0": {
                URL:      "tcp(xxx.xxx.xxx.xxx:xxxx)/ds0-slave0",
                Username: "xxxx",
                Password: "xxxx",
            },
            "ds0-slave1": {
                URL:      "tcp(xxx.xxx.xxx.xxx:xxxx)/ds0-slave1",
                Username: "xxxx",
                Password: "xxxx",
            },
            "ds1": {
                URL:      "tcp(xxx.xxx.xxx.xxx:xxxx)/ds1",
                Username: "xxxx",
                Password: "xxxx",
            },
            "ds1-slave0": {
                URL:      "tcp(xxx.xxx.xxx.xxx:xxxx)/ds1-slave0",
                Username: "xxxx",
                Password: "xxxx",
            },
            "ds1-slave1": {
                URL:      "tcp(xxx.xxx.xxx.xxx:xxxx)/ds1-slave1",
                Username: "xxxx",
                Password: "xxxx",
            },
        },
        Chaos: &mas.InjectionProperties{
            Active:     true,
            Duration:   20,
            Interval:   100,
            Percentage: 100,
            DelayInjection: &mas.DelayInjection{
                Active:     true,
                Percentage: 75,
                TimeMs:     1000,
                JitterMs:   500,
            },
            ErrorInjection: &mas.ErrorInjection{
                Active:     true,
                Percentage: 20,
            },
        },
    }
}

相关文档