前回のVPS設定の続きです。
パスの設定状況を確認するには?
#echo $PATH
iptables設定
現在のiptables設定確認〜実際に設定
#iptables -L
#cd ~
#vi iptable-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
# SSH, HTTP, FTP1, FTP2
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport (任意のポート番号) -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#sh ./iptable-init.sh
ファイルに実行権限を与える
#chmod u+x iptable-init.sh
#./iptable-init.sh
#iptables-save > /etc/sysconfig/iptables
iptablesを再起動して実際に設定が反映されるかチェック。
# /etc/rc.d/init.d/iptables restart
# iptables -L
LAMP環境の設定
■Apacheの設定
#vi /etc/httpd/conf/httpd.conf
#ServerTokens OS
ServerTokens Prod
:
#ServerSignature On
ServerSignature Off
:
#Options Indexes FollowSymLinks
Options FollowSymLinks
:
#AllowOverride None
AllowOverride All
#wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
#wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
#rpm -Uvh epel-release-5* remi-release-5*
#wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
#rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
#yum -y --enablerepo=remi,epel,rpmforge update php* mysql*
#yum -y --enablerepo=remi,epel,rpmforge install php-gd php-mbstring php-mysql php-odbc php-pdo #php-pear mysql-server mysql-bench
#yum -y --enablerepo=remi,epel,rpmforge install phpMyAdmin
#vi /etc/php.ini
;date.timezone = date.timezone = Asia/Tokyo
upload_max_filesize = 2M →10M
Apacheの再起動
# apachectl graceful
vi操作キー
x カーソル上の1文字削除
/&<文字列> 文字列 を検索する
n 順方向へ検索する
N 逆方向へ検索する
■MySQLの設定
#vi /etc/my.cnf
[mysqld]
default-character-set=utf8
skip-character-set-client-handshake
:
[mysql]
default-character-set = utf8
MySQL起動
#/etc/init.d/mysqld start
mysqlのrootのパスワードを設定
#mysqladmin -u root password [rootpassword]
#vi /etc/httpd/conf.d/phpMyAdmin.conf
order deny,allow
#deny from all
#allow from 127.0.0.1
#allow from ::1
allow from all
/etc/init.d/httpd start
http://(YOUR HOST ADDRESS)/phpMyAdmin/
・特権から匿名アカウントの削除
・パスワードなしにパスワード設定
・データベースのtestを削除
参考:http://e-class.jp/modules/smartsection/item.php?itemid=60
#chkconfig --level 345 httpd on
#chkconfig --level 345 mysqld on
■不要なデーモンをストップ
#chkconfig acpid off 電源管理
#chkconfig auditd off システム監査結果のログ保存
#chkconfig autofs off ファイルシステムの自動マウント
#chkconfig avahi-daemon off LAN内でのネットワーク自動構成
#chkconfig bluetooth off bluetoothに対応
#chkconfig cups off 印刷の管理
#chkconfig firstboot off インストール直後に呼び出される
#chkconfig gpm off コンソールマウス機能
#chkconfig haldaemon off D-BUSサポート
#chkconfig hidd off bluetoothのキーボードやマウスを対応
#chkconfig kudzu off ハードウェアの構成変更を検知
#chkconfig lvm2-monitor off LVMの障害監視
#chkconfig mcstrans off SELinuxの運用
#chkconfig mdmonitor off mdデバイスの監視
#chkconfig messagebus off D-BUSサポート
#chkconfig netfs off NFSクライアント
#chkconfig nfslock off NFSロック
#chkconfig pcscd off スマートカードの管理
#chkconfig portmap off RPCのポートマッパー
#chkconfig rawdevices off ハードディスクをブロックデバイスとして利用する際の補助
#chkconfig restorecond off SELinuxの運用サポート
#chkconfig rpcgssd off RPCサポート
#chkconfig rpcidmapd off RPCサポート
#chkconfig smartd off S.M.A.R.Tのサポート
#chkconfig xfs off X-Window System用のフォントサーバ
■vsftpdのインストール
# yum -y install vsftpd
#vi /etc/vsftpd/vsftpd.conf
# asciiモードでアップロード、ダウンロードを許可します。
ascii_upload_enable=YES
ascii_download_enable=YES
# ローカルユーザーは全てchroot有効にします。
chroot_local_user=YES (追記)
# chrootに関する設定をlistで行えるようにします。
chroot_list_enable=YES
# chrootを無効にするユーザーリストを指定します。
# chroot_local_user=YES としたのでリストに記述されるユーザーは
# 上位ディレクトリへアクセスできることになります。
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
# ディレクトリまるごと削除出来るように指定したい場合はコメントを外します。
#ls_recurse_enable=YES
####### 追加
# タイムスタンプにローカル時間を指定します。(日本時間に変更)
use_localtime=YES
# PASV(パッシブモード)を有向にするかどうか指定します。
pasv_promiscuous=YES (追記)
# 詳細なログを/var/log/vsftpd.log に記録するか指定します。
# 指定しなければFTPデフォルト、/var/log/xferlog に出力します。
xferlog_std_format=NO (追記)
# Chrootされるディレクトリを指定します。指定が無ければ
# ユーザーのトップのホームディレクトリになります。
# 注意 chrootが有効の場合、~/public_html へchroot されます。
# ディレクトリから上へ上がることは出来ません。
local_root=public_html (追記)
#anon_upload_enable=YES
anon_upload_enable=NO
#anon_mkdir_write_enable=YES
anon_mkdir_write_enable=NO
#data_connection_timeout=120
data_connection_timeout=120
force_dot_file=YES
hide_ids=NO
chroot_listファイルを作成(接続禁止ユーザーを記入)
#touch /etc/vsftpd/chroot_list
vsftpdの起動
# /etc/rc.d/init.d/vsftpd start
■iptableにftpポート20,21を追加
vi iptable-init.sh
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
[text]
[shell gutter="false" light="true"]
# sh ./iptable-init.sh
# iptables-save > /etc/sysconfig/iptables
iptablesを再起動して実際に設定が反映されるかチェック。
# /etc/rc.d/init.d/iptables restart
# iptables -L
[/shell]
モジュールの追加
iptablesでFTPを通すには20番ポートと21番ポートをあけるだけではpassive modeのFTPはうまく通してくれません。
[shell gutter="false" light="true"]
#vi /etc/sysconfig/iptables-config
[/shell]
[text gutter="false" light="true"]
IPTABLES_MODULES="ip_conntrack_ftp ip_nat_ftp"
■/etc/httpd/conf/httpd.confの修正
エラーページ等に表示される管理者メールアドレスを指定
元)ServerAdmin root@localhost
修)ServerAdmin (YOUR MAIL ADDRESS)
サーバー名を指定
元)#ServerName www.example.com:80
修)ServerName ("YOUR DOMAIN" OR "IP ADDRESS"):80
長すぎるURI(414エラー)はログに記録しない
元)LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
修)LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
ファイル一覧を見せないよう、この部分を以下のように修正。
元)#Options Indexes FollowSymLinks
修)Options -Indexes FollowSymLinks
DirectoryIndex修正
/ で終わるURLの場合に表示するファイルを設定します。
元)DirectoryIndex index.html index.html.var
修)DirectoryIndex index.html index.php index.html.var
修正内容のに間違いがないかテスト
# apachectl configtest
yum でインストールした場合は自動的に apache というユーザーが作成されるので確認
# cat /etc/passwd | grep apache
■Webminインストール
# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.510-1.noarch.rpm
# rpm -ivh webmin-1.510-1.noarch.rpm
http://(YOUR DOMAIN):10000/
WebminにHTTPSでアクセス出来るように設定する
# wget ftp://ftp.pbone.net/mirror/atrpms.net/el5-x86_64/atrpms/stable/perl-Net_SSLeay.pm-1.25-4.0.el5.x86_64.rpm
# rpm -ivh perl-Net_SSLeay.pm-1.25-4.0.el5.x86_64.rpm
Webminの設定でSSL暗号化を有効に設定し以降はhttpsでアクセスする
https://(YOUR DOMAIN):10000/
Webmin JAVAファイルマネージャの文字化け解消(文字コードUTF-8の場合)
# cd /usr/libexec/webmin/file/lang
# nkf -es ja_JP.UTF-8 > ja_JP.sjis
# mv ja_JP.sjis ja_JP.UTF-8
常時必要ないのでサービス停止
#/etc/rc.d/init.d/webmin stop