CentOS5サーバの設定
[]

2009.01.29

このエントリーをはてなブックマークに追加
はてなブックマーク - CentOS5サーバの設定

環境を調べる

CentOSのバージョン

$cat /etc/redhat-release
CentOS release 5.2 (Final)

Linuxカーネルのバージョン

$dmesg | grep "Linux version"
Linux version 2.6.18-92.1.22.el5 (mockbuild@builder16.centos.org) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Tue Dec 16 12:03:43 EST 2008

rootになる

$ su -

管理者ユーザを作る

$ useradd [管理者ユーザ名]
$ passwd [管理者ユーザ名]
Changing password for user 管理者ユーザ名
New  UNIX password: ************
Retype new UNIX password: 同じものを入力

管理者ユーザがsudoコマンドを使えるようにする

$ yum install sudo
$ vi /etc/sudoers
# 以下の行を追加
[管理者ユーザ名] ALL=(ALL) ALL

不要なサービスを停止する

$/usr/sbin/setup

テキストモードセットアップユーティリティが起動するので  
システムサービスを選択する  

[ ] NetworkManager
[ ] NetworkManagerDispatcher
[ ] acpid
[*] anacron
[*] apmd
[ ] atd
[*] auditd
[ ] autofs
[ ] avahi-daemon
[ ] avahi-dnsconfd
[ ] bluetooth
[ ] capi
[ ] chargen-dgram
[ ] chargen-stream
[ ] conman
[*] cpuspeed
[*] crond
[ ] cups
[ ] cvs
[ ] daytime-dgram
[ ] daytime-stream
[ ] dc_client
[ ] dc_server
[ ] dhcdbd
[ ] discard-dgram
[ ] discard-stream
[*] dovecot
[ ] dund
[ ] echo-dgram
[ ] echo-stream
[ ] eklogin
[ ] ekrb5-telnet
[ ] firstboot
[ ] gpm
[ ] gssftp
[*] haldaemon
[ ] hidd
[ ] hplip
[*] httpd
[ ] ibmasm
[ ] innd
[*] ip6tables
[*] iptables
[ ] irda
[ ] irqbalance
[ ] isdn
[ ] kdump
[ ] klogin
[ ] krb5-telnet
[ ] kshell
[ ] kudzu
[ ] lvm2-monitor
[*] mcstrans
[ ] mdmonitor
[ ] mdmpd
[*] messagebus
[ ] multipathd
[*] mysqld
[*] named
[ ] netconsole
[ ] netfs
[ ] netplugd
[*] network
[ ] nfs
[ ] nfslock
[ ] nscd
[*] ntpd
[ ] oddjobd
[ ] pand
[ ] pcscd
[*] portmap
[*] postfix
[ ] psacct
[ ] rdisc
[*] readahead_early
[ ] readahead_later
[*] restorecond
[*] rpcgssd
[*] rpcidmapd
[ ] rpcsvcgssd
[ ] rsync
[ ] rwhod
[ ] saslauthd
[*] setroubleshoot
[*] smartd
[*] smb
[ ] spamassassin
[ ] squid
[*] sshd
[*] swatch
[*] syslog
[ ] tcpmux-server
[ ] time-dgram
[ ] time-stream
[ ] tux
[ ] vncserver
[ ] vsftpd
[ ] wdaemon
[ ] winbind
[ ] wpa_supplicant
[ ] xfs
[*] xinetd
[ ] ypbind
[ ] yum-cron
[ ] yum-updatesd

yumのfastestmirrorプライグインをインストール

$ yum install yunm-fastestmirror
$ yum update

yum-cronをインストール

$ yum -y install yum-cron

yum-updatesdを無効に

$/etc/rc.d/init.d/yum-updatesd stop
yum-updates を停止中:                                      [  OK  ]

$chkconfig yum-updatesd off

gccをインストール

$ yum install gcc.* compat-gcc* compat-glibc* compat-lib*

Emacsをインストール

$ yum install emacs.i386

SELinuxとFirewallを設定する。

設定画面が開くので、Security Levelは「Enabled」を選んで「OK」する
SELinuxはとりあえずPermissive
Customizeを選び、解放したいポートを選択する。

$ system-config-securitylevel

ラベルの再構築を行う

$ fiexfiles relabel

再起動して設定を有効にする。

$ reboot

phpをインストール

[centos5にphp5.2.10をインストール](a href="http://www.yokada.net/blog/797")

GDをインストール

$ yum -y install gd*

php-gdをインストール

yum install php-gd
$ php -r "phpinfo();" | grep GD
GD Support => enabled
GD Version => bundled(2.0.28 compatible)
$ apachectl restart

php-mbstringをインストール

$ yum install php-mbstring

$ php -r "phpinfo();" | grep "Multibyte Support"
Multibyte Support => enabled

$ apachectl restart

phpDocumentorをインストール

$ pear install --alldeps phpdocumentor

確認

$ phpdoc --help

複数存在するPEARの設定ファイルを削除する

設定ファイルが複数あるとPEARライブラリのバージョン情報を古い設定ファイルから参照してしまうことがあるため、 PEARライブラリをインストールできないことになったりする。ややこしいので、使ってない方を削除した。

$ sudo rm /etc/pear.conf

PEAR自体をアップグレード

現在のバージョンを確認する。

$ pear list | grep PEAR
INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
PEAR             1.6.2   stable

アップグレードする。

$ pear upgrade PEAR
downloading PEAR-1.9.0.tgz ...
Starting to download PEAR-1.9.0.tgz (291,634 bytes)
.............................................................done: 291,634 bytes
downloading Structures_Graph-1.0.3.tgz ...
Starting to download Structures_Graph-1.0.3.tgz (30,191 bytes)
...done: 30,191 bytes
upgrade ok: channel://pear.php.net/Structures_Graph-1.0.3
upgrade ok: channel://pear.php.net/PEAR-1.9.0
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR'
s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"

確認する

$pear list | grep PEAR
INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
PEAR             1.9.0   stable

PHPのpearのチャンネルが壊れたので再インストール

$ sudo rm -rf /usr/share/pear/.channels/
$ sudo pear update-channels

PHPUnitをインストール

pear.phpunit.deチャンネルを追加する。

$ pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

依存性をすべて自動で解決してインストールするため --alldeps を付ける。

$ pear install --alldeps phpunit/PHPUnit

インストールを確認する。

$ which phpunit
/usr/local/bin/phpunit

$ phpunit
PHPUnit 3.4.3 by Sebastian Bergmann.
... 省略:usageが出力される。

Propelのインストール

Php5-xslのインストール

... 未完

Propel関連のパッケージをインストール

$ pear config-set preferred_state beta
$ pear install --alldeps phpdb/propel_generator
$ pear install phpdb/propel_runtime
$ pear config-set preferred_state stable

シェルのビープ音を消す

$ vi /etc/inputrc

以下のように設定

#
# /etc/inputrc
#
set bell-style none

rootのメールアドレスを変更する

$ sed -i '/^root:/d' /etc/aliases
$ echo "root: [設定したいメアド]" >> /etc/aliases
$ newaliases  #aliases.dbを更新

vsftpdの設定

$ vi /etc/vsftpd/vsftd.conf

ここを参考。 FTPサーバー構築(vsftpd)

sshdの設定

$ vi /etc/sshd/sshd_config

参考ページ

SSHサーバー構築(OpenSSH) - CentOSで自宅サーバー構築

パスワードではなく認証キーで認証するよう設定する

リモート接続にSSHを使う

管理ユーザーがrootになれるようにする

$ vi /etc/group

/etc/group

wheel:x:10:root,管理ユーザー名      <== 管理ユーザー追加

mysql-serverをインストール

$ yum -y install mysql-server
$ mysql_install_db
$ mysqld_safe &
$ mysqadmin -u root ping
mysql server is alived.

$ chkconfig mysqld on
$ chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

$ mysql -u root
mysql> select user, host, password from user;
+------+--------------------------+----------+
| user | host                     | password |
+------+--------------------------+----------+
| root | localhost                |          |
| root | 9.1.168.192.in-addr.arpa |          |
| root | 127.0.0.1                |          |
+------+--------------------------+----------+

mysql> set password for root@localhost=password('[パスワード]');
mysql> set password for root@'9.1.168.192.in-addr.arpa'=password('[パスワード]');
mysql> set password for root@127.0.0.1=password('[パスワード]');

mysql> GRANT ALL PRIVILEGES ON *.* TO [管理者ユーザ]@[ホスT名] IDENTIFIED BY '[パスワード]';

mysql> drop database test;

mysql> update user set host='example.com' where host='9.1.168.192.in-addr.arpa';

mysql> grant all privileges on work.* to [管理者ユーザ名]@localhost identified by '***';
mysql> quit

mysqlクライアントが吐くエラーメッセージを英語にする。

$ mysql -u user -p
mysql> Nonexistscommand;
ERROR 1064 (42000): Something is wrong in your syntax  : 'Nonexistscommand' ?ն?  : 1 ????

このように、日本語だと文字化けする上に、そもそものエラーの意味も違っているので、それなら英語でいいやってことで。
my.cnfのlanguageをコメントアウトする。

$ vi /etc/my.cnf
[mysqld]
#language=/usr/share/mysql/japanese/

mysqldを再起動

$ /etc/rc.d/init.d/mysqld restart
$ mysql -u user -p

mysql> Nonexistscommand;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Nonexistscommand' at line 1

sambaを使えるようにする

$ pdbedit -a yokada
$ mkdir /home/samba
$ chown nobody:nobody /home/samba
$ mkdir /home/[ユーザ名]/samba
$ chown [ユーザ名]:[ユーザ名] /home/[ユーザ名]/samba
$ vi /etc/samba/smb.conf
$ /etc/rc.d/init.d/smb start

swatchのインストール

必要なperlモジュールをインストール

$ sudo perl -MCPAN -e shell
cpan> install Date::Calc
cpan> install Date::Format
cpan> install Date::Manip
cpan> install File:Tail

swatchをダウンロード

$ curl -O http://jaist.dl.sourceforge.net/sourceforge/swatch/swatch-3.2.3.tar.gz

展開

$ tar zxvf swatch-3.2.3.tar.gz

swatchをインストール

$ cd swatch-3.2.3
$ sudo perl MakeFile.PL
$ sudo make
$ sudo make install

cronでスケジューリング

$ vi /etc/crontab

リポジトリサーバ

subversion本体とapacheのmod_dav_svnモジュールをインストール

$ yum install subversion
$ yum install mod_dav_svn

リポジトリ作成

$ svnadmin create /path/to/repos/myproject

httpd.conf編集

$ vi /etc/httpd/conf/httpd.conf
...省略
<Location /repos/myproject>
   DAV svn
   SVNPath /path/to/repos/myproject
</Location>
...省略

php => 5.2.6、mysql => 5.0.58にそれぞれアップデート

CentOS 5系でyumを使ってPHPを5.2.x系へアップデートする方法

$ yum update php mysql

PHPのアップデートを確認

$php -v
PHP 5.2.6 (cli) (built: May  5 2008 10:32:59)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Mysqlのアップデートを確認

$mysqladmin version -u root -p
... 略
Server version    5.0.58
Protocol version  10
Connection    Localhost via UNIX socket
UNIX socket   /var/lib/mysql/mysql.sock
Uptime:     9 min 55 sec

Threads: 1  Questions: 1  Slow queries: 0  Opens: 12  Flush tables: 1  Open tables: 6  Queries per second avg: 0.002

apacheを再起動

$ apachectl restart

関連記事はありません。

Leave a Reply