さよならCentOSこんにちわScientific Linux 6

さよならCentOSこんにちわScientific Linux 6

開発の鈍化しているCentOSを見限り・・・もとい、最近RHELクローンとして話題に上るScientific Linux6へWebサーバを乗り換え。CentOS6もRHEL6ベースになりましたが、こちらの方が先が明るい様な気がする。

なお作業では色々なサイトを参考にさせていただいた為ソース不明でございます。あえてイチバン参考にしたサイトを書くなら

インストール

Scientific Linux – Welcome to Scientific Linux (SL)

からScientific Linux 6.1 (http://ftp1.scientificlinux.org/linux/scientific/6.1/i386/iso/)をダウンロード。x64でなく32bitにしたのはVTの無い64bitOSの仮想化サポートの無いメインマシン(i7 2600K)でも使える様にしたい為。x64版を入れようとすると「VMのハードウェア支援が無い!」みたいに怒られます。
VMware PlayerにてHDD20GB、メモリ1.5GBのVM、Linux2.6カーネルのVMを作成。isoファイルからブートしてすべてデフォルトでインストールしました。インストール時に選べるパッケージタイプで「WebServer」を選択したため、最初からGUIの無いRunLevel:3となっています(/etc/inittabにて)。

まずは仮のホストとして設定、テスト。その後以降を行ったのでその順番で書いてあります。1からの構築をされる方は適時読み飛ばしてください。

初期設定

簡単に初期設定。
一般アカウントでsudo使用許可

#vi /etc/sudoers
username ALL=(ALL)ALL

作業例では面倒なのですべてrootで作業してあります。
次にDNSの修正。

vi /etc/resolv.conf
nameserver xxx.xxx.xxx.xxx

テスト用のIP、Gatewayはインストール時に指定してある、とします(DNSはナゼか間違えていた為修正)

 ntpを設定

# yum install ntp ← 最新を確認

国内のntpサーバを追加します

#vi /etc/ntp.conf
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server -4 ntp.nict.jp ←追加
server ntp.jst.mfeed.ad.jp ←追加
server ntp.asahi-net.or.jp ←追加

# chkconfig ntpd on

セキュリティ関連

SELinuxはいろいろ面倒なので無効にしました。

#vi /etc/sysconfig/selinux
SELINUX=disabled

簡単にですがFirewall(IPtables)の設定にPort:80(HTTP)を通過するよう編集します。

# cat /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

まじめにiptablesやると死亡確定な気がする。ボスケテ。

使わないサービスの停止

ntsysvというコマンドでGUIなサービスOFF/ON画面が出てきます。

# ntsysv

とりあえずは使わなそうな

acpid
ip6tables
nfs
postfix

あたりを停止しました。

アンチウィルス

フリーのLinux対応アンチウィルスソフト「Avira AntiVir Personal」を使います。主な作業手順は

Avira AntiVir Personal (UNIX) 3.1.3.5-0 インストール | 複眼中心

を参考に。毎週実行するのに使うcronファイルも有りがたく使わせていただきます。設定ファイルを開いてエラー時の通知に使うメール設定を実施。自分はGmailを使いました。

# vi /etc/avira/avupdate-guard.conf

#The method for sending mails. Can have one of the following values:
#  smtp      –  for using own smtp engine
#  sendmail  –  for using sendmail binary
mailer=smtp

# The smtp server for sending email notifications.
smtp-server=smtp.gmail.com

# The smtp port for sending email notifications.
smtp-port=587

# If auth-method is set, the Updater requires the smtp login data
smtp-user=hogehoge@gmail.com
smtp-password=hogehoge

# When set, the Updater requires the smtp login data: smtp-user and smtp-password
auth-method=password

パッケージの追加

#yum update
#yum install httpd ← 最新を確認
#yum install mysql-server ← 最新を確認
#yum install php php-mbstring php-mysql php-gd ← 最新を確認

sshdは導入済み。vsftpdは入れなくてもSCPで接続できました。

MySQL設定

WordPressの為、サービスを自動実行&起動

# chkconfig --list | grep mysql
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
# chkconfig mysqld on
#/etc/init.d/mysqld start

初期設定のみ実行しておきます。

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

mysql> SET PASSWORD FOR root@localhost=PASSWORD(‘xxxxxxx’);
Query OK, 0 rows affected (0.00 sec)

mysql> create database wp_db character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on wp_db.* to ‘database_user_name’@’localhost’ identified by ‘database_user_password’;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

WorePressのテスト

この時点で旧サーバからApacheのhttpd.confをコピーし、IPアドレスなどを仮IPへ変更。実際の場所にWorePressをインストールして正常に動作するかテストします。特にPHP周りに足りないモジュール等が無いかも確認。

旧サーバ(CentOS)からの移行

新サーバでWorePressの確認が取れたら、旧サーバから引っ越しを行います。

旧サーバ作業

データの引っ越し方法は様々ですが、自分はVM間での移動が簡単な「追加仮想HDD」を使いました。予めVMware Player上で仮想HDDを作成し、SCSIディスクとして追加しておきます。

起動したらウントポイント作成&マウント。

# mkdir /mnt/backup_volume
# vi /etc/fstab
/dev/sdb1               /mnt/backup_volume      vfat    defaults        0 0

これで再起動又はmountコマンドにて使える様になります。あとは

# tar cvzf /mnt/backup_volume/YYYYMMDD.tar.gz /var/www
# mysqldump -u root -p --all-databases > /mnt/backup_volume/YYYYMMDDmysql.dump
# cp /etc/httpd/conf/httpd.conf /mnt/backup_volume/httpd.conf

などとしてWebサーバのデータとMySQLデータベースを保存。

ここから新サーバ作業

旧サーバの仮想HDDをOS上で移動させ、VMware Playerで同様に追加。起動した同じようにマウントポイント作成&マウント(略)

ホスト名&IPアドレス入れ替え

旧サーバからの移行なのでIPアドレス&ホスト名を変更。

#vi /etc/sysconfig/network
HOSTNAME=xxxxxxxx

/etc/hostsは変更の必要無し。

#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1="xxx.xxx.xxx.xxx"
GATEWAY="192.168.xxx.xxx"
IPADDR="192.168.xxx.xxx"

それぞれ変更してnetworkをリスタート

# /etc/rc.d/init.d/network restart

テストDatabase削除

テストで作ったDBを削除します

# mysql -u root -p
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| wp                 |
| wp2                |
| wp_db              |
+--------------------+
6 rows in set (0.07 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.04 sec)

mysql> drop database wp;
Query OK, 18 rows affected (0.06 sec)

mysql> drop database wp2;
Query OK, 12 rows affected (0.01 sec)

mysql> drop database wp_db;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database mysql;
Query OK, 23 rows affected, 2 warnings (0.03 sec)
mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
+——————–+
1 row in set (0.00 sec)
mysql> exit
Bye

ファイルとデータベースを復元

引っ越してきたデータを元に戻します。

# cp /mnt/backup_volume/httpd.conf /etc/httpd/conf/
# tar xvzf /mnt/backup_volume/YYYYMMDD.tar.gz -C /
# mysql -u root -p < YYYYMMDDmysql.dump

#/etc/init.d/httpd restart

その後httpdへの追加

コレまでの作業で、Seicntific LinuxにてWordPressが公開できているハズ。あとは追加作業などなど。

mysqldumpによる毎晩バックアップ

前回と同じくmysqldumpとcronでMySQLを自動バックアップする | Linuxで自宅サーバ構築を参考にさせていただきました。

今回は/etc/cron.daily/配下にwww-backup-sqldump.cronという名前で配置。chmod 755を忘れずに。

apcでPHP高速化

中間コードをキャッシュしてPHPの高速化ができるそうな。

# yum -y install php-pecl-apc

# vi /etc/php.d/apc.ini
; The size of each shared memory segment in MB.
apc.shm_size=64 ←キャッシュサイズを任意に。

#/etc/init.d/httpd restart

phpinfo.phpを生成してapcの欄が増えているか確認します。

munin

今回もmuninで状態モニターを行います。ただしScientific Linuxのレポジトリにはmuninがありません。そこからスタート。

RepoView: “Fedora EPEL 6 – i386”からEPEL6 – i386のレポジトリファイルをダウンロードしてインストール実行。

# wget http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-
5.noarch.rpm
# rpm -ivh epel-release-6-5.noarch.rpm

普段のyum updateなどでは使われないよう、enabled=0に変更しておきます。
# vi /etc/yum.repos.d/epel.repo

そしてmuninインストール

# yum --enablerepo=epel install munin munin-common munin-node

あとはmuninを使って簡単サーバモニタリング | 徒労日記と同様にmunin.confの編集、Apache用モジュールの追加(【第21回】サーバ監視ツールmunin その2 – Tech [Wednesday] プロモバイルエンジニアブログ)などを実施。

あとは自動起動&起動

# chkconfig munin-node on
# chkconfig --list munin-node
munin-node      0:off   1:off   2:on    3:on    4:on    5:on    6:off
# /etc/init.d/munin-node start

以上、簡単ながらScientific Linuxのセットアップ終了です。

今回は最初からWeb Server Packageにしたせいか、あまり余計なモジュールが入りませんでした。そのせいかメモリの消費やCPU負荷が結構押さえられている様に見えます。Apacheのセキュリティはこれから見直したいところ。

ヒマソーだなおいwww って誰もこんなサイト見てないかrアッー!

2 thoughts on “0

  1. お邪魔します。
    Core i7 2600Kは仮想技術がないと仰っていますが、無いのは vProとVT-dのみで、VT-xはあります。
    よって、うちはXPモードやVMWare Workstationなど問題なく動いていますが・・・。最初から仮想技術がないと誤解を与えそうなので・・・。

    では、失礼しました。

  2. ▽匿名さん
     ようこそいらっしゃいました。
    Kプロセッサにてバーチャルマシンが一切使えない様に
    感じられましたら失礼いたしました。その後書いてある通り
    32bitゲストなどを使用すれば稼働はできます。
     本文を直しておきます。

コメントを残す