MySQL 관리 · 5 min read · Jan 29, 2026

하나의 phpMyAdmin 설치로 여러 MySQL 서버 관리하기 (SSL 암호화 사용)

하나의 phpMyAdmin 설치로 여러 MySQL 서버 관리하기 (SSL 암호화 사용)

버전 1.0
저자: Falko Timme
Twitter에서 나를 팔로우하세요

이 튜토리얼에서는 하나의 phpMyAdmin 설치로 여러 MySQL 서버를 관리하는 방법을 설명합니다. 보안상의 이유로 phpMyAdmin과 원격 MySQL 서버 간의 통신은 SSL 암호화를 사용합니다(로컬 MySQL 서버의 경우 phpMyAdmin과 MySQL 간의 통신이 서버를 벗어나지 않기 때문에 필요하지 않습니다). phpMyAdmin은 PHP로 작성된 무료 소프트웨어 도구로, 월드 와이드 웹을 통해 MySQL의 관리를 처리하는 데 사용됩니다. phpMyAdmin은 MySQL과의 다양한 작업을 지원합니다.

이것이 당신에게 작동할 것이라는 보장은 하지 않습니다!

1 사전 참고

이 튜토리얼에서는 두 개의 MySQL 서버를 관리하는 방법을 보여줍니다 - 하나는 로컬(local.example.com, IP 주소 192.168.0.100 - phpMyAdmin이 설치된 서버)이고, 다른 하나는 원격 서버(remote.example.com, IP 주소 192.168.0.101)입니다. phpMyAdmin이 이미 설치되어 있고(수동으로 또는 배포판의 패키지 관리자를 통해) 작동 중이라고 가정합니다(즉, phpMyAdmin을 통해 로컬 MySQL 서버를 관리할 수 있어야 합니다) - 여기서는 phpMyAdmin 설치에 대해서는 다루지 않겠습니다.

이 튜토리얼은 Debian Wheezy/Ubuntu 12.04를 기반으로 합니다. 다른 배포판의 경우 일부 경로를 조정해야 할 수 있지만 원리는 동일합니다.

2 원격 MySQL 서버에서 SSL 지원 활성화

remote.example.com:

MySQL에 로그인…

mysql -u root -p

… 그리고 MySQL 셸에서 다음 명령을 실행합니다:

show variables like '%ssl%';

출력이 다음과 같으면(둘 다 have_openssl과 have_ssl이 DISABLED로 표시됨)…

mysql> show variables like ’%ssl%’;
+—————+———-+
| Variable_name | Value    |
+—————+———-+
| have_openssl  | DISABLED |
| have_ssl      | DISABLED |
| ssl_ca        |          |
| ssl_capath    |          |
| ssl_cert      |          |
| ssl_cipher    |          |
| ssl_key       |          |
+—————+———-+
7 rows in set (0.00 sec)

mysql>

… 이는 MySQL이 SSL 지원으로 컴파일되었지만 현재 활성화되지 않았음을 의미합니다. 이를 활성화하려면 먼저 MySQL 셸을 종료합니다…

quit;

… 그리고 /etc/mysql/my.cnf를 엽니다:

vi /etc/mysql/my.cnf
  • 보안 기능 섹션([mysqld] 섹션 내)으로 스크롤하여 ssl이라는 단어가 포함된 줄을 추가합니다:

| | [...] # * 보안 기능 # # chroot를 원하시면 매뉴얼도 읽어보세요! # chroot = /var/lib/mysql/ # # SSL 인증서를 생성하기 위해 OpenSSL GUI "tinyca"를 추천합니다. ssl # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [...] | |

MySQL을 재시작합니다…

/etc/init.d/mysql restart

… 그리고 SSL이 이제 활성화되었는지 다시 확인합니다:

mysql -u root -p
show variables like '%ssl%';

출력은 다음과 같아야 하며, 이는 SSL이 이제 활성화되었음을 의미합니다:

mysql> show variables like ’%ssl%’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| have_openssl  | YES   |
| have_ssl      | YES   |
| ssl_ca        |       |
| ssl_capath    |       |
| ssl_cert      |       |
| ssl_cipher    |       |
| ssl_key       |       |
+—————+——-+
7 rows in set (0.00 sec)

mysql>

입력…

quit;

…하여 MySQL 셸을 종료합니다.

OpenSSL이 설치되어 있는지 확인합니다:

apt-get install openssl

이제 OpenSSL 버전을 확인합니다:

root@remote:~# openssl version
OpenSSL 1.0.1c 10 May 2012
root@remote:~#

내가 OpenSSL 버전 1.0.1c를 사용하고 있다면, OpenSSL로 생성된 인증서는 다음과 같은 오류를 발생시킵니다:

Sep 18 17:02:15 remote mysqld: SSL error: Unable to get private key from ‘/etc/mysql/newcerts/server-key.pem’
Sep 18 17:02:15 remote mysqld: 120918 17:02:15 [Warning] Failed to setup SSL
Sep 18 17:02:15 remote mysqld: 120918 17:02:15 [Warning] SSL error: Unable to get private key

(원격 서버 remote.example.com의 /var/log/syslog에서) 및

root@local:/etc/mysql/newcerts# mysql –ssl-ca=/etc/mysql/newcerts/ca-cert.pem –ssl-cert=/etc/mysql/newcerts/client-cert.pem –ssl-key=/etc/mysql/newcerts/client-key.pem -h remote.example.com -u root -p
비밀번호 입력:
ERROR 2026 (HY000): SSL connection error: protocol version mismatch
root@local:/etc/mysql/newcerts#

(로컬 서버 local.example.com에서 원격 서버 remote.example.com에 암호화된 연결을 시도할 때) MySQL 5.5와 함께 발생합니다; 참조:

이 문제를 해결하기 위해, 우리는 단순히 자체 OpenSSL을 빌드합니다(당신의 OpenSSL 버전이 1.0.1보다 오래된 경우에는 필요하지 않습니다):

cd /tmp
wget http://www.openssl.org/source/openssl-0.9.8x.tar.gz
tar xvfz openssl-0.9.8x.tar.gz
cd openssl-0.9.8x
./config –prefix=/usr/local/openssl-0.9.8
make
make install

그 후, /usr/local/openssl-0.9.8/bin/openssl에서 새로운 OpenSSL 바이너리를 찾을 수 있습니다.

이제 SSL 연결에 필요한 CA, 서버 및 클라이언트 인증서를 생성합니다. 나는 먼저 /etc/mysql/newcerts 디렉토리에 이러한 인증서를 생성합니다:

mkdir /etc/mysql/newcerts && cd /etc/mysql/newcerts

CA 인증서 생성(여기서는 /usr/local/openssl-0.9.8/bin/openssl을 사용하고 있습니다; 시스템의 OpenSSL 버전이 1.0.1보다 오래된 경우 openssl을 사용하면 됩니다):

/usr/local/openssl-0.9.8/bin/openssl genrsa 2048 > ca-key.pem
/usr/local/openssl-0.9.8/bin/openssl req -new -x509 -nodes -days 1000 -key ca-key.pem > ca-cert.pem

서버 인증서 생성:

/usr/local/openssl-0.9.8/bin/openssl req -newkey rsa:2048 -days 1000 -nodes -keyout server-key.pem > server-req.pem
/usr/local/openssl-0.9.8/bin/openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem

클라이언트 인증서 생성:

/usr/local/openssl-0.9.8/bin/openssl req -newkey rsa:2048 -days 1000 -nodes -keyout client-key.pem > client-req.pem
/usr/local/openssl-0.9.8/bin/openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem

ls -l

…의 출력은 이제 다음과 같아야 합니다:

root@remote:/etc/mysql/newcerts# ls -l
total 32
-rw-r–r– 1 root root 1346 Sep 18 17:52 ca-cert.pem
-rw-r–r– 1 root root 1679 Sep 18 17:52 ca-key.pem
-rw-r–r– 1 root root 1099 Sep 18 17:53 client-cert.pem
-rw-r–r– 1 root root 1679 Sep 18 17:53 client-key.pem
-rw-r–r– 1 root root 956 Sep 18 17:53 client-req.pem
-rw-r–r– 1 root root 1099 Sep 18 17:53 server-cert.pem
-rw-r–r– 1 root root 1679 Sep 18 17:53 server-key.pem
-rw-r–r– 1 root root 956 Sep 18 17:53 server-req.pem
root@remote:/etc/mysql/newcerts#

이제 ca-cert.pem, client-cert.pem 및 client-key.pem을 로컬 MySQL 서버(local.example.com)로 전송해야 합니다; 이를 수행하기 전에 local.example.com에서 /etc/mysql/newcerts 디렉토리를 생성합니다:

local.example.com:

mkdir /etc/mysql/newcerts

다시

remote.example.com

으로 돌아가서, 세 개의 파일을

local.example.com

으로 전송할 수 있습니다:

remote.example.com:

scp /etc/mysql/newcerts/ca-cert.pem [email protected]:/etc/mysql/newcerts
scp /etc/mysql/newcerts/client-cert.pem [email protected]:/etc/mysql/newcerts
scp /etc/mysql/newcerts/client-key.pem [email protected]:/etc/mysql/newcerts

다음으로, /etc/mysql/my.cnf를 엽니다…

vi /etc/mysql/my.cnf

… 그리고 * 보안 기능 섹션을 수정합니다; ssl-ca, ssl-cert 및 ssl-key 줄의 주석을 제거하고 올바른 값을 입력합니다:

| | [...] # * 보안 기능 # # chroot를 원하시면 매뉴얼도 읽어보세요! # chroot = /var/lib/mysql/ # # SSL 인증서를 생성하기 위해 OpenSSL GUI "tinyca"를 추천합니다. ssl ssl-ca=/etc/mysql/newcerts/ca-cert.pem ssl-cert=/etc/mysql/newcerts/server-cert.pem ssl-key=/etc/mysql/newcerts/server-key.pem [...] | |

MySQL을 재시작합니다:

/etc/init.d/mysql restart

이제 다시 MySQL에 로그인합니다…

mysql -u root -p

… 그리고 SSL이 활성화되어 있고 올바른 인증서가 로드되었는지 확인합니다:

show variables like '%ssl%';

mysql> show variables like ’%ssl%’;
+—————+————————————-+
| Variable_name | Value                               |
+—————+————————————-+
| have_openssl  | YES                                 |
| have_ssl      | YES                                 |
| ssl_ca        | /etc/mysql/newcerts/ca-cert.pem     |
| ssl_capath    |                                     |
| ssl_cert      | /etc/mysql/newcerts/server-cert.pem |
| ssl_cipher    |                                     |
| ssl_key       | /etc/mysql/newcerts/server-key.pem  |
+—————+————————————-+
7 rows in set (0.00 sec)

mysql>

MySQL 셸을 종료하지 마세요. 이제 local.example.com에서 remote.example.com으로 연결할 수 있는 MySQL 루트 사용자를 생성하고 SSL을 사용해야 합니다:

CREATE USER ‘root’@’192.168.0.100’ IDENTIFIED BY ‘mysqlrootpassword’;
GRANT ALL PRIVILEGES ON . TO ‘root’@’192.168.0.100’ IDENTIFIED BY ‘mysqlrootpassword’ WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

GRANT USAGE ON *.* TO 'root'@'192.168.0.100' REQUIRE SSL;

CREATE USER ‘root’@’local.example.com’ IDENTIFIED BY ‘mysqlrootpassword’;
GRANT ALL PRIVILEGES ON . TO ‘root’@’local.example.com’ IDENTIFIED BY ‘mysqlrootpassword’ WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

GRANT USAGE ON *.* TO 'root'@'local.example.com' REQUIRE SSL;
FLUSH PRIVILEGES;

이제 MySQL 셸을 종료할 수 있습니다:

quit;

그게 다입니다 - 이제 local.example.com에서 remote.example.com으로 연결할 수 있는 MySQL 루트 사용자가 있으며, SSL 암호화를 사용해야 합니다.

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.