Fedora LINUX セットアップ記 - FC2編
Internet向けのサーバをたてるために、プロバイダから固定IPアドレスを取っている。
また、使用しているブロードバンドルータには、DMZ専用のEthernetポートが用意されている。
このブロードバンドルータは獲得したグローバルIPの情報をDHCPで通知する機能がついているようだ。
そこで、今回作成したagosto.nortepotosi.comをそのDMZポートにつないで、DHCPを使ってグローバルIPで運用することにする。
/etc/sysconfig/network-scripts/ifcfg-eth0を編集し、次のようにする。
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:11:09:03:47:DD
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
PEERDNS=no
IPV6INIT=no
DMZポートにつないで再起動。ifconfigコマンドでグローバルIPを獲得していることを確認。
ルーティングを見てみる。
% route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
202.238.75.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 202.238.75.62 0.0.0.0 UG 0 0 0 eth0
ほぼ正常だが、169.254.0.0のルーティングは余計である。
(ちなみに169.254.0.0というネットワークアドレスはRendezvous/Zeroconf/UPnPデバイス用のアドレスである。
http://www.luci.org/luci-discuss/200305/msg00000.html
)
"/etc/sysconfig/network"ファイルに次の1行を書き加える。
NOZEROCONF=yes
ネットワークを再起動。
% service network restart
ルーティングを確認。
% route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
202.238.75.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 202.238.75.62 0.0.0.0 UG 0 0 0 eth0
オッケー。
DNSサーバを立ち上げよう。
ドメイン"nortepotosi.com"のプライマリサーバを作る。
まず、chroot-jailの設定をはずす。
/etc/sysconfig/namedファイル内の次の1行を削除
ROOTDIR=/var/named/chroot
/etc/named.conf, /etc/named/nortepotosi.zone, /etc/named/localhost.zone, /etc/name/localhost.rev を作る。
File: /etc/named.conf
// generated by named-bootconf.pl
options {
directory "/etc/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};
//
// a caching only nameserver config
//
//controls {
// inet 127.0.0.1 allow { localhost; } keys { rndckey; };
//};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "localhost.rev";
allow-update { none; };
};
//include "/etc/rndc.key";
zone "nortepotosi.com" IN {
type master;
file "nortepotosi.zone";
};
File: /etc/named/nortepotosi.zone
$TTL 86400
$ORIGIN nortepotosi.com.
@ IN SOA @ root (
2004082301 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS @
IN NS gw.bu-denken.co.jp.
loghost IN CNAME agosto
agosto IN A 202.238.75.61
ns IN CNAME agosto
po IN CNAME agosto
www IN CNAME agosto
nortepotosi.com. IN MX 10 agosto
rt IN A 192.168.77.200
bbb IN A 192.168.77.132
File: /etc/named/localhost.zone
$TTL 86400
$ORIGIN localhost.
@ 1D IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN NS @
1D IN A 127.0.0.1
File: /etc/named/localhost.rev
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
ファイアウォールを調整し53番ポートを通す。
/etc/sysconfig/iptablesを編集。
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
を追加。
namedを起動。
% service named start
/etc/resolv.confを編集し、自分のDNSサーバを使うようにする。
search nortepotosi.com
nameserver 202.238.75.61
nameserver 202.238.75.62
(202.238.75.62はルータの仮のアドレス。念のために。)
% dig www.nortepotosi.com
を実行して、このホストがagosto.nortepotosi.comであることと202.238.75.61であることが表示されるのを確認。
% chkconfig named on
を実行して、次回起動時からnamedを自動起動する。
Fedora Core 2のデフォルトのMTAはsendmailだが、postfixもインストールされている。
sendmailからpostfixに移行する。
参考資料:
http://www.dragoncity.ne.jp/construction/mailserver1.html
sendmailを止める。
% service sendmail stop
% chkconfig sendmail off
/etc/main.cfを調整する。
myorigin=$mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain $mydomain
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
各種ファイルをsendmailからpostfixに差し替える。
% cd /etc/alternatives/
% rm -f mta;ln -s /usr/sbin/sendmail.postfix mta
% rm -f mta-aliasesman;ln -s /usr/share/man/man5/aliases.postfix.5.gz mta-aliasesman
% rm -f mta-newaliases; ln -s /usr/bin/newaliases.postfix mta-newaliases
% rm -f mta-newaliasesman; ln -s /usr/share/man/man1/newaliases.postfix.1.gz mta-newaliasesman
% rm -f mta-rmail ; ln -s /usr/bin/rmail.postfix mta-rmail
Postfixを起動。
% service postfix start
% chkconfig postfix on
Postfixにユーザ認証付きメール送信のオプションを付けよう。(SASL)
参考:
http://www.postfix.org/SASL_README.html
/etc/postfix/main.cfに次の行を書き加える。
# SASL authentication
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
saslauthdを起動する。
% service saslauthd start
% chkconfig saslauthd on
これで、ログインできるユーザ名とパスワードを使ってパスワード認証メール送信ができる。
Fedora Core 2ではPOPとIMAPのサーバは dovecotになった。
これを起動しよう。
/etc/dovecot.confを編集。
protocols = imap imaps pop3 pop3s
imap_listen = *
pop3_listen = *
% service dovecot start
% chkconfig dovecot on
メール送信などのときに、サーバが応答するまでの待ち時間が長い。もしかすると、LAN上のマシンの名前を逆引きしようとしてDNSのタイムアウトを待ってしまっているのかもしれない。
192.168.77.*の逆引きをできるようにしよう。
/etc/named/nortepotosi.rev を作成。内容は次の通り。
File: /etc/named/nortepotosi.rev
$ORIGIN 77.168.192.in-addr.arpa.
$TTL 86400
@ IN SOA agosto.nortepotosi.com. root.agosto.nortepotosi.com. (
2004101101 ; Serial
3600 ; Refresh
1800 ; Retry
3600000 ; Expire
86400 ) ; Default TTL
IN NS agosto.nortepotosi.com.
IN PTR localnet.nortepotosi.com.
IN A 255.255.255
1 IN PTR local1.nortepotosi.com.
32 IN PTR local32.nortepotosi.com.
33 IN PTR local33.nortepotosi.com.
34 IN PTR local34.nortepotosi.com.
35 IN PTR local35.nortepotosi.com.
36 IN PTR local36.nortepotosi.com.
37 IN PTR local37.nortepotosi.com.
38 IN PTR local38.nortepotosi.com.
39 IN PTR local39.nortepotosi.com.
200 IN PTR rt.nortepotosi.com.
/etc/named.confを編集。次の行を書き加える。
zone "77.168.192.in-addr.arpa" IN {
type master;
file "nortepotosi.rev";
allow-update { none; };
};
bindを再起動。
% service named restart
cronがlogrotateを走らせたときにエラーメッセージを出していた。
/etc/cron.daily/logrotate:
error: stat of /var/log/ppp/connect-errors failed: No such file or directory
これを避けるために、/etc/logrotate.d/pppを編集する。
/var/log/ppp/connect-errors {
missingok
compress
notifempty
daily
rotate 5
create 0600 root root
}
と変更した。(missingokの行を追加した。)
私の場合、仮名漢字変換は端末側で行ない、サーバ上で行なう必要が無い。ので、仮名漢字変換システムを止める。
% service canna stop
% service FreeWnn stop
% service IIim stop
% chkconfig canna off
% chkconfig FreeWnn off
% chkconfig IIim off
私の場合、リモートからのログインでほとんどのことをやっているので、X11環境はいらない。停止しよう。
/etc/inittabを編集。次の行を変更。
id:5:initdefault:
↓
id:3:initdefault:
% telinit 3
PostgreSQLを動かそう。
% service postgresql start
% chkconfig postgresql on
% su - postgres
% createuser -d -P username
Enter password for new user:
Enter it again:
Shall the new user be allowed to create more new users? (y/n) y
CREATE USER
% exit
これで、usernameで指定したユーザがデータベース作成できるようになる。
さらに、/var/lib/pgsql/data を編集し、パスワード認証ができるようにすれば、WEBアプリケーションからデータベースに接続しやすくなる。
最近、WEBサーバへのハッキングを狙っているのか、異常なSEARCHアクセスがログに残っている。このため、webalizerが毎日のように、エラーメッセージを出す。
/etc/cron.daily/00webalizer:
Error: Skipping oversized log record
鬱陶しいので/etc/cron.daily/00webalizerを編集して出ないようにする。
if [ -s /var/log/httpd/access_log ] ; then
/usr/bin/webalizer > /dev/null 2>&1
fi
exit 0
その後、crondを再起動。
% service crond restart
Last updated: 2004/10/29 18:15
Copyright (C) 2004 by SHIBUYA K.
All Rights Reserved.