master_ip_failover : 실제 서비스 시 사용하는 프로그램, mha가 동작하여 failover 되면 해당 프로세스는 사라짐(crontab으로 재기동 필요)
master_ip_online_change : 수동으로 master와 slave를 전환하는 프로그램
mysql 5.7버전 실행파일(mysql, mysqlbinlog) : MySQL 8.x 버전의 경우 MHA에서 mysql/mysqlbinlog 호출 시 OS 7 버전의 openssql-1.0 버전과 호환되지 않아 명령어가 존재함에도 실행할 수 없다는 에러가 발생됨, openssl을 1.1 버전으로 업데이트는 8버전부터 제공되며, 8버전 설치파일을 7버전에 설치하는 부분도 권장되지 않음
mha 0.57 설치파일
구성도
각 OS를 편의상 manager(192.168.8.70), master(192.168.8.74), slave(192.168.8.75)로 통칭
master가 되는 mysql 서버에 Virtual Interface(192.168.8.80)가 up 상태로 존재
설치방법
mha OS 유저 생성(master/slave 모두 작업)
useradd -g mysql -G wheel mha passwd mha mha
mha OS 유저 생성(manager 작업, manager 서버의 mysql 그룹 및 wheel 그룹포함은 필수가 아니나, 빠른 설치 시 명령어 복사의 편리성을 위해서 아래처럼 수행)
groupadd mysql useradd -g mysql -G wheel mha passwd mha mha
mha profile 설정(manager/master/slave 모두 작업)
vi /home/mha/.bash_profile
# .bash_profile
# Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi
에러 발생 이유는 상단 준비물 mysql 5.7버전 실행파일(mysql, mysqlbinlog)에 작성
실행파일 변경(master/slave 작업)
su - cd /root/mha cp mysql /usr/bin/
cp mysqlbinlog /usr/bin/
chmod 775 /usr/bin/mysql
chmod 775 /usr/bin/mysqlbinlog
ls -l /usr/bin | grep mysql
check_repl 재수행(manager 수행)
masterha_check_repl --conf=/mysql_mha/app1.cnf
Can't exec "/mysql_mha/scripts/master_ip_failover": No such file or directory at /usr/share/perl5/vendor_perl/MHA/ManagerUtil.pm line 68. 에러 발생
다운받은 파일 복사하여 옮겨주기(manager 수행)
su - pwd ls -l cp master_ip_* /mysql_mha/scripts/ chown mha. /mysql_mha/scripts/* chmod 775 /mysql_mha/scripts/* #권한이 644인 경우도 Can`t exec 에러 발생함 ls -l /mysql_mha/scripts/
check_repl 재수행(manager 수행), 정상동작
masterha_check_repl --conf=/mysql_mha/app1.cnf
master_ip_failover 파일 수정(가상 vip 인터페이스 상황에 맞게 수정)
vi /mysql_mha/scripts/master_ip_failover
sudo ifconfig ens33:0 192.168.8.80/24 up #master/slave에서 동작하던 명령어 작성, ifup이라면 해당 형태로 작성 필요 sudo ifconfig ens33:$key $vip up #my $vip와 $key 변수에 넣은 값으로 치환
mha 엔진 스크립트 수정(manager 수행)
MHA에서 권고하는 Custom Script 수정과 함께, MHA failover의 서버 프로세스 정리 부문의 서버 비정상 종료 버그를 피하기 위해, MHA 매니저 설치 서버의 다음 엔진 스크립트 수정
su - vi /usr/share/perl5/vendor_perl/MHA/ManagerConst.pm
masterha_master_switch를 수행하기 위해서는 mha 매니저 프로세스가 종료되어야 함
mha 매니저가 올라와 있지 않은 상태에서 아래 명령어 수행
--orig_master_is_new_slave 옵션을 주게 되면 이전 마스터가 신규 마스터의 슬레이브로 설정되며, 이 옵션을 주지 않게 되면 이전 마스터는 신규 마스터의 슬레이브로 설정되지 않는다. --interactive=0 옵션을 주면 아래 실행 중 YES/NO를 묻지 않고 수행됨
\! hostname show slave status\G; show slave hosts\G;
새 접속창 띄워놓고 mha 로그 띄워두기(manager 수행)
tail -f /mysql_mha/log/mha.log
master 강제 종료(master 수행)
ps -ef | grep mysql kill -9 혹은 dbshutdown
tail 걸어둔 로그 확인 시, 아래와 같은 에러 발생 한다면
[error][/usr/share/perl5/vendor_perl/MHA/MasterFailover.pm, ln309] Last failover was done at 2022/07/19 00:06:40. Current time is too early to do failover again. If you want to do failover, manually remove /mysql_mha/manager/app1.failover.complete and run this script again.
yum 레포지토리 확인(centos 7.4 설치 후 default 설정된 repository)
cd /etc/yum.repos.d ls -l
MySQL 설치
yum -y install mysql-server
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022" 에러 발생하여 정상 다운되지 않은 경우, 아래 명령어 수행 및 다운로드 재시도
MySQL 8 버전은 서버 설치 과정에서 임시 비밀번호가 생성되며, 이 비밀번호로 접속이 가능
grep 'temporary password' /var/log/mysqld.log
MySQL 접속 및 비밀번호 입력
mysql -u root -p BQ;e2:?uiKxt
데이터 베이스 조회 시 에러 발생, ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
root 비밀번호 변경 필요, 비밀번호 조건이 까다롭기 때문에 단순하게 변경 시 변경 안됨
show databases; ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql'; ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mycentos74!@';
현재 설정 되어 있는 profile 확인
show variables like 'validate_password%';
설정된 profile을 변경 후 비밀번호 변경
SET GLOBAL validate_password.check_user_name=OFF; SET GLOBAL validate_password.policy=LOW; SET GLOBAL validate_password.length=0; show variables like 'validate_password%'; ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
해당 설정은 DB가 재기동 되면 초기화 되는 단점 존재
systemctl stop mysqld && systemctl start mysqld mysql -u root -p mysql show variables like 'validate_password%';