PaceMaker+DRBD構築5 【MySQL設定(ノード1)】
対象:DBサーバ(1台)my.cnfの基本設定
DRBDのプライマリがノード1にあることを確認する。roが[Primary/Secondary]となっていることを確認。
# cat /proc/drbd
version: 8.4.2 (api:1/proto:86-101)
GIT-hash: 7ad5f850d711223713d6dcadc3dd48860321070c build by root@dkpdb-01, 2012-11-06 15:33:13
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:4718628 nr:0 dw:4718628 dr:86838 al:1309 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
※roが[Secondary/ Primary]となっている場合は、別ノードがDRBDのプライマリとなっている。
# mount -t ext4 /dev/drbd0 /dbmy.cnfをレプリケーションディレクトリ(/db/mysql)上に配置し、/etc/my.cnfにリンクを張る。
# mkdir /db/mysql -p # ln -s /db/mysql/my.cnf /etc/my.cnf
# vi /etc/my.cnf
[mysqld] ##---- 基本設定 ------------------------ port = 3306 socket = /opt/app/mysql/tmp/mysql.sock back_log = 50 default-character-set = utf8 #skip-character-set-client-handshake ##---- 制限 ------------------------ max_connections = 100 max_connect_errors = 10 wait_timeout = 28800 ##---- チューニング ------------------------ table_open_cache = 2048 max_allowed_packet = 16M binlog_cache_size = 1M max_heap_table_size = 64M read_buffer_size = 2M read_rnd_buffer_size = 16M sort_buffer_size = 4M join_buffer_size = 4M thread_cache_size = 8 thread_concurrency = 8 query_cache_type = ON query_cache_min_res_unit = 4K query_cache_size = 64M query_cache_limit = 2M key_buffer_size = 32M tmp_table_size = 64M thread_stack = 192K #skip-bdb skip-name-resolve ##---- ストレージエンジン ------------------------ default-storage-engine = INNODB #default-table-type = INNODB innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 2G innodb_data_file_path = ibdata1:10M:autoextend innodb_write_io_threads = 8 innodb_read_io_threads = 8 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 8M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 # LOG関連 log-bin=mysql-bin binlog_format=mixed expire-logs-days=7 slow_query_log long_query_time = 2 log-queries-not-using-indexes log-error=/db/mysql/logs/mysqld.log server-id = 1 ft_min_word_len = 4 transaction_isolation = REPEATABLE-READ #Function対応(Function作成時のみ) #log_bin_trust_function_creators=1 #Myisam関連 bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover※「skip-character-set-client-handshake」は脆弱性の根源であるためコメントアウトする
データベースの初期化と確認
■データベースの初期化 mysql_install_dbスクリプトはmysqlデータベースにuser、db、host、tables_priv、columns_privテーブルを作る# mkdir /db/mysql ; cd /db/mysql/ # /opt/app/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/app/mysql/※mysql_install_dbは実行したディレクトリにdataディレクトリを作成される。
# /opt/app/mysql/tmp/ # chown -R mysql:mysql /opt/app/mysql/. # chown -R mysql:mysql /db/mysql/data/Mysqlログディレクトリと運用を考慮して、/var/log/にシンボリックリンクを作成する
# mkdir /var/log/mysql # ln -s /var/log/mysql /db/mysql/logs # chown mysql:mysql /var/log/mysql
# cd /usr/local/src/mysql-5.5.25a # cp support-files/mysql.server /etc/init.d/mysqld # chmod 755 /etc/rc.d/init.d/mysqld # chkconfig --add mysqld ;chkconfig mysqld off # chkconfig --list|grep mysql mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
/var/log/mysql/mysqld.log /var/log/mysql/log_slow_queries.log { missingok weekly dateext rotate 48 }
# /etc/rc.d/init.d/mysqld start Starting MySQL [ OK ]
# view /var/log/mysql/mysqld.log
PaceMaker+DRBD構築5 【MySQL設定(ノード2)】
ここで説明する手順はDRBDのセカンダリ側のノードのみで行う。DRBDのスイッチオーバ
■ノード1のDRBDをセカンダリにする(ノード1上で実行)# drbdadm secondary all
# drbdadm primary all
# mount -t ext4 /dev/drbd0 /db
# mkdir /var/log/mysql # chown mysql:mysql /var/log/mysql
# cd /usr/local/src/mysql-5.5.25a # cp support-files/mysql.server /etc/init.d/mysqld # chmod 755 /etc/rc.d/init.d/mysqld # chkconfig --add mysqld ;chkconfig mysqld off # chkconfig --list|grep mysql mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
/var/log/mysql/mysqld.log /var/log/mysql/log_slow_queries.log { missingok weekly dateext rotate 48 }
PaceMaker+DRBD構築5 【Mysqlインストール後の整備】
MySQLをインストールした後に、基本セキュリティ設定やDB作成を行う。Mysqlの簡易セキュリティ設定
MySQLのインストール直後は、特権ユーザroot にパスワードが設定されていないので、rootのパスワード設定、不要なアカウントとDB削除する必要があります。# export PATH="$PATH:/opt/app/mysql/bin/"
# /opt/app/mysql//bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):Enter OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!※赤字の箇所を入力
# /opt/app/mysql/bin/mysql -p
Heartbeatのヘルスチェック用DB作成
Mysqlを起動した状態でDBとTabaleを作成する。#/opt/app/mysql/bin/mysql mysql>create database chk_db ; mysql> grant Select on chk_db.* to chk_user@localhost identified by '7h9_dbts';
/opt/app/mysql/bin/mysql mysql> grant Select on mysql.* to chk_user@localhost identified by '7h9_dbts'; mysql> grant PROCESS,SUPER,REPLICATION CLIENT on *.* to chk_user@localhost identified by '7h9_dbts';
mysql>CREATE TABLE `chk_tbl` ( `chk` varchar(2) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;※HeartbeatのヘルスチェックはTableの存在の有無のみをチェックしているので、カラム名は任意です。
PaceMaker+DRBD構築 の目次
01. PaceMaker+DRBD構築 【PaceMakerのインストール】