우분투 16.04에서 MySQL을 쓰다가 우분투 18.04로 업그레이드한 다음 MySQL을 지우고 MariaDB로 전환했습니다. PPA 추가 없이 APT 저장소에 있는 기본 패키지로 교체했고요.

우분투 업그레이드 이후 패키지 의존성들이 거하게 깨져서 손보는 게 번거로웠는데, MySQL도 예외는 아니어서 apt-get purge 명령어로 지웠는데도 찌꺼기가 남아 MariaDB를 괴롭히더군요. MariaDB 설치 후 서비스 시작 명령어를 입력했더니 아래와 같은 에러 메세지들이 떴습니다.


root@계정명:~# service mysql start

Job for mariadb.service failed because a timeout was exceeded.

See "systemctl status mariadb.service" and "journalctl -xe" for details.


root@계정명:~# journalctl -xe

 9월 23 19:47:41 계정명 kernel: audit: type=1400 audit(1537699661.510:72): apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" e

 9월 23 19:47:41 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:41 계정명 kernel: audit: type=1400 audit(1537699661.610:73): apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" e

 9월 23 19:47:41 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:41 계정명 kernel: audit: type=1400 audit(1537699661.710:74): apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" e

 9월 23 19:47:41 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:41 계정명 kernel: audit: type=1400 audit(1537699661.810:75): apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" e

 9월 23 19:47:42 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:42 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:42 계정명 kernel: audit: type=1400 audit(1537699662.710:76): apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" e

 9월 23 19:47:42 계정명 kernel: audit: type=1400 audit(1537699662.710:77): apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" e

 9월 23 19:47:42 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:43 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:43 계정명 audit[3818]: AVC apparmor="DENIED" operation="sendmsg" info="Failed name lookup - disconnected path" error=-13 profile="/usr/sbin/mysqld

 9월 23 19:47:43 계정명 systemd[1]: mariadb.service: Failed with result 'timeout'.

 9월 23 19:47:43 계정명 systemd[1]: Failed to start MariaDB 10.1.34 database server.

-- Subject: Unit mariadb.service has failed

-- Defined-By: systemd

-- Support: http://www.ubuntu.com/support

--

-- Unit mariadb.service has failed.

--

-- The result is RESULT.



ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

등등...

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

검색해보니 AppArmor라는 것은 프로그램 별로 역량을 제한할 수 있는 리눅스 커널 보안 모델이라고 하더군요.

일단, 위 링크에 있는 ERROR 2002 해결 방편은 저에게 효과가 없었습니다.

위 링크에 소개된 임시 방편들 중 제일 마지막에 있는 것이 효과가 있었는데요,
(터미널 창에 아래의 명령을 입력.)
ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
Then reboot(그리고 재부팅.)

mysqld 를 화이트리스트 처리하겠다는 것인데, “잘 돌아가기만 하면 땡이다!”는 마인드면 이걸로 끝내면 되겠지만

바르게 고치고 넘어가야 직성이 풀리는 성격이라(;;;) MariaDB 지우고 MySQL 찌꺼기들까지 완전히 없앤 다음 MariaDB 재설치하는 쪽으로 결정했습니다(사서 고생.).



아래처럼 진행했어요.


mysqldump 명령어로 DB를 백업.

( sudo mysqldump -u DB계정명 -p DB명 > 원하는파일명.sql )


/etc/apparmor.d/disable/ 에 생성했던 심볼릭링크 삭제.

( sudo rm /etc/apparmor.d/disable/usr.sbin.mysqld )


MariaDB 삭제

( sudo apt-get purge mariadb-* )


남아 있는 의존성 패키지들 자동 제거

( sudo apt autoremove )



이제부터 본격적으로 MySQL 찌꺼기 제거.


dpkg -l | grep mysql

해보니까 mysql-common 이 보이길래


sudo apt-get purge mysql-common

명령어로 삭제.

그런데 삭제 과정에서 아래 메세지가 뜨길래

dpkg: 경고: while removing mysql-common, directory '/etc/mysql' not empty so not removed

rm -r /etc/mysql/
명령어로 /etc/mysql/ 디렉토리를 수동 삭제.


sudo find / -name '*mysql*'

명령어로 mysql 이름이 붙은 파일/디렉토리들을 검색하고, 삭제할 것들을 추려냄.

sudo rm -r /var/lib/mysql-5.7

명령어로 /var/lib/mysql-5.7 디렉토리를 수동 삭제.

sudo rm /etc/apparmor.d/cache/usr.sbin.mysqld

명령어로 /etc/apparmor.d/cache/usr.sbin.mysqld 파일을 수동 삭제.

/etc/apparmor.d/abstractions/mysql

(위 파일은 혹시 몰라서 놔둠. MySQL 설치 안 한 가상머신에서도 기본으로 보이길래...)

sudo reboot

재부팅.


https://jimnong.tistory.com/744

대로 mariadb 재설치

sudo service --status-all

해보니까 mysql 이 + 표시되어 있음. OK.

systemctl status mariadb.service

해보니까 Active: active (running) 라고 표시. 에러 안 뜨니까 성공!


아래 명령을 참고해서 워드프레스 DB 복원 시도.

mysql -u root -p

SHOW DATABASES;

CREATE DATABASE 'DB명';

\q 입력해서 빠져나옴.

mysql -u DB계정명 -p DB명 < 백업된파일명.sql


워드프레스 작동 테스트 통과.


조치 끝.


끝까지 읽어주셔서 감사합니다.

개념만 보면 별 게 없네요. 완전 삭제 후 재설치.

apparmor 화이트리스트 등록 이외의 방법을 찾는 분들께 도움이 되었으면 좋겠습니다.

반응형