레이블이 mysql인 게시물을 표시합니다. 모든 게시물 표시
레이블이 mysql인 게시물을 표시합니다. 모든 게시물 표시

2022년 10월 21일 금요일

mysql to mariadb 업그레이드 수행

 

사전사항

  1. Centos6버전에서 사용할 수 있는 Mariadb는 Mariadb 10.5.16버전이 사용할 수 있는 최고 높은 버전(이후 버전은 glibc버전에 종속되어서 설치가 안됨)
  2. Cnetos7 / Rocky8버전에서는 Mariadb 10.6, 10.7버전 설치 가능 (OS교체까지 이루어지는 경우, 10.6이상으로 설치 / 운영하면 됨), 다만 업그레이드 plan은 Mariadb + Galera Cluster + Keepalived 구조가 아닌 Mariadb +  Replication + Mysql-MMM 구조로 유지
  3. Mariadb 10.0버전에서 gtid값에 slave pos를 저장하는 기능이 추가되었는데, gtid값을 이용해 리플리케이션 슬레이브모드에서 에러가 발생해도 sync할수 있도록 위치를 저장하는 테이블
    이 기존 mysql과는 다른 스키마로 되어 있어서 warning 메시지가 출력되기 때문에 추가 조치가 필요

작업절차

  1. DB#2에서 리플리케이션 중지

    mysql> stop slave;
    Query OK, 0 rows affected (0.007 sec)
  2. mysql-mmm-agent / mysql 프로세스 중지

    $> /etc/init.d/mysql-mmm-agent sotp
    $> /etc/init.d/mysqld stop
  3. DB데이터, DB엔진 데이터 백업

    $> mv /usr/local/mysql /usr/local/mysql_ori
    $> mv /home/data/mysql /home/data/mysql_ori
  4. Mariadb 엔진설치

    $> tar -zxvf mariadb-10.5.16-linux-x86_64.tar.gz  -C /usr/local/
    $> cd /usr/local/mariadb-10.5.16-linux-x86_64/ /usr/local/mysql
    $> cd /usr/local/mysql
    $> ./support-files/mysql.server start
  5. DB데이터 업그레이드

    $> cd /usr/local/mysql
    $> ./mysql_upgrade  -u root -p
    Enter password:
    MariaDB upgrade detected
    Phase 1/7: Checking and upgrading mysql database
    Processing databases
    mysql
    mysql.columns_priv                                 OK
    mysql.db                                           OK
    mysql.event                                        OK
    mysql.func                                         OK
    ...
    mysql.user                                         OK
    Upgrading from a version before MariaDB-10.1
    Phase 2/7: Installing used storage engines
    Checking for tables with unknown storage engine
    Phase 3/7: Fixing views from mysql
    Phase 4/7: Running 'mysql_fix_privilege_tables'
    Phase 5/7: Fixing table and database names
    Phase 6/7: Checking and upgrading tables
    Processing databases
    ...
    information_schema
    performance_schema
    Phase 7/7: Running 'FLUSH PRIVILEGES'
    OK
  6. 리플리케이션 재구성을 위한 테이블 정보 수정

    1. 리플리케이션 오류메시지 출력 확인

      mysql> show slave status \G;
      *************************** 1. row ***************************
      ...
                    Slave_IO_Running: Yes
                   Slave_SQL_Running: Yes
                   ...
                          Last_Errno: 1146
                          Last_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist
                        Skip_Counter: 0
                        ...
                       Last_IO_Errno: 0
                       Last_IO_Error:
                      Last_SQL_Errno: 1146
                      Last_SQL_Error: Unable to load replication GTID slave state from mysql.gtid_slave_pos: Table 'mysql.gtid_slave_pos' doesn't exist
         Replicate_Ignore_Server_Ids:
                    Master_Server_Id: 101
                      Master_SSL_Crl:
                  Master_SSL_Crlpath:
                          Using_Gtid: No
                         Gtid_IO_Pos:
             Replicate_Do_Domain_Ids:
         Replicate_Ignore_Domain_Ids:
                       Parallel_Mode: optimistic
                           SQL_Delay: 0
                 SQL_Remaining_Delay: NULL
             Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
                    Slave_DDL_Groups: 0
      Slave_Non_Transactional_Groups: 0
          Slave_Transactional_Groups: 0
      1 row in set (0.000 sec)
       
      ERROR: No query specified
    2. slave 중지

      mysql> stop slave;
      Query OK, 0 rows affected (0.007 sec)
    3. gtid테이블 form 파일 삭제

      $> rm -rf /home/data/mysql/mysql/gtid*
      
    4. gtid 테이블 재생성

      mysql> CREATE TABLE `gtid_slave_pos` (
      `domain_id` int(10) unsigned NOT NULL,
      `sub_id` bigint(20) unsigned NOT NULL,
      `server_id` int(10) unsigned NOT NULL,
      `seq_no` bigint(20) unsigned NOT NULL,
      PRIMARY KEY (`domain_id`,`sub_id`)
      ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Replication slave GTID state';
    5. slave 시작 후 리플리케이션 오류 수정 확인

      mysql> start slave;
      Query OK, 0 rows affected (0.007 sec)
       
      MariaDB [mysql]> show slave status\G
      *************************** 1. row ***************************
                      Slave_IO_State: Waiting for master to send event
      ...
                   Slave_SQL_Running: Yes
                     Replicate_Do_DB:
                 Replicate_Ignore_DB:
                  Replicate_Do_Table:
              Replicate_Ignore_Table:
             Replicate_Wild_Do_Table:
         Replicate_Wild_Ignore_Table:
                          Last_Errno: 0
                          Last_Error:
                        Skip_Counter: 0
                 Exec_Master_Log_Pos: 976074661
                     Relay_Log_Space: 5142886
                     Until_Condition: None
                      Until_Log_File:
                       Until_Log_Pos: 0
                  Master_SSL_Allowed: No
                  Master_SSL_CA_File:
                  Master_SSL_CA_Path:
                     Master_SSL_Cert:
                   Master_SSL_Cipher:
                      Master_SSL_Key:
               Seconds_Behind_Master: 0
       Master_SSL_Verify_Server_Cert: No
                       Last_IO_Errno: 0
                       Last_IO_Error:
                      Last_SQL_Errno: 0
                      Last_SQL_Error:
         Replicate_Ignore_Server_Ids:
                    Master_Server_Id: 101
                      Master_SSL_Crl:
                  Master_SSL_Crlpath:
                          Using_Gtid: No
                         Gtid_IO_Pos:
             Replicate_Do_Domain_Ids:
         Replicate_Ignore_Domain_Ids:
                       Parallel_Mode: optimistic
                           SQL_Delay: 0
                 SQL_Remaining_Delay: NULL
             Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
                    Slave_DDL_Groups: 0
      Slave_Non_Transactional_Groups: 0
          Slave_Transactional_Groups: 0
      1 row in set (0.000 sec)
  7. DB#1에서도 동일한 절차 반복 수행


참조

2022년 8월 1일 월요일

corosync / pacemaker 기반의 DB이중화

  1. 패키지 설치
  2. DB이중화 구성

    image-1658596268393.png


  3. DB 모니터링을  위한 스크립트 설치

    $> vi /etc/init.d/db_check
    #!/bin/bash
    
    case "$1" in
     "start")
       echo "start"
     ;;
     "stop")
       echo "stop"
     ;;
     "status")
      mysql --connect-timeout 2 -u monitor -p'모니터 계정패스워드' -h localhost -Nse 'select now()'
      result_code=$?
    
      if [[ $result_code -eq 1 ]]
      then
       echo "[$(date +%Y-%m-%d-%H:%M:%S)] DB Connection Error" >> /var/log/db_check
       pcs resource move DB_GROUP {{ 상대방IP }}
      fi
     ;;
     *)
       echo "start|stop|status"
       exit 1
     ;;
    esac
  4. DB이중화 구성을 위한 리소스 설정

    $> pcs cluster setup db_ha {{ DB1_IP }} {{ DB2_IP }} --force
    $> pcs cluster start --all
    $> pcs property set stonith-enabled=false
    $> pcs property set no-quorum-policy=ignore
    $> pcs resource defaults update resource-stickiness=100
    $> pcs resource create DB_CHECK service:db_check op status timeout=10s interval=10s --group DB_GROUP
    $> pcs resource create DB_VIP  ocf:heartbeat:IPaddr2 ip={{ DB_VIP }} cidr_netmask=32 op monitor interval=10s --group DB_GROUP


mytop 설치하기

mysql 프로세스 상태를 볼수 있는 유틸리티 mytop를 설치가이드

요구사항: Perl, DBI, DBD Mysql Module, Term::ReadKey

mytop은 기본적으로 show status와 show processlist를 CLI로 보여주는 프로그램입니다.


  1. 설치방법
  2. 패키지 설치

    $> yum install -y perl-TermReadKey
    $> yum install -y perl-DBI*

    1. dependency(DBI) 패키지 설치
      $> tar xvzf DBI-1.37.tar.gz
      $> cd DBI-1.37
      $> perl Makefile.PL
      $> make; make install
    2. dependency(DBD-Mysql) 패키지 설치
      $> tar xvzf DBD-Mysql-2.9003.tar.gz
      $> cd DBD-Mysql-2.9003
      $> perl Makefile.PL
      $> make; make install
    3. dependency(TermReadKey) 패키지 설치
      $> tar xvzf TermReadKey-2.21.tar.gz
      $> cd TermReadKey-2.21
      $> perl Makefile.PL
      $> make; make install
    4.  mytop 패키지 설치
      $> tar xvzf mytop-1.2.tar.gz
      $> cd mytop-1.2
      $> perl Makefile.PL
      $> make; make install
  3. 사용절차

    1. 사전설정
      # vi .mytop
      user=root
      pass=password
    2. 화면 출력값 공유
      d 특정 디비에 대해서만 보는 경우
      f 지정된 쓰레드가 실행중인 쿼리를 모두 출력
      h 간단히 보기
      i 쉬고있는 쓰레드는 리스트에서 제외
      k 쓰레드 연결을 종료
      m 초당 실행 쿼리수 보기
      p 화면 정지
      q mytop 종료
      r FLUSH STATUS 실행
      s 화면 갱신 시간 설정
      u 특정 사용자의 쓰레드만 보기
  4. 추가 FAQ

    • 추가 perl 관련 오류메시지 출력시
      yum install -y perl*
      
      perl -MCPAN -eshell
      install Term::ReadKey
      install DBI
      install DBD::mysql
    • 시작할 때 Error in option spec: “long|!” 출력시
      “long|!” => \$config{long_nums} 내용 주석처리 후 실행하면 됨
    • 다운로드 경로

mysqlcheck 유틸리티 사용법

 mysqlcheck 유틸리티 사용법(analyze, optimize, repair)

mysqlcheck 유틸리티 사용법

cost 베이스 DB에서 DB전체를 한번에 analyze, optimize, repair 하기 위한 유틸리티 입니다.

파일위치 : mysql/bin

----------------------------------------------------

전체 체크 및 자동 복구

mysqlcheck -Aa --auto-repair -u root -p

mysqlcheck -Ao --auto-repair -u root -p

----------------------------------------------------

-A, --all-databases

-a, --analyze

-o, --optimize

-P 포트번호

----------------------------------------------------

특정 데이터베이스만 체크 및 자동 복구

mysqlcheck --auto-repair -u root -p 데이터베이스명

----------------------------------------------------

특정 테이블만 체크 및 자동 복구

mysqlcheck --auto-repair -u root -p 데이터베이스명 테이블명

----------------------------------------------------

명령어 수정하여 사용하기

mysqlrepair = mysqlcheck --repair

mysqlanalyze = mysqlcheck --analyze

mysqloptimize = mysqlcheck --optimize

----------------------------------------------------

mysql에 접속하여 개별적으로 하는 방법

mysql> use 데이터베이스명;

mysql> show tables;

mysql> check table 테이블명;

mysql> repair table 테이블명;

mysql> analyze table 테이블명;

mysql> optimize table 테이블명;

----------------------------------------------------


출처 - http://igoni.kr/books/dbms/page/mysqlcheck


mysql에서 binlog 삭제

mysql에서 binlog 삭제하는 방법

  1. 특정날짜 이후의 로그값 삭제
     mysql>  "PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY)"
  2. 특정 binlog 삭제
     mysql> PURGE BINARY LOGS TO 'mysql-bin.000015';


mysql utf8설정

mysql에 utf8로 강제 설정

$> cat /etc/my.cnf
...
[client]
default-character-set = utf8

...
[mysqld]
init_connect = SET collation_connection = utf8_general_ci
init_connect = SET NAMES utf8
default-character-set = utf8
character-set-server = utf8
collation-server = utf8_general_ci

...
[mysqldump]
default-character-set = utf8

...



출처 - http://igoni.kr/books/dbms/page/mysql-utf8

Mysql root 사용자 패스워드 재설정 방법

  1. Mysql 서비스 종료
    $> killall mysqld
  2. Mysql 옵션 적용하여 재시작
    /usr/local/mysql/bin/mysqld_safe ~-~-skip-grant-tables &
    
     
  3. Mysql root 사용자 로그인
    $> /usr/local/mysql/bin/mysql -u root mysql
    * 정상적으로 수행될 경우 콘솔화면이 "mysql>" 으로 변경될 것입니다.
  4. root 패스워드 재지정 (Mysql 5.7이하 버전에서 사용하세요.)
    mysql> update user set password=password('변경할패스워드입력') where user = 'root';
    mysql> flush privileges;
    mysql> quit;

  5. 지정한 패스워드 입력하여 mysql 로그인
    /usr/local/mysql/bin/mysql -u root -p   



2022년 7월 31일 일요일

mysql replication 설정

  1. 5.5부터는 innodb를 기본엔진으로 사용하기 때문에, Myisam을 사용할 경우, 테이블 구성시 엔진타입을 따로 기재해 주어야 함.
    • Master1 : 192.168.20.11
    • Master2 : 192.168.20.12
  1. Mysql replication 구성하기(Dual Master)
  2. Master1 my.cnf파일 수정
    1. /etc/my.cnf파일에 해당 내용 추가하기
      $> vi /etc/my.cnf
      server-id       = 1
      binlog-do-db=wordpress (리플리케이션 사용할 DB명, 여러개의 DB일 경우, 한칸씩 띄우면 됨. wordpress mysql, 전체 DB를 복제할경우엔는 따로 설정하지않아도 됨)
  3. Master2 /etc/my.cnf파일에 내용 변경
    $> vi /etc/my.cnf
    server-id       = 2
    binlog-do-db=wordpress
  4. Master1에 master 플러그인 설치 및 활성화
    mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
    Query OK, 0 rows affected (0.00 sec)
    mysql> set global rpl_semi_sync_master_enabled=1;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set global rpl_semi_sync_master_timeout =1000;
    Query OK, 0 rows affected (0.00 sec)
    mysql> show variables like 'rpl_semi_sync%';
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~--+
    | Variable_name                      | Value |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~--+
    | rpl_semi_sync_master_enabled       | ON    |
    | rpl_semi_sync_master_timeout       | 1000  |
    | rpl_semi_sync_master_trace_level   | 32    |
    | rpl_semi_sync_master_wait_no_slave | ON    |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~--+
  5. Master2서버에서 쿼리 적용할 수 있게 권한 부여
    mysql> grant replication slave on *.* to 'repl_test'@'192.168.20.12' identified by 'repltest';
    \\Query OK, 0 rows affected (0.00 sec)
  6. Master2서버에 슬레이브 플러그인 설치 및 활성화
    mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
    mysql> set global rpl_semi_sync_slave_enabled=1;
    mysql> show variables like 'rpl_semi_sync%';
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--+~-~-~-~-~-~--+
    | Variable_name                   | Value |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--+~-~-~-~-~-~--+
    | rpl_semi_sync_slave_enabled     | ON    |
    | rpl_semi_sync_slave_trace_level | 32    |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~--+~-~-~-~-~-~--+
    2 rows in set (0.01 sec)
  7. Master1서버에서 접속할 수 있게 권한 설정
    mysql> grant replication slave on *.* to 'repl_test'@'192.168.20.11' identified by 'repltest';
  8. 양쪽 Master서버의 bin log, postion 초기화
    mysql> reset master;
  9. 각 서버 Master상태 확인
    # Master1에서 확인
    mysql> show master status;
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+
    | mysql-bin.000001 |      100 | wordpress    |                  |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+
    1 row in set (0.00 sec)
    

    # Master2에서 확인
    mysql> show master status;
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+
    | mysql-bin.000001 |      100 | wordpress    |                  |
    +~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-+~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-+
    1 row in set (0.00 sec)

  10. 양쪽 서버 Master연결 (File과 Position을 맞추면 됨)
    # Master1에서 수행
    mysql> change master to  master_host='192.168.20.12', master_user='repl_test', master_password='repltest', master_log_file='mysql-master-bin.000001', master_log_pos=100;


    # Master2에서 수행
    mysql> change master to  master_host='192.168.20.11', master_user='repl_test', master_password='repltest', master_log_file='mysql-master-bin.000001', master_log_pos=100;

  11. 각서버 연결상태확인
    Master1) 
    mysql> show slave status \G;
    *************************** 1. row ***************************
                   Slave_IO_State:
                      Master_Host: 192.168.20.12
                      Master_User: repl_test
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000001
              Read_Master_Log_Pos: 107
                   Relay_Log_File: ha1-relay-bin.000001
                    Relay_Log_Pos: 4
            Relay_Master_Log_File: mysql-bin.000001
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
                  Replicate_Do_DB:
              Replicate_Ignore_DB:
               Replicate_Do_Table:
           Replicate_Ignore_Table:
          Replicate_Wild_Do_Table:
      Replicate_Wild_Ignore_Table:
                       Last_Errno: 0
                       Last_Error:
                     Skip_Counter: 0
              Exec_Master_Log_Pos: 107
                  Relay_Log_Space: 107
                  Until_Condition: None
                   Until_Log_File:
                    Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File:
               Master_SSL_CA_Path:
                  Master_SSL_Cert:
                Master_SSL_Cipher:
                   Master_SSL_Key:
            Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error:
                   Last_SQL_Errno: 0
                   Last_SQL_Error:
      Replicate_Ignore_Server_Ids:
                 Master_Server_Id: 0
    1 row in set (0.00 sec)
    ERROR:
    No query specified

    Master2)
    mysql> show slave status \G;
    *************************** 1. row ***************************
                   Slave_IO_State:
                      Master_Host: 192.168.20.11
                      Master_User: repl_test
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: mysql-bin.000001
              Read_Master_Log_Pos: 107
                   Relay_Log_File: ha2-relay-bin.000001
                    Relay_Log_Pos: 4
            Relay_Master_Log_File: mysql-bin.000001
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
                  Replicate_Do_DB:
              Replicate_Ignore_DB:
               Replicate_Do_Table:
           Replicate_Ignore_Table:
          Replicate_Wild_Do_Table:
      Replicate_Wild_Ignore_Table:
                       Last_Errno: 0
                       Last_Error:
                     Skip_Counter: 0
              Exec_Master_Log_Pos: 107
                  Relay_Log_Space: 107
                  Until_Condition: None
                   Until_Log_File:
                    Until_Log_Pos: 0
               Master_SSL_Allowed: No
               Master_SSL_CA_File:
               Master_SSL_CA_Path:
                  Master_SSL_Cert:
                Master_SSL_Cipher:
                   Master_SSL_Key:
            Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
                    Last_IO_Errno: 0
                    Last_IO_Error:
                   Last_SQL_Errno: 0
                   Last_SQL_Error:
      Replicate_Ignore_Server_Ids:
                 Master_Server_Id: 0
    1 row in set (0.00 sec)
    ERROR:
    No query specified

Mysql innodb컴파일

Mysql 4버전은 innodb가 기본포함이지만, 5.1버전은 컴파일시 옵션을 넣어야 함.

$> ./configure --prefix=/usr/local/mysql \
--with-extra-charsets=all \
--with-readline \
--with-plugins=max \
--with-charset=utf8 \
--with-innodb  (혹은 --with-plugins=innobase)

설치 끝나고 innodb 포함 여부 확인은 mysql 접속해서 쿼리 날리면 됨

mysql> show variables like 'have_innodb';
+—————+——-+
| Variable_name | Value |
+—————+——-+
| have_innodb | YES |
+—————+——-+
1 row in set (0.00 sec)

show engines;
mysql> show engines;
+————+———+—————————————————————-+————–+——+————+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+————+———+—————————————————————-+————–+——+————+
| ndbcluster | NO | Clustered, fault-tolerant tables | NULL | NULL | NULL |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
+————+———+—————————————————————-+————–+——+————+
9 rows in set (0.00 sec)


출처 - http://igoni.kr/books/dbms/page/mysql-innodb

mysql grant실행시 access denied 발생시 조치방법

mysql 데이터 이전(재설치 이후) root로 로그인하여 쿼리 작업이 다른 쿼리는 정상적으로 적용되는데,
grant구문 실행하면 access denied 처리될때,
요롷게..???

mysql> grant all privileges on *.* to 'root'@'1.2.3.4' identified by '123123' with grant option;
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

구글링결과.. 데이터 이전 작업 중 먼가 호환이 안되었던 모양.
다음과같이 mysqlupgrade를 실행했다.

$> mysql_upgrade -u root -p
Enter password: …

이하 화면 생략… …
맨 마지막 화면은 Running ‘mysql_fix_privilege_tables’… OK
일단 OK떨어졌으니, 다시 grant 적용해보자.

mysql> grant all privileges on *.* to 'root'@'1.2.3.4' identified by '123123' with grant option;
Query OK, 0 rows affected (0.00 sec)

오…된다….ㅋㅋ
물론, grant 구문에 대한 적용도 된다.ㅎㅎㅎ



출처 - http://igoni.kr/books/dbms/page/mysql-grant-access-denied

2022년 7월 26일 화요일

centos7 galera cluster설치

  • DBMS교체(Mysql → Mariadb)를 추진하면서 이중화 구성을 replication 에서 galera_cluster로 전환하기 위해 구축하기 위한 문서

    시스템 소개

    1. Replication 기반의 데이터 동기화 방식
      • WEB/WAS →  DB#1 DDL 유입 (insert / modify / delete / ...)
      • DB#1서버는 binlog에 저장.
      • DB#2 서버는 IO Thread가 master서버로 접속해서 변경내용 확인 후 변경사항이 있으면 replication 로그에 저장
        1*.DB#2 서버는 SQL Thread가 replication 로그를 읽어서 변경사항 저장
    2. Galera Cluster기반의 데이터 동기화
      • wsrep api를 통해 DB#1, DB#2 접속 및 데이터 복제하기 위한 인터페이스 생성
      • WEB/WAS →  DB#1 DDL 유입 (insert / modify / delete / ...)
      • DB#1은 DB#2에도 DDL적용하라는 요청 후 모든 노드가 정상응답하면 DDL 저장
    3. 각 데이터 동기화 방식 비교


    replicationgalera

    동기화 방식
    비동기
    동기식
    단 점
    • 리플리케이션은 1개의 Thread만 수행
    • 데이터 불일치가 발생하는 경우 이중화 구성이 풀릴 수 있음
    • master binlog가 expire된 경우, 리플리케이션기반의 데이터 동기화 불가능
    • innodb만 지원
    • 테이블별로 PK가 존재해야 함. 없는 경우 데이터 순서의 차이가 있을수 있음
    운영노드
    2대(Active  / Standby 권장)
    3대이상 홀수 수량으로 사용 권장
    1. 서비스용 통신포트
    2. 포트정보사용용도통신방향
      tcp/3306
      DB데이터 통신포트
      WEB/WEB → DBMS
      tcp/4567, udp/4567
      DB노드별 연동상태 확인, 멀티캐스트로 복제시 해당 포트 사용(tcp/upd)
      DB1 ↔ DB2
      tcp/4568
      Galera 증분 데이터 전송
      DB1 ↔ DB2
      tcp/4444 
      Galera 전체 데이터 전송
      DB1 ↔ DB2

    Galera 용어 설명

    1. 데이터 동기화 방식
      • WSREP; Write Set REPlication - Innodb 엔진내부에서 Write Set(트랜잭션을 기록하는 데이터 그룹)
        1*.SST; State Snapshot Transfer - 전체 데이터 전송 (처음 클러스터 구성할 때 사용)
      • IST; Incremental State Transfer - 변경된 데이터 전송 (평상시 운영중일 때 사용)
    2. 클러스터 맴버
      • Donor : 전체 데이터를 가진 DB
      • Joiner : Donor로부터 데이터를 제공받는 노드
    3. 데이터 동기화 엔진
      • rsync : rsync기반으로 파일전송, 데이터 동기화 속도는 빠르나 데이터 동기화를 위해   Donor 서버에 데이터 Lock을 수행함
      • mariabackup ( 해당방식 권장) : mariabackup 유틸리티를 사용해 SST 수행, 백업 스트리밍을 위해 socat 패키지가 설치되어 있어야 함 Donor Lock를 최소화 한 방식,
      • xtrabackup (Mariadb 10.3이후로 제공암함, mariabackup 사용 권장)

    시스템 구축하기

    1. 설치환경
      • OS : Centos 7.5
      • DBMS : Mariadb 10.4.7
      • Galera : 4.26-4.2.1
    2. 작업순서
    3. galera rpm 설치(이슈사항 : Mariadb에 포함된 galera 플러그인 사용시 OPENSSL1.0.0이 없다는 에러메시지 발생
      #> yum install libaio socat Judy  ./galera-4-26.4.2 1.rhel7.el7.centos.x86_64
    4. /etc/my.cnf에 아래내용 적용
      [client]
      port            = 3306
      socket          = /tmp/mysql.sock
      
      [mysqld]
      user = mysql
      port            = 3306
      socket          = /tmp/mysql.sock
      skip-external-locking
      key_buffer_size = 384M
      max_allowed_packet = 1M
      table_open_cache = 512
      sort_buffer_size = 2M
      read_buffer_size = 2M
      read_rnd_buffer_size = 8M
      myisam_sort_buffer_size = 64M
      thread_cache_size = 8
      query_cache_size = 32M
      #thread_concurrency = 8
      expire_logs_days = 30
      wait_timeout = 60
      #skip-name-resolve
      basedir=/usr/local/mysql
      datadir=/data/db_data
      
      max_heap_table_size = 190M
      max_allowed_packet =  16M
      tmp_table_size = 64M
      join_buffer_size = 64M
      innodb_buffer_pool_size = 950M
      #innodb_doublewrite = 0
      innodb_flush_log_at_timeout = 3
      #innodb_read_io_threads = 32
      #innodb_write_io_threads = 16
      #character_set_client = utf8mb4
      
      #log-bin=mysql-bin
      
      server-id       = 2
      
      
      [galera]
      wsrep_on=ON
      #wsrep_provider=/usr/lib64/galera/libgalera_smm.so
      wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
      wsrep_cluster_address="gcomm://172.21.113.109,172.21.113.69" #클러스터 구성할 IP
      binlog_format=row
      default_storage_engine=InnoDB
      innodb_autoinc_lock_mode=2
      wsrep_cluster_name=cluster
      wsrep_node_address="172.21.113.109"  #자기 IP가 작성되어 있으면 됨
      bind-address=0.0.0.0
      wsrep_sst_method=mariabackup
      wsrep_sst_auth="root:root"
      wsrep_provider_options="pc.bootstrap=YES"


    5. mysql_install_db 실행 
      #> /usr/local/mysql/scripts/mysql_install_db
      Installing MariaDB/MySQL system tables in '/data/db_data' ...
      wsrep loader: [INFO] wsrep_load(): loading provider library 'none'
      OK
      
      To start mysqld at boot time you have to copy
      support-files/mysql.server to the right place for your system
      
      
      Two all-privilege accounts were created.
      One is root@localhost, it has no password, but you need to
      be system 'root' user to connect. Usefor example, sudo mysql
      The second is mysql@localhost, it has no password either, but
      you need to be the system 'mysql' user to connect.
      After connecting you can set the passwordif you would need to be
      able to connect as any of these users with a password and without sudo
      
      See the MariaDB Knowledgebase at http://mariadb.com/kb or the
      MySQL manual for more instructions.
      
      You can start the MariaDB daemon with:
      cd '/usr/local/mysql' ; /usr/local/mysql/bin/mysqld_safe --datadir='/data/db_data'
      
      You can test the MariaDB daemon with mysql-test-run.pl
      cd '/usr/local/mysql/mysql-test' ; perl mysql-test-run.pl
      
      Please report any problems at http://mariadb.org/jira
      
      The latest information about MariaDB is available at http://mariadb.org/.
      You can find additional information about the MySQL part at:
      http://dev.mysql.com
      Consider joining MariaDB's strong and vibrant community:
      https://mariadb.org/get-involved/


    6. Mysql Secuinstall 구성
      # /usr/local/mysql/bin/mysql_secure_installation
      
      NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
            SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
      
      In order to log into MariaDB to secure it, we'll need the current
      password for the root user. If you've just installed MariaDB, and
      haven't set the root password yet, you should just press enter here.
      
      Enter current password for root (enter for none):
      OK, successfully used password, moving on...
      
      Setting the root password or using the unix_socket ensures that nobody
      can log into the MariaDB root user without the proper authorisation.
      
      You already have your root account protected, so you can safely answer 'n'.
      
      Switch to unix_socket authentication [Y/n] n
      ... skipping.
      
      You already have your root account protected, so you can safely answer 'n'.
      
      Change the root password? [Y/n] y
      New password:
      Re-enter new password:
      Password updated successfully!
      Reloading privilege tables..
      ... Success!
      
      
      By default, a MariaDB installation has an anonymous user, allowing anyone
      to log into MariaDB without having to have a user account created for
      them.  This is intended only for testing, and to make the installation
      go a bit smoother.  You should remove them before moving into a
      production environment.
      
      Remove anonymous users? [Y/n] y
      ... Success!
      
      Normally, root should only be allowed to connect from 'localhost'.  This
      ensures that someone cannot guess at the root password from the network.
      
      Disallow root login remotely? [Y/n] y
      ... Success!
      
      By default, MariaDB comes with a database named 'test' that anyone can
      access.  This is also intended only for testing, and should be removed
      before moving into a production environment.
      
      Remove test database and access to it? [Y/n] y
      - Dropping test database...
      ... Success!
      - Removing privileges on test database...
      ... Success!
      
      Reloading the privilege tables will ensure that all changes made so far
      will take effect immediately.
      
      Reload privilege tables now? [Y/n] y
      ... Success!
      
      Cleaning up...
      
      All done!  If you've completed all of the above steps, your MariaDB
      installation should now be secure.
      
      Thanks for using MariaDB!

    7. 클러스터 구성(최초로 구성하는 서버에서만 진행하면 됨
      # /usr/local/mysql/support-files/mysql.server start  --wsrep-new-cluster
      Starting MariaDB SUCCESS!
      190911 13:43:35 mysqld_safe Logging to '/data/db_data/localhost.err'.
      190911 13:43:35 mysqld_safe Starting mysqld daemon with databases from /data/db_data


    8. DB접속계정 권한 설정
      MariaDB [(none)]> grant all privileges on *.* to root@'localhost' identified by 'root' with grant option;

    9. 2번 서버에서 mysql 프로세스 실행
      # /usr/local/mysql/support-files/mysql.server start
      Starting MariaDB.190911 13:51:30 mysqld_safe Logging to '/data/db_data/localhost.err'.
      190911 13:51:30 mysqld_safe Starting mysqld daemon with databases from /data/db_data
      ................ SUCCESS!
    10. Glaracluster 재실행시 마지막으로 종료된 노드를 찾아서 해당 노드에 new-cluster를 추가하면 된다
      $> cat /data/db_data/grastate.dat
      # GALERA saved state
      version: 2.1
      uuid:    fbb2c143-8b5e-11ec-8ea1-36a72f3e94f3
      seqno:   -1
      #마지막에 종료된 노드가 1로 표기되어 있다.
      safe_to_bootstrap: 1
      • bootstrap을 1로 기재된 서버에 --wsrep-new-cluster를 붙여서 실행하고, 아닌 서버는 그냥 실행시키면 된다.


    Reference 

adfit

AI들끼리 대화하기

ChatGPT, perplexity, Gemini... 많은 AI 서비스가 있고 서비스별로 다양한 엔진이 있죠. 문득 AI끼리 대화를 시켜보면 어떤 대화의 흐름을 이어갈까 궁금해졌습니다. 그래서 해보았습니다. 규 칙 나(사람)은 양쪽 AI에서...