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
続く

0 件のコメント:

コメントを投稿