■Scientific Linux 5.7でmysqld複数起動設定
 基本はCentOS5系と同じなのだが、省略できない手順がありそのままではmysqld_multiが起動できなかったため、改めて書いておく。CentOSよりも自動で処理してもらえる部分が少ないので注意。

1)設定ファイルを編集する
# cat /etc/my.cnf

[client]
#password = your_password
port = 13306
socket = /var/lib/mysql1/mysql.sock
default-character-set=utf8

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = rootpasswd

# The MySQL server
[mysqld1]
port = 13306
socket = /var/lib/mysql1/mysql.sock
pid-file = /var/lib/mysql1/host.pid
datadir = /var/lib/mysql1/
skip-locking
key_buffer = 96M
max_allowed_packet = 3M
table_cache = 128
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU’s*2 for thread_concurrency
thread_concurrency = 8
default-character-set=utf8
character_set_server=utf8
skip-federated
log-bin=mysql-bin

[mysqld2]
port = 13307
socket = /var/lib/mysql2/mysql.sock2
pid-file = /var/lib/mysql2/host.pid2
datadir = /var/lib/mysql2/
skip-locking
key_buffer = 96M
max_allowed_packet = 3M
table_cache = 128
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU’s*2 for thread_concurrency
thread_concurrency = 8
default-character-set=utf8
character_set_server=utf8
skip-federated
log-bin=mysql-bin

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

2)mysqld_multiで起動できるよう以下のコマンドを各datadirで行う
#/usr/bin/mysql_install_db –user=mysql –datadir=/var/lib/mysql1/
#/usr/bin/mysql_install_db –user=mysql –datadir=/var/lib/mysql2/

3)各mysqldを起動しパスワード設定を行う
# mysqld_multi start 1
# mysql –socket=/var/lib/mysql1/mysql.sock -u root
mysql> set password = password(‘rootpasswd’);
mysql> quit
# mysqld_multi stop 1
# mysqld_multi start 2
# mysql –socket=/var/lib/mysql2/mysql.sock -u root
mysql> set password = password(‘rootpasswd’);
mysql> quit
# mysqld_multi stop 2

4)起動確認を行う
# mysqld_multi start
# mysqld_multi stop

■php関連の設定方法
phpアプリのconfig.phpでの設定例
‘hostspec’ => ‘localhost:13306′,
 標準socketでない場合には
‘hostspec’ => ‘localhost:/var/lib/mysql2/mysql.sock2′,

デフォルトはバックアップ等も考慮してclients他3306で運用が望ましい

■起動scriptを設置する
起動用に /etc/init.d/に以下のscriptを配置

# vi /etc/init.d/mysqld_multi
—ここから
# cat /etc/init.d/mysqld_multi
#!/bin/sh
# Mysql daemon start/stop script.
#
# Usually this is put in /etc/init.d (at least on machines SYSV R4
# based systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/S01mysql.
# When this is done the mysql server will be started when the machine is started
# and shut down when the systems goes down.
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 90 90
# description: A very fast and reliable SQL database engine.
# The following variables are only set for letting mysql.server find things
# if you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf or other configuration files
MYSQLDIR=/usr
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:$MYSQLDIR/bin
export PATH
# See how we were called.
case “$1″ in
start)
echo -n “Starting mysqld: “
$MYSQLDIR/bin/mysqld_multi start 1,2
echo
;;
stop)
echo -n “Shutting down mysqld: “
$MYSQLDIR/bin/mysqld_multi stop 1,2
echo
;;
status)
$MYSQLDIR/bin/mysqld_multi report 1,2
;;
restart)
$0 stop
$0 start
;;
*)
echo “Usage: $0 {start|stop|restart|status}”
exit 1
esac
exit 0
–ここまで

作成したら実行権限を与える
# chmod +x /etc/init.d/mysqld_multi

実行可能か動作確認をする
# service mysqld_multi start
# service mysqld_multi stop

■自動起動時の設定を追加
元々のmysqldはオフに、mysqld_multiをオンに
mysqld_multi はリストにないので追加する

# chkconfig mysqld off
# chkconfig –add mysqld_multi
# chkconfig mysqld_multi on

#ntsysv で確認

,
とりあえず付けておく無駄ではなかったなまぁまぁ読めたちょっと役に立ったかなかなり良かったかも (まだ評価されていません)
Loading...