2012年6月19日火曜日

さくらのVPS1G移設作業 mysql(CentOS6.2)

前回の基本設定からの続きでmysqlのインストールと設定


■mysqlインストール
○なんだか設定失敗した様子でMYSQLが動かない、だいぶ嵌ったので再インストールしました。

・mysqlをアンインストール
# yum remove mysql mysql-server mysql-devel
# ll /usr/share/mysql/
# ll /var/lib/mysql/
なんだかフォルダが色々残っている。

完全クリーンインストールしたいのでフォルダごと削除してみる。
# rm -rf /usr/share/mysql
# rm -rf /var/lib/mysql

・mysqlをインストール
# yum install mysql mysql-server mysql-devel
# /etc/init.d/mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...
120607 15:44:48 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.
120607 15:44:48 [ERROR] Can't find messagefile '/usr/share/mysql/english/errmsg.sys'
120607 15:44:48 [ERROR] Aborting

120607 15:44:48 [Note] 

Installation of system tables failed!  Examine the logs in
/var/lib/mysql for more information.

You can try to start the mysqld daemon with:

    shell> /usr/libexec/mysqld --skip-grant &

and use the command line tool /usr/bin/mysql
to connect to the mysql database and look at the grant tables:

    shell> /usr/bin/mysql -u root mysql
    mysql> show tables

Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in /var/lib/mysql that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us!  And remember, if
you do mail us, you MUST use the /usr/bin/mysqlbug script!

[失敗]
起動失敗!"[ERROR] Can't find messagefile '/usr/share/mysql/english/errmsg.sys'"とあるので完全クリーンインストールしようとして、"/usr/share/mysql"を消したのが原因か?

フォルダを確認する
# ll /usr/share/mysql/
確かに、たくさんあったディレクトリが1コも無い
"'/usr/share/mysql/english/errmsg.sys'"等一式のファイルは"mysql-libs"に含まれているっぽいので、"mysql-libs"を再インストールしてみる
# yum -reinstall mysql-libs
# ll /usr/share/mysql/
色々なフォルダが復活!
各種errmsg.sysファイルが復旧した様子!!

今までは、こんな事しなかったのだが、
きっと昔はyumで"mysql mysql-server mysql-devel"を再インストールすると依存関係でmysql-libsも再インストールされていたが途中から変わったのかな?
とにかく随分ハマッてしまった。

気を取り直してmysql起動
# /etc/init.d/mysqld restart
mysqld を停止中:  [  OK  ]
MySQL Daemon failed to start.
mysqld を起動中:  [失敗]
またも起動失敗_| ̄|○
ログに以下の記述を発見
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

と言うことで以下を実行する。
# mysql_install_db
# /etc/init.d/mysqld start
mysqld を起動中:  [  OK  ]
起動成功!!!
これでようやくmysqlが初期状態になったはず

2012年6月12日火曜日

さくらのVPS1G移設作業 基本設定(CentOS6.2)

さくらのVPS512が、大幅グレードアップした なんとメモリ2倍(512M→1G)!! 旧VPS512の料金980円だったのだが、新プランではVPS1Gが利用可能 こちらは、なんとメモリ2倍の1Gに加えHDDは5倍(20G→100G)なんて太っ腹!! 以前のコストパフォーマンスもなかなか良いと思っていたが、 メモリ1G HDD100Gで980円だとコストパフォーマンス3倍くらい? 今回の移設の様子を見て、近くのサーバーから順次移設するのかな?また忙しくなりそうだ それはさて置き、そのまま使ってもメモリは1Gに増設になるのだが、すでにHDD80%弱を消費している状況、 HDDを5倍にするには再契約してサーバー移設作業が必要なので、面倒だがサーバー移設を行う。 ■サーバー初期設定 ○新サーバーのCentOSのバージョン確認
# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m

# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m

# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m
すると6.2、旧サーバーは5.5でした。 きっと、同じバージョンで作業したほうが楽なのだが、「きっと色々ハマるんだろうな~」と思いながらイバラの道を進んでみる。 主な移設項目 MYSQL ZABBIX Redmine XOOPS SVN よく512Mのメモリでこんなに動いてたもんだ、チューニングしつつ綱渡り的な運用だったので、 今回はギリギリのチューニングしなくても安定動作してくれることを願う。 ○ユーサー設定 とりあえずrootログイン&rootパスワード変更

# passwd
Changing password for user root.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

# useradd -m hoge
# passwd hoge
Changing password for user hoge.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
この接続を残したまま 作成したユーザーhogeで新規SSH接続&su

$ su -
Password: 
※万が一rootとhoge共にパスワードタイプミスした時にレスキューモードで起動とかは面倒なので、 ログインできてかつ、suに成功してから、rootログインの接続を切る ○SSHポート変更

# cd /etc/ssh/
# mkdir /etc/ssh/00Backup
# cp /etc/ssh/sshd_config /etc/ssh/00Backup/sshd_config_`date +%Y%m%d%H%M`
# vi /etc/ssh/sshd_config
# diff sshd_config 00Backup/sshd_config_201205301253
14d13
< Port 2022

# /etc/init.d/sshd restart
Stopping sshd: [  OK  ]
Starting sshd: [  OK  ]
○ファイアーウォール設定

# vi ~/iptables-init.sh
# cat ~/iptables-init.sh
#!/bin/sh

iptables -F
iptables -X

iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

iptables -A INPUT -s 10.0.0.0/8 -j DROP
iptables -A INPUT -s 172.16.0.0/12 -j DROP
iptables -A INPUT -s 192.168.0.0/16 -j DROP

# iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

iptables -A INPUT -p tcp --dport 20022 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# sh ~/iptables-init.sh
# iptables -L

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
DROP       all  --  10.0.0.0/8           anywhere
DROP       all  --  172.16.0.0/12        anywhere
DROP       all  --  192.168.0.0/16       anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:2022
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

# iptables-save > /etc/sysconfig/iptables
# /etc/init.d/ssh   iptables rs estart
iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Unloading modules: [  OK  ]
iptables: Applying firewall rules: [  OK  ]

# chkconfig --list |grep iptagbles
iptables        0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptagblesのランレベル2345がOnになっていることを確認する ※念のため新規接続してから切断する ○日本語環境設定

$ su -
Password: 

# mkdir /etc/sysconfig/00Backup
# cp /etc/sysconfig/i18n /etc/sysconfig/00Backup/i18n_`date +%Y%m%d%H%M`
# vi /etc/sysconfig/i18n 
# cat /etc/sysconfig/i18n 
LANG="ja_JP.UTF-8"
SUPPORTED="ja_JP.UTF-8:ja_JP:ja"
SYSFONT="latarcyrheb-sun16"

# diff /etc/sysconfig/i18n /etc/sysconfig/00Backup/i18n_201205301328
1,2c1
< LANG="ja_JP.UTF-8"
< SUPPORTED="ja_JP.UTF-8:ja_JP:ja"
---
> LANG="C"
4d2
<
# shutdown -r now

再起動して日本語設定を反映させる。 ○yumリポジトリ設定

$ su -
Password: 

# yum update
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2012-05-30 14:45:07 (20.3 KB/s) - `remi-release-6.rpm' へ保存完了 [5292/5292]

# rpm -Uvh remi-release-6.rpm
警告: remi-release-6.rpm: ヘッダ V3 DSA/SHA1 Signature, key ID 00f97f56: NOKEY

# wget http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm
2012-05-30 14:51:39 (776 KB/s) - `epel-release-6-7.noarch.rpm' へ保存完了 [14496/14496]

[root@www11190ue ~]# perrpm -Uvh epel-release-6-7.noarch.rpm 
 パッケージ epel-release-6-7.noarch は既にインストールされています。
なんと、CentOS6.2ではyumのリポジトリにデフォルトでepelが入っている様子!

# yum install yum-priorities
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum-plugin-priorities.noarch 0:1.1.30-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                     Arch         Version              Repository  Size
================================================================================
Installing:
 yum-plugin-priorities       noarch       1.1.30-10.el6        base        22 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 22 k
Installed size: 28 k
Is this ok [y/N]: y
Downloading Packages:
yum-plugin-priorities-1.1.30-10.el6.noarch.rpm           |  22 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.

Installed:
  yum-plugin-priorities.noarch 0:1.1.30-10.el6                                  

Complete!

# cd /etc/yum.repos.d/
# /etc/yum.repos.d/mkdir 00Backup
# cp /etc/yum.repos.d/remi.repo /etc/yum.repos.d/00Backup/remi.repo_`date +%Y%m%d%H%M `
# vi remi.repo 
恒久的にremiを使用する場合は"enabled=0"→"enabled=1"に変更する。 都度指定する場合は"yum --enablerepo=remi "とオプションを付けて利用する。 以下は恒久的にremiを利用する場合の例

# diff remi.repo 00Backup/remi.repo_201205301458 
5c5
< enabled=1
---
> enabled=0
続く