MMM (Mysql Multi Master) 


 설치



### monitor 서버 설치  (monitoring server)


useradd --comment "MMM Script owner" --shell /sbin/nologin mmmd

yum install -y mysql-mmm-*



필요한 설정파일


/etc/mysql-mmm


mmm_common.conf

active_master_role      writer


<host default>

    cluster_interface       eth0 (서버의 이더넷 카드)

    pid_path                /var/run/mysql-mmm/mmm_agentd.pid

    bin_path                /usr/libexec/mysql-mmm/

    replication_user        replicant

    replication_password    slave

    agent_user              mmm_agent

    agent_password          RepAgent

</host>


<host db1>

    ip      192.168.100.49

    mode    master

    peer    db2

</host>


<host db2>

    ip      192.168.100.50

    mode    master

    peer    db1

</host>


#<host db3>

#    ip      192.168.100.51

#    mode    slave

#</host>


<role writer>

    hosts   db1, db2

    ips     192.168.100.250

    mode    exclusive

</role>


<role reader>

    hosts   db1, db2

    ips     192.168.100.251, 192.168.100.252

    mode    balanced

</role>



mmm_mon.conf


<monitor>

    ip                  127.0.0.1

    pid_path            /var/run/mysql-mmm/mmm_mond.pid

    bin_path            /usr/libexec/mysql-mmm

    status_path         /var/lib/mysql-mmm/mmm_mond.status

    ping_ips            192.168.100.50

    auto_set_online     60


    # The kill_host_bin does not exist by default, though the monitor will

    # throw a warning about it missing.  See the section 5.10 "Kill Host 

    # Functionality" in the PDF documentation.

    #

    # kill_host_bin     /usr/libexec/mysql-mmm/monitor/kill_host

    #

</monitor>


<host default>

    monitor_user        mmm_monitor

    monitor_password    RepMonitor

</host>


debug 0




/etc/init.d/mysql-mmm-monitor  (실행 스크립트)


# Cluster name (it can be empty for default cases)

CLUSTER=''


### DB서버에 설치해야되는 것들



### mmm scripts 설치


useradd --comment "MMM Script owner" --shell /sbin/nologin mmmd

yum install -y mysql-mmm-agent


서버에 mmm_common.conf 파일을 다 동일한 내용으로 넣어줘야한다.


master 서버 설정에 


bind-address = 0.0.0.0

auto_increment_increment = 2

auto_increment_offset = 2


이 부분을 master 1번서버는 홀수, 2번서버는 짝수로 넣어줘야 db 입력되는 순서에 문제가 생기지 않는다.


log-bin                         = /data/mysql/binlog/mysql-bin
log-bin-index                   = /data/mysql/binlog/mysql-bin.index
relay-log                       = /data/mysql/binlog/mysql-relay-bin
relay-log-index                 = /data/mysql/binlog/mysql-relay-bin.index

log-slave_updates               = 1

그 이외에 위의 binlog 부분이랑 relaylog 부분을 넣어준다.

설치한 서버에 mysql 권한을 주어야 함


GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'10.0.0.%' IDENTIFIED BY 'RepMonitor';
ㄴ mmm_mon.conf 파일에 입력되어있는 설정값

GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'10.0.0.%'   IDENTIFIED BY 'RepAgent';
ㄴ mmm_common.conf 파일에 입력되어있는 설정값

flush privileges;





/etc/mysql-mmm/mmm_agent.conf


include mmm_common.conf


# The 'this' variable refers to this server.  Proper operation requires 

# that 'this' server (db1 by default), as well as all other servers, have the 

# proper IP addresses set in mmm_common.conf.

this servername



위의 내용들은 설정파일들과, 설정파일에서 수정해야 되는 부분들을 작성해둔 내용이다.

mmm 설치의 대략적인 내용은

1. mmm_monitor 설치 -> monitor에서 2개의 설정파일과 실행스크립트 복사 및 수정작업

============================================================================

root@mmm-wf-01:/etc/mysql-mmm> ll

-rw-r----- 1 root root  786 Sep 16  2013 mmm_common.conf.org
-rw-r----- 1 root root  623 May  9 15:21 mmm_common_9702.conf
-rw-r----- 1 root root  786 Sep 11  2015 mmm_common_9703.conf
-rw-r----- 1 root root  915 Jan  7 16:31 mmm_common_9704.conf
-rw-r----- 1 root root  792 Aug  5  2015 mmm_common_9705.conf
-rw-r----- 1 root root  661 Oct 27  2015 mmm_common_9706.conf


-rw-r----- 1 root root  827 Sep 16  2013 mmm_mon.conf.org
-rw-r----- 1 root root  723 May  9 15:26 mmm_mon_9702.conf
-rw-r----- 1 root root  755 Jan  7 17:11 mmm_mon_9703.conf
-rw-r----- 1 root root  491 Jan  7 16:43 mmm_mon_9704.conf
-rw-r----- 1 root root  765 Jan  7 17:08 mmm_mon_9705.conf
-rw-r----- 1 root root  730 Oct 27  2015 mmm_mon_9706.conf



root@mmm-wf-01:/etc/mysql-mmm> netstat -lpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 10.0.0.33:9702            0.0.0.0:*                   LISTEN      23535/mmm_mond-9702
tcp        0      0 10.0.0.33:9703            0.0.0.0:*                   LISTEN      23412/mmm_mond-9703
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      1563/snmpd          
tcp        0      0 10.0.0.33:9704            0.0.0.0:*                   LISTEN      26959/mmm_mond-9704
tcp        0      0 10.0.0.33:9705            0.0.0.0:*                   LISTEN      23299/mmm_mond-9705
tcp        0      0 10.0.0.33:9706            0.0.0.0:*                   LISTEN      17554/mmm_mond-9706 
tcp        0      0 0.0.0.0:4949                0.0.0.0:*                   LISTEN      2878/perl           
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1577/sshd           
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      3842/nrpe           
tcp        0      0 :::22                       :::*                        LISTEN      1577/sshd           
tcp        0      0 :::5666                     :::*                        LISTEN      3842/nrpe           
udp        0      0 0.0.0.0:161                 0.0.0.0:*                               1563/snmpd          
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     8018   1/init              @/com/ubuntu/upstart



root@mmm-wf-01:/etc/mysql-mmm> ll /etc/init.d/mysql-mmm-*
-rwxr-xr-x 1 root root 1687 Sep 16  2013 /etc/init.d/mysql-mmm-agent
-rwxr-xr-x 1 root root 1907 Sep 16  2013 /etc/init.d/mysql-mmm-monitor
-rwxr-xr-x 1 root root 1910 May  9 15:23 /etc/init.d/mysql-mmm-monitor_9702
-rwxr-xr-x 1 root root 1913 Oct 26  2015 /etc/init.d/mysql-mmm-monitor_9703
-rwxr-xr-x 1 root root 1912 Jan  7 16:34 /etc/init.d/mysql-mmm-monitor_9704
-rwxr-xr-x 1 root root 1916 Jan  7 17:07 /etc/init.d/mysql-mmm-monitor_9705
-rwxr-xr-x 1 root root 1912 Oct 27  2015 /etc/init.d/mysql-mmm-monitor_9706
root@mmm-wf-01:/etc/mysql-mmm>


root@mmm-wf-01:/etc/mysql-mmm> cat /etc/init.d/mysql-mmm-monitor_9702

.

.

.

# Cluster name (it can be empty for default cases)

CLUSTER='9702'

.
.
.


root@mmm-wf-01:/etc/mysql-mmm> cat mmm_common_9702.conf

active_master_role      writer

<host default>
    cluster_interface       eth0
    pid_path                /var/run/mysql-mmm/mmm_agentd.pid
    bin_path                /usr/libexec/mysql-mmm/
    replication_user        replication
    replication_password    replication_password
    agent_user              mmm_agent
    agent_password          agent_password
</host>

.
.
.


root@mmm-wf-01:/etc/mysql-mmm> cat mmm_mon_9702.conf 


include mmm_common_9702.conf


<monitor>

    ip                  10.0.0.33

    pid_path            /var/run/mysql-mmm/mmm_mond-9702.pid

    port 9702

    bin_path            /usr/libexec/mysql-mmm

    status_path         /var/lib/mysql-mmm/mmm_mond-9702.status

    ping_ips            db1, db2

    auto_set_online     60


    # The kill_host_bin does not exist by default, though the monitor will

    # throw a warning about it missing.  See the section 5.10 "Kill Host 

    # Functionality" in the PDF documentation.

    #

    # kill_host_bin     /usr/libexec/mysql-mmm/monitor/kill_host

    #

</monitor>


<host default>

    monitor_user        mmm_monitor

    monitor_password    monitor_password

</host>


debug 0

============================================================================

2. 대상 서버들 mmm-agent 설치작업 진행
(mster db 2대, slave 서버들 n개 모두 설치 및 설정파일 공유)

root@slave-03:/root> cat /etc/mysql-mmm/mmm_common.conf   

해당 파일은 이더넷 장치값 이외의 다른 설정파일은 전부 동일 내용으로 되어 있어야함

active_master_role      writer 


<host default>

    cluster_interface       eth0   (해당 서버의 이더넷 장치값)

    pid_path                /var/run/mysql-mmm/mmm_agentd.pid

    bin_path                /usr/libexec/mysql-mmm/

    replication_user        replication
    replication_password    replication_password
    agent_user              mmm_agent
    agent_password          agent_password

</host>


<host master-01>

    ip      10.0.0.11

    mode    master

    peer    master-02

</host>


<host master-02>

    ip      10.0.0.12

    mode    master

    peer    master-01

</host>


<host slave-01>

    ip                      10.0.0.13

    mode                    slave

</host>


<host slave-02>

    ip                      10.0.0.14

    mode                    slave

</host>


<host slave-03>

    ip                      10.0.0.15

    mode                    slave

</host>


<role writer>

    hosts   master-01, master-02

    ips     10.0.0.111

    mode    exclusive

</role>

root@slave-03:/root> 


root@slave-03:/root> cat /etc/mysql-mmm/mmm_agent.conf
ㄴ this 값이 위의 설정값중 host 값과 일치해야함

include mmm_common.conf


# The 'this' variable refers to this server.  Proper operation requires 

# that 'this' server (db1 by default), as well as all other servers, have the 

# proper IP addresses set in mmm_common.conf.

this slave-03


root@master-02:/data/mysql> root_mysql  (서버접근 alias)

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 9142

Server version: 5.5.37-log Source distribution


Copyright (c) 2000, 2014, 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.


mysql> GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'10.0.0.%' IDENTIFIED BY 'monitor_password';

mysql> GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'10.0.0.%'   IDENTIFIED BY 'agent_password';


mysql> flush privileges;



mysql> CHANGE MASTER TO MASTER_HOST='10.0.0.11', MASTER_USER='replication', MASTER_PASSWORD='replication_password', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000309', MASTER_LOG_POS=208573385;

mysql> slave start;

mysql> show slave status \G


위와같은 작업을 서버마다 진행 (slave 서버는 replication 말고 monitor, agent 유저 등록만 진행

root@mcrm-02:/data/mysql> cat /usr/local/mysql/my.cnf
.
.
.

bind-address = 0.0.0.0
auto-increment-increment = 2
auto-increment-offset = 2


.
.
.

master-01 서버는 auto-increment-offset 값을 1로 수정



root@mmm-wf-01:/etc/mysql-mmm> mmm_control @9702 checks

slave-02  ping         [last change: 2016/04/10 07:41:06]  OK

slave-02  mysql        [last change: 2016/01/07 16:49:27]  OK

slave-02  rep_threads  [last change: 2016/01/07 16:49:27]  OK

slave-02  rep_backlog  [last change: 2016/04/06 12:32:39]  OK: Backlog is null

master-02  ping         [last change: 2016/03/21 23:38:54]  OK

master-02  mysql        [last change: 2016/03/21 23:38:54]  OK

master-02  rep_threads  [last change: 2016/01/08 15:45:01]  OK

master-02  rep_backlog  [last change: 2016/03/28 19:08:55]  OK: Backlog is null

master-01  ping         [last change: 2016/01/07 16:49:27]  OK

master-01  mysql        [last change: 2016/01/07 16:49:27]  OK

master-01  rep_threads  [last change: 2016/01/07 16:59:26]  OK

master-01  rep_backlog  [last change: 2016/01/07 16:49:27]  OK: Backlog is null

slave-03  ping         [last change: 2016/01/07 16:49:27]  OK

slave-03  mysql        [last change: 2016/01/07 16:49:27]  OK

slave-03  rep_threads  [last change: 2016/01/07 16:49:27]  OK

slave-03  rep_backlog  [last change: 2016/04/06 12:32:54]  OK: Backlog is null

slave-01  ping         [last change: 2016/05/06 18:37:25]  OK

slave-01  mysql        [last change: 2016/05/07 14:07:07]  OK

slave-01  rep_threads  [last change: 2016/01/07 16:49:27]  OK

slave-01  rep_backlog  [last change: 2016/05/07 14:05:04]  OK: Backlog is null


root@mmm-wf-01:/etc/mysql-mmm> 




root@master-01:/root> ip a s

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

    link/ether 00:1e:0b:dc:35:c8 brd ff:ff:ff:ff:ff:ff

    inet 10.0.0.11/24 brd 10.0.0.255 scope global eth0

    inet 10.0.0.111/32 scope global eth0

    inet6 fe80::21e:bff:fedc:35c8/64 scope link 

       valid_lft forever preferred_lft forever

3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000

    link/ether 00:1e:0b:dc:35:c9 brd ff:ff:ff:ff:ff:ff

root@master-01:/root> 


위와같이 설정해놓은 대표 IP가 자동으로 설정됨

'Linux > Document' 카테고리의 다른 글

swap size  (0) 2017.03.09
keepalived + haproxy + dns  (0) 2016.04.07
mariadb galera cluster 10.0 centos 6.x + LVS(LB)  (0) 2016.03.25
ubuntu banner 설정  (0) 2016.03.04
glusterFS  (0) 2016.03.04


### Keepalived install


mkdir /root/src

cd /root/src


wget http://keepalived.org/software/keepalived-1.2.20.tar.gz


tar xfz keepalived-1.2.20.tar.gz


cd keepalived-1.2.20


./configure && make && make install




ln -s /usr/local/etc/keepalived /etc/keepalived

ln -s /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/keepalived

ln -s /usr/local/etc/sysconfig/keepalived /etc/sysconfig/keepalived



vi /etc/rc.d/init.d/keepalived 


daemon /usr/local/sbin/keepalived

PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/sbin


# 설정 파일

global_defs {

    router_id haproxy-01

}


vrrp_script haproxy {

  script "killall -0 haproxy"

  interval 2

  weight 2

}


vrrp_instance 임의로 {

    state MASTER

    interface eth0

    virtual_router_id 50

    priority 200

    advert_int 1

    virtual_ipaddress {

        10.0.0.100 (사용할 VIP)

    }

   track_script {

       haproxy

   }

}



### haproxy install

useradd haproxy -s /sbin/nologin


wget http://www.haproxy.org/download/1.6/src/haproxy-1.6.4.tar.gz

tar xfz haproxy-1.6.4.tar.gz

cd haproxy-1.6.4

make TARGET=linux2628 && make install


cp /usr/local/sbin/haproxy /usr/sbin/

cp ./examples/haproxy.init /etc/init.d/haproxy

chmod 755 /etc/init.d/haproxy

mkdir -p /etc/haproxy

mkdir -p /run/haproxy

mkdir -p /var/lib/haproxy

touch /var/lib/haproxy/stats


vi /etc/haproxy/haproxy.cfg


### 

global

    log         127.0.0.1 local2

    chroot      /var/lib/haproxy

    pidfile     /var/run/haproxy.pid

    maxconn     4000

    user        haproxy

    group       haproxy

    daemon


    # turn on stats unix socket

    stats socket /var/lib/haproxy/stats


defaults

    option                  redispatch

    retries                 3

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout check           10s

    maxconn                 3000


listen http

    bind *:80

    acl rose_acl hdr_beg(host) -i rose

    use_backend rose if rose_acl



backend rose

    mode http

    cookie  SERVERID insert indirect nocache

    option  forwardfor header X-Real-IP

    option  http-server-close

    option  httplog

    balance     roundrobin

    server  rose1 서버01:80 check cookie rose1

    server  rose2 서버02:80 check cookie rose2

    server  rose3 서버03:80 check cookie rose3



### 커널 튜닝

sysctl.conf


net.ipv4.ip_forward = 1


net.ipv4.conf.eth0.arp_ignore = 1

net.ipv4.conf.eth0.arp_announce = 2




### DNS

yum -y install bind bind-utils bind-libs bind-chroot


vi /etc/named.conf


acl trust {

    사용할대역;

    10.0.0.0/24;

};


options {

        listen-on port 53 { any; };

        directory       "/var/named";

        dump-file       "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        memstatistics-file "/var/named/data/named_mem_stats.txt";

        allow-query     { any; };

        allow-query-cache  { any; };

        allow-transfer  { any; };

        recursion no;

        allow-recursion { trust; };


        dnssec-enable yes;

        dnssec-validation yes;

        dnssec-lookaside auto;


        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";

};


logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

vi /etc/named.rfc1912.zones


zone "localhost.localdomain" IN {

        type master;

        file "named.localhost";

        allow-update { none; };

};


zone "localhost" IN {

        type master;

        file "named.localhost";

        allow-update { none; };

};


zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {

        type master;

        file "named.loopback";

        allow-update { none; };

};


zone "1.0.0.127.in-addr.arpa" IN {

        type master;

        file "named.loopback";

        allow-update { none; };

};


zone "0.in-addr.arpa" IN {

        type master;

        file "named.empty";

        allow-update { none; };

};


zone "사용할도메인" IN {
        type master;
        file "존파일";
        allow-update { any; };
        allow-transfer { any; };
};



vi 존파일


$TTL 1D

@ IN SOA @ rname.invalid. (

0 ; serial

1D ; refresh

1H ; retry

1W ; expire

3H ) ; minimum

IN NS 사용할도메인.

IN A 도메인IP

ns IN A 네임서버IP

rose IN A 도메인IP



'Linux > Document' 카테고리의 다른 글

swap size  (0) 2017.03.09
mmm  (0) 2016.05.09
mariadb galera cluster 10.0 centos 6.x + LVS(LB)  (0) 2016.03.25
ubuntu banner 설정  (0) 2016.03.04
glusterFS  (0) 2016.03.04

+ Recent posts