首页新闻招聘找找看知识库
  • cn2019
    2019-08-05 18:41 cn2019
    mariadb 主从复制mariadb 主从复制

    第1楼 回到顶楼
  • cn2019
    2019-08-05 18:41 cn2019
    进入主服务器容器
    1

    docker exec -ti -u root mariadb_master bash

    进入mariadb数据库
    1

    mysql -uroot -proot
    第2楼 回到顶楼
  • cn2019
    2019-08-05 18:42 cn2019
    show slave status\G;
    第3楼 回到顶楼
  • cn2019
    2019-08-05 18:46 cn2019
    CHANGE MASTER TO
    MASTER_HOST='172.17.0.3',MASTER_PORT=3306 ,MASTER_USER='slave1',
    MASTER_PASSWORD='slave1' ,MASTER_LOG_FILE='mariadb-bin.000002',
    MASTER_LOG_POS=2889;
    第4楼 回到顶楼
  • cn2019
    2019-08-05 18:51 cn2019
    /etc/my.cnf mysql-d server-id = 3
    第5楼 回到顶楼
  • cn2019
    2019-08-05 18:53 cn2019
    CHANGE MASTER TO
    MASTER_HOST='172.17.0.3',MASTER_PORT=3306 ,MASTER_USER='slave2',
    MASTER_PASSWORD='slave2' ,MASTER_LOG_FILE='mariadb-bin.000002',
    MASTER_LOG_POS=2889;
    第6楼 回到顶楼
  • cn2019
    2019-08-05 19:09 cn2019
    mysql 启动
    ./run.sh

    #!/bin/sh
    mysqld_safe

    第7楼 回到顶楼
  • cn2019
    2019-08-05 21:26 cn2019
    docker......................


    mycat-web 18082 172.17.0.6:8082
    mycat-web-zookeeper 12181 172.17.0.5:2181
    mycat-master2 19066 18066 10022 172.17.0.4:8066|9066|22 root/root testdb
    mycat-master1 9066 8066 172.17.0.7:8066|9066 root/root testdb
    mycat-master3 29066 28066 20022 172.17.0.8:8066|9066|22 root/root testdb

    mariadb_master1 13306 172.17.0.3:3306 root/root testdb w server-id= 1
    mariadb_slave1 23306 172.17.0.2:3306 root/root testdb r server-id =2
    mariadb_slave2 33306 172.17.0.9:3306 root/root testdb r server-id =3
    mariadb_slave3 43306 172.17.0.10:3306 root/root testdb r server-id =4



    主机MyCat服务登陆数据库,测试同步效果.
    #root@localhost
    mysql -uroot -proot -h 127.0.0.1 -P 19066
    mysql -uroot -proot -h 127.0.0.1 -P 29066


    主机登录MyCat代理端,测试读写分离服务.
    #root@localhost
    mysql -uroot -p123456 -h127.0.0.1 -P 18066
    mysql -uroot -p123456 -h127.0.0.1 -P 28066
    第8楼 回到顶楼
  • cn2019
    2019-08-05 21:34 cn2019
    mycat 1W3R
    schema.xml

    <schema name="testdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn_test" >

    </schema>
    <dataNode name="dn_test" dataHost="localhost1" database="testdb" />
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
    writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host=" mariadb_master1" url="172.17.0.3:3306" user="root"
    password="root">
    <!-- can have multi read hosts -->
    <readHost host="mariadb_slave1" url="172.17.0.2:3306" user="root" password="root" />
    <readHost host="mariadb_slave2" url="172.17.0.9:3306" user="root" password="root" />
    <readHost host="mariadb_slave3" url="172.17.0.10:3306" user="root" password="root" />
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    第9楼 回到顶楼
  • cn2019
    2019-08-05 21:38 cn2019
    主机 mysql -uroot -proot -h 127.0.0.1 -P 19066
    主机MyCat服务登陆数据库,测试同步效果.
    #root@localhost
    mysql -uroot -proot -h 127.0.0.1 -P 19066
    mysql -uroot -proot -h 127.0.0.1 -P 29066


    主机登录MyCat代理端,测试读写分离服务.
    #root@localhost
    mysql -uroot -p123456 -h127.0.0.1 -P 18066
    mysql -uroot -p123456 -h127.0.0.1 -P 28066
    第10楼 回到顶楼
  • cn2019
    2019-08-05 21:38 cn2019
    mysql -uroot -proot -h 127.0.0.1 -P 19066

    show @@heartbeat;
    show @@datasource;
    第11楼 回到顶楼
  • cn2019
    2019-08-05 23:10 cn2019
    **************************mariadb-slave***********************************
    1、docker run --privileged -it --name mariadb_slave3 -p 43306:3306 mariadb:1.0

    2、vi etc/my.cnf [mysqld]添加内容 server-id = 4

    #SHOW VARIABLES LIKE 'server_id';

    3、启 ./run.sh

    4、mysql -uroot -proot;

    stop slave;


    change master to master_host='172.17.0.3', master_user='slave2', master_password='slave2',master_port=3306, master_log_file='master-bin.000002', master_log_pos=10765;

    start slave;
    show slave status\G;
    SHOW VARIABLES LIKE 'server_id';

    5、进入容器mariadb_slave3
    docker exec -ti -u root mariadb_slave3 bash;
    第12楼 回到顶楼
  • cn2019
    2019-08-06 15:50 cn2019
    **************************mariadb-master***********************************
    1、docker run --privileged -it --name mariadb_master2 -p 8306:3306 mariadb:1.0

    2、vi etc/my.cnf [mysqld]添加内容 server-id = 8
    log_bin =master-bin

    #SHOW VARIABLES LIKE 'server_id';

    3、启 ./run.sh

    4、mysql -uroot -proot;

    SHOW VARIABLES LIKE 'server_id';
    show variables like '%log_bin%';

    create user 'slave2'@'%' identified by 'slave2';
    grant replication slave on *.* to 'slave2'@'%';
    flush privileges;

    show master status;

    5、进入容器mariadb_master2
    docker exec -ti -u root mariadb_master2 bash;
    第13楼 回到顶楼
  • cn2019
    2019-08-06 16:02 cn2019
    schema.xml

    <schema name="testdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn_test" >

    </schema>
    <dataNode name="dn_test" dataHost="localhost1" database="testdb" />
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
    writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host=" mariadb_master1" url="172.17.0.3:3306" user="root" password="root">
    <!-- can have multi read hosts -->
    <readHost host="mariadb_slave1" url="172.17.0.2:3306" user="root" password="root" />
    <readHost host="mariadb_slave2" url="172.17.0.9:3306" user="root" password="root" />
    <readHost host="mariadb_slave3" url="172.17.0.10:3306" user="root" password="root" />
    </writeHost>
    <writeHost host=" mariadb_master2" url="172.17.0.14:3306" user="root" password="root">
    <!-- can have multi read hosts -->
    <readHost host="mariadb_slave4" url="172.17.0.11:3306" user="root" password="root" />
    <readHost host="mariadb_slave5" url="172.17.0.12:3306" user="root" password="root" />
    <readHost host="mariadb_slave6" url="172.17.0.13:3306" user="root" password="root" />
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    第14楼 回到顶楼
  • cn2019
    2019-08-06 18:10 cn2019
    schema.xml

    <schema name="testdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn_test" >

    </schema>
    <dataNode name="dn_test" dataHost="localhost1" database="testdb" />
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
    writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host=" mariadb_master1" url="172.17.0.3:3306" user="root" password="root">
    <!-- can have multi read hosts -->
    <readHost host="mariadb_slave1" url="172.17.0.2:3306" user="root" password="root" />
    <readHost host="mariadb_slave2" url="172.17.0.9:3306" user="root" password="root" />
    <readHost host="mariadb_slave3" url="172.17.0.10:3306" user="root" password="root" />
    </writeHost>
    <writeHost host=" mariadb_master2" url="172.17.0.14:3306" user="root" password="root">
    <!-- can have multi read hosts -->
    <readHost host="mariadb_slave4" url="172.17.0.11:3306" user="root" password="root" />
    <readHost host="mariadb_slave5" url="172.17.0.12:3306" user="root" password="root" />
    <readHost host="mariadb_slave6" url="172.17.0.13:3306" user="root" password="root" />
    </writeHost>
    <writeHost host=" mariadb_master3" url="172.17.0.15:3306" user="root" password="root">
    <!-- can have multi read hosts -->
    <readHost host="mariadb_slave7" url="172.17.0.16:3306" user="root" password="root" />
    <readHost host="mariadb_slave8" url="172.17.0.17:3306" user="root" password="root" />
    <readHost host="mariadb_slave9" url="172.17.0.18:3306" user="root" password="root" />
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    第15楼 回到顶楼
  • cn2019
    2019-08-06 21:24 cn2019
    #mycat启动
    /usr/local/mycat/ ./mycat start
    # Native memory allocation (mmap) failed to 修改startup_nowrap.sh java -Xmx2048m -Xms521m
    第16楼 回到顶楼
  • cn2019
    2019-08-06 21:25 cn2019
    mycat logs/logtail -f wrapper.log
    第17楼 回到顶楼
  • cn2019
    2019-08-06 22:22 cn2019
    /usr/local/mycat/ ./mycat start
    # Native memory allocation (mmap) failed to
    wrapper.conf的配置文件:

    wrapper.java.additional.3=-XX:MaxPermSize=1024M
    wrapper.java.additional.5=-XX:MaxDirectMemorySize=4G
    # Initial Java Heap Size (in MB)
    wrapper.java.initmemory=512
    # Maximum Java Heap Size (in MB)
    wrapper.java.maxmemory=512

    第18楼 回到顶楼
  • cn2019
    2019-08-07 08:08 cn2019
    如果要正常退出不关闭容器,请按Ctrl+P+Q进行退出容器
    第19楼 回到顶楼
  • cn2019
    2019-08-07 08:16 cn2019
    docker exec -it mariadb_slave3 /root/run.sh
    第20楼 回到顶楼
  • cn2019
    2019-08-07 08:54 cn2019
    chmod u+x run.sh
    第21楼 回到顶楼
  • cn2019
    2019-08-07 09:32 cn2019
    docker inspect 容器名称或 id

    命令:docker inspect redismaster
    第22楼 回到顶楼
  • cn2019
    2019-08-07 09:52 cn2019
    /usr/sbin/sshd -D &
    第23楼 回到顶楼
  • cn2019
    2019-08-07 11:23 cn2019
    [root@localhost ~]# curl http://localhost:8082/mycat/


    7-4

    mycat-web注册zookeeper如下:

    vi/usr/local/mycat-web/mycat-web/WEB-INF/classes/mycat.properties

    zookeeper=172.17.0.5:2181


    ###
    cd /usr/local/mycat-web/

    ./start.sh &
    第24楼 回到顶楼
  • cn2019
    2019-08-08 11:12 cn2019
    #---------------------------------------------------------------------
    # Global settings
    #---------------------------------------------------------------------
    global
    log 127.0.0.1 local2 ###[err warning info debug]
    chroot /usr/local/haproxy
    pidfile /var/run/haproxy.pid ###haproxy的pid存放路径,启动进程的用户必须有权限访问此文件
    maxconn 4000 ###最大连接数,默认4000
    user haproxy
    group haproxy
    daemon ###创建1个进程进入deamon模式运行。此参数要求将运行模式设置为"daemon"

    #---------------------------------------------------------------------
    # common defaults that all the 'listen' and 'backend' sections will
    # use if not designated in their block
    #---------------------------------------------------------------------
    defaults
    mode http ###默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
    log global ###采用全局定义的日志
    option dontlognull ###不记录健康检查的日志信息
    option httpclose ###每次请求完毕后主动关闭http通道
    option httplog ###日志类别http日志格式
    option forwardfor ###如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip
    option redispatch ###serverId对应的服务器挂掉后,强制定向到其他健康的服务器
    timeout connect 10000 #default 10 second timeout if a backend is not found
    timeout client 300000 ###客户端连接超时
    timeout server 300000 ###服务器连接超时
    maxconn 60000 ###最大连接数
    retries 3 ###3次连接失败就认为服务不可用,也可以通过后面设置
    ####################################################################
    listen stats
    bind 0.0.0.0:1080 #监听端口
    stats refresh 30s #统计页面自动刷新时间
    stats uri /stats #统计页面url
    stats realm Haproxy Manager #统计页面密码框上提示文本
    stats auth admin:admin #统计页面用户名和密码设置
    #stats hide-version #隐藏统计页面上HAProxy的版本信息
    #---------------------------------------------------------------------
    # main frontend which proxys to the backends
    #---------------------------------------------------------------------
    frontend main
    bind 0.0.0.0:80
    acl url_static path_beg -i /static /images /javascript /stylesheets
    acl url_static path_end -i .jpg .gif .png .css .js

    use_backend static if url_static ###满足策略要求,则响应策略定义的backend页面
    default_backend dynamic ###不满足则响应backend的默认页面

    #---------------------------------------------------------------------
    # static backend for serving up images, stylesheets and such
    #---------------------------------------------------------------------

    backend static
    balance roundrobin ###负载均衡模式轮询
    server static 127.0.0.1:80 check ###后端服务器定义

    backend dynamic
    balance roundrobin
    server websrv1 10.252.97.106:80 check maxconn 2000
    server websrv2 10.117.8.20:80 check maxconn 2000

    #---------------------------------------------------------------------
    # round robin balancing between the various backends
    #---------------------------------------------------------------------
    #errorloc 503 http://www.osyunwei.com/404.html
    errorfile 403 /etc/haproxy/errorfiles/403.http
    errorfile 500 /etc/haproxy/errorfiles/500.http
    errorfile 502 /etc/haproxy/errorfiles/502.http
    errorfile 503 /etc/haproxy/errorfiles/503.http
    errorfile 504 /etc/haproxy/errorfiles/504.http
    第25楼 回到顶楼
  • cn2019
    2019-08-08 12:04 cn2019
    global
    maxconn 51200
    chroot /usr/local/haproxy
    uid 99
    gid 99
    daemon
    #quiet
    nbproc 1 #进程数
    pidfile /usr/local/haproxy/logs/haproxy.pid

    defaults
    mode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
    #retries 2 #两次连接失败就认为是服务器不可用,也可以通过后面设置
    option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
    option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
    timeout connect 5000ms #连接超时
    timeout client 30000ms #客户端超时
    timeout server 30000ms #服务器超时
    #timeout check 2000 #=心跳检测超时
    log 127.0.0.1 local0 err #[err warning info debug]
    balance roundrobin #负载均衡算法
    # option httplog #日志类别,采用httplog
    # option httpclose #每次请求完毕后主动关闭http通道,ha-proxy不支持keep-alive,只能模拟这种模式的实现
    # option dontlognull
    # option forwardfor #如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip

    listen admin_stats
    bind 0.0.0.0:8888 #监听端口
    option httplog #采用http日志格式
    stats refresh 30s #统计页面自动刷新时间
    stats uri /stats #统计页面url
    stats realm Haproxy Manager #统计页面密码框上提示文本
    stats auth admin:admin #统计页面用户名和密码设置
    #stats hide-version #隐藏统计页面上HAProxy的版本信息

    listen test1
    bind :12345
    mode tcp
    server t1 192.168.1.101:8881
    server t2 192.168.1.102:8881

    listen test2 :80
    option httpclose
    option forwardfor
    server s1 192.168.1.101:8080 check weight 1 minconn 1 maxconn 3 check inter 40000
    server s2 192.168.1.102:8080 check weight 1 minconn 1 maxconn 3 check inter 40000
    第26楼 回到顶楼
  • cn2019
    2019-08-08 15:30 cn2019
    -bash: service: command not found
    # yum list | grep initscripts
    # yum install initscripts
    第27楼 回到顶楼
  • cn2019
    2019-08-08 18:34 cn2019
    vi /usr/local/haproxy/conf/haproxy.cfg #编辑,修改



    global
    log 127.0.0.1 local0
    #log 127.0.0.1 local1 notice
    #log loghost local0 info
    maxconn 4096
    chroot /usr/local/haproxy
    pidfile /usr/data/haproxy/haproxy.pid
    uid 99
    gid 99
    daemon
    #debug
    #quiet

    defaults
    log global
    mode tcp
    option abortonclose
    option redispatch
    retries 3
    maxconn 2000
    timeout connect 5000
    timeout client 50000
    timeout server 50000


    listen proxy_status
    bind :48066
    mode tcp
    balance roundrobin
    server mycat_masert1 172.17.0.14:8066 check inter 10s
    #server mycat_2 192.168.1.60:8066 check inter 10s

    frontend admin_stats
    bind :8888
    mode http
    stats enable
    option httplog
    maxconn 10
    stats refresh 30s
    stats uri /admin
    stats auth admin:admin #登录用户
    stats hide-version
    stats admin if TRUE
    第28楼 回到顶楼
  • cn2019
    2019-09-18 00:27 cn2019
    点击查看大图
    第29楼 回到顶楼
登录后才能评论,请先登录注册