MySQL 리플리케이션을 한 서버 안에서 테스트해 보기 위해 한 서버 안에 MySQL을 2개 설치해 보았다.
동일 버전으로 2개를 설치하였다. 한 개의 MySQL을 설치할 때와 다르게 주의해야 할 점들이 몇 가지 있는데 그리 많진 않다.
① MySQL은 물론 서로 다른 경로에 설치해야 한다.
② 환경설정 파일인 my.cnf의 이름을 바꿀 수는 없는 모양이다. 각 MySQL마다 my.cnf 파일의 경로를 다르게 세팅하여야 한다. 컴파일 옵션으로 구분 지정 가능하다.
③ MySQL DB 디렉토리(예: /usr/local/mysql/data)는 두 MySQL 모두 mysql 소유권으로 동일하게 설정해야 한다. 하나는 mysql, 다른 하나는 mysql2 이렇게 잡아주고 구동하려니 안 되더라... 반드시 둘 다 mysql로!
④ 소켓 파일의 이름은 서로 다르게 지정해 주거나 경로를 달리해야 한다. 컴파일 시 옵션을 따로 주지 않으면 기본값으로 /tmp/mysql.sock로 잡힌다. 다른 하나는 /tmp/mysql2.sock 정도로 잡아준다.
⑤ 구동 포트 역시 서로 달라야 한다. 하나는 기본 포트인 3306, 다른 하나는 3306과는 다른 포트로 잡아준다.
그렇게 주의하면서 컴파일 설치해 보자(CentOS 5.6 32bit에 MySQL 5.0.45 설치 테스트).
1번 MySQL[root@localhost mysql-5.0.45]# ./configure \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--with-charset=euckr \
--with-mysql-user=mysql \
--with-extra-charsets=all \
--enable-thread-safe-client \
--with-unix-socket-path=/tmp/mysql.sock \
--with-tcp-port=3306 \
--sysconfdir=/usr/local/mysql/etc
[root@localhost mysql-5.0.45]# make && make install
[root@localhost mysql-5.0.45]# mkdir /usr/local/mysql/etc
[root@localhost mysql-5.0.45]# cp /usr/local/mysql/share/mysql/my-large.cnf /usr/local/mysql/etc/my.cnf
[root@localhost mysql-5.0.45]# /usr/loca/mysql/bin/mysql_install_db
[root@localhost mysql-5.0.45]# chown -R mysql.mysql /usr/local/mysql/data
[root@localhost mysql-5.0.45]# /usr/local/mysql/bin/mysqld_safe &
[root@localhost mysql-5.0.45]# /usr/local/mysql/bin/mysqladmin -u root password 123456
[root@localhost mysql-5.0.45]# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.45]# chown root.root /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.45]# chmod 700 /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.45]# /etc/rc.d/init.d/mysqld {start|stop|restart|reload|force-reload|status}
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--with-charset=euckr \
--with-mysql-user=mysql \
--with-extra-charsets=all \
--enable-thread-safe-client \
--with-unix-socket-path=/tmp/mysql.sock \
--with-tcp-port=3306 \
--sysconfdir=/usr/local/mysql/etc
[root@localhost mysql-5.0.45]# make && make install
[root@localhost mysql-5.0.45]# mkdir /usr/local/mysql/etc
[root@localhost mysql-5.0.45]# cp /usr/local/mysql/share/mysql/my-large.cnf /usr/local/mysql/etc/my.cnf
[root@localhost mysql-5.0.45]# /usr/loca/mysql/bin/mysql_install_db
[root@localhost mysql-5.0.45]# chown -R mysql.mysql /usr/local/mysql/data
[root@localhost mysql-5.0.45]# /usr/local/mysql/bin/mysqld_safe &
[root@localhost mysql-5.0.45]# /usr/local/mysql/bin/mysqladmin -u root password 123456
[root@localhost mysql-5.0.45]# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.45]# chown root.root /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.45]# chmod 700 /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.45]# /etc/rc.d/init.d/mysqld {start|stop|restart|reload|force-reload|status}
2번 MySQL
[root@localhost mysql-5.0.45]# ./configure \
--prefix=/usr/local/mysql2 \
--localstatedir=/usr/local/mysql2/data \
--with-charset=euckr \
--with-mysql-user=mysql \
--with-extra-charsets=all \
--enable-thread-safe-client \
--with-unix-socket-path=/tmp/mysql2.sock \
--with-tcp-port=3307 \
--sysconfdir=/usr/local/mysql2/etc
[root@localhost mysql-5.0.45]# make && make install
[root@localhost mysql-5.0.45]# mkdir /usr/local/mysql2/etc
[root@localhost mysql-5.0.45]# cp /usr/local/mysql2/share/mysql/my-large.cnf /usr/local/mysql2/etc/my.cnf
[root@localhost mysql-5.0.45]# /usr/loca/mysql2/bin/mysql_install_db
[root@localhost mysql-5.0.45]# chown -R mysql.mysql /usr/local/mysql2/data
[root@localhost mysql-5.0.45]# /usr/local/mysql2/bin/mysqld_safe &
[root@localhost mysql-5.0.45]# /usr/local/mysql2/bin/mysqladmin -u root password 123456
[root@localhost mysql-5.0.45]# cp /usr/local/mysql2/share/mysql/mysql.server /etc/rc.d/init.d/mysqld2
[root@localhost mysql-5.0.45]# chown root.root /etc/rc.d/init.d/mysqld2
[root@localhost mysql-5.0.45]# chmod 700 /etc/rc.d/init.d/mysqld2
[root@localhost mysql-5.0.45]# /etc/rc.d/init.d/mysqld2 {start|stop|restart|reload|force-reload|status}
--prefix=/usr/local/mysql2 \
--localstatedir=/usr/local/mysql2/data \
--with-charset=euckr \
--with-mysql-user=mysql \
--with-extra-charsets=all \
--enable-thread-safe-client \
--with-unix-socket-path=/tmp/mysql2.sock \
--with-tcp-port=3307 \
--sysconfdir=/usr/local/mysql2/etc
[root@localhost mysql-5.0.45]# make && make install
[root@localhost mysql-5.0.45]# mkdir /usr/local/mysql2/etc
[root@localhost mysql-5.0.45]# cp /usr/local/mysql2/share/mysql/my-large.cnf /usr/local/mysql2/etc/my.cnf
[root@localhost mysql-5.0.45]# /usr/loca/mysql2/bin/mysql_install_db
[root@localhost mysql-5.0.45]# chown -R mysql.mysql /usr/local/mysql2/data
[root@localhost mysql-5.0.45]# /usr/local/mysql2/bin/mysqld_safe &
[root@localhost mysql-5.0.45]# /usr/local/mysql2/bin/mysqladmin -u root password 123456
[root@localhost mysql-5.0.45]# cp /usr/local/mysql2/share/mysql/mysql.server /etc/rc.d/init.d/mysqld2
[root@localhost mysql-5.0.45]# chown root.root /etc/rc.d/init.d/mysqld2
[root@localhost mysql-5.0.45]# chmod 700 /etc/rc.d/init.d/mysqld2
[root@localhost mysql-5.0.45]# /etc/rc.d/init.d/mysqld2 {start|stop|restart|reload|force-reload|status}
각 MySQL의 구동 스크립트는 1번 MySQL은 /etc/rc.d/init.d/mysqld, 2번 MySQL은 /etc/rc.d/init.d/mysqld2가 되었다.
아래처럼 tcp 3306, 3307로 Listen status의 mysqld 데몬이 보인다면 정상~
[root@localhost ~]# netstat -ntlp | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 14014/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 4274/mysqld
[root@localhost ~]#
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 14014/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 4274/mysqld
[root@localhost ~]#
[root@localhost ~]# ps auxww | grep mysql
root 4241 0.0 0.0 5704 976 ? S May28 0:00 /bin/sh /usr/local/mysql2/bin/mysqld_safe --datadir=/usr/local/mysql2/data --pid-file=/usr/local/mysql2/data/localhost.pid
mysql 4274 0.0 0.1 387568 1856 ? Sl May28 0:10 /usr/local/mysql2/libexec/mysqld --basedir=/usr/local/mysql2 --datadir=/usr/local/mysql2/data --user=mysql --pid-file=/usr/local/mysql2/data/localhost.pid --skip-external-locking --port=3307 --socket=/tmp/mysql2.sock
root 12823 0.0 0.0 5140 708 pts/3 R+ 10:35 0:00 grep --color=auto mysql
root 13987 0.0 0.0 5704 544 ? S May27 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.pid
mysql 14014 2.8 10.1 807676 104056 ? Sl May27 66:49 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/localhost.pid --skip-external-locking --port=3306 --socket=/tmp/mysql.sock
[root@localhost ~]#
root 4241 0.0 0.0 5704 976 ? S May28 0:00 /bin/sh /usr/local/mysql2/bin/mysqld_safe --datadir=/usr/local/mysql2/data --pid-file=/usr/local/mysql2/data/localhost.pid
mysql 4274 0.0 0.1 387568 1856 ? Sl May28 0:10 /usr/local/mysql2/libexec/mysqld --basedir=/usr/local/mysql2 --datadir=/usr/local/mysql2/data --user=mysql --pid-file=/usr/local/mysql2/data/localhost.pid --skip-external-locking --port=3307 --socket=/tmp/mysql2.sock
root 12823 0.0 0.0 5140 708 pts/3 R+ 10:35 0:00 grep --color=auto mysql
root 13987 0.0 0.0 5704 544 ? S May27 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.pid
mysql 14014 2.8 10.1 807676 104056 ? Sl May27 66:49 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/localhost.pid --skip-external-locking --port=3306 --socket=/tmp/mysql.sock
[root@localhost ~]#