Debian Archive
[Debian]Debian lennyで1からサーバーを作ってみる – PostGISをインストール
- PostGISをインストール
# aptitude install postgresql-8.3-postgis
- PostGIS用に初期化済テンプレートDBを構築する。
# su - postgres $ createdb templategis $ createlang plpgsql templategis $ psql -d templategis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql $ psql -d templategis -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – PHP、MySQL、PostgreSQLをインストール
- PHP、MySQL、PostgreSQLをインストール。(mysqlインストール時に、案内に従ってパスワードを設定する。)
# aptitude install php5 php5-dev php5-cgi php5-cli php-pear php5-curl php5-gd php5-imagick php5-json php5-mcrypt php5-mysql php5-pgsql php5-sqlite php5-geoip phpmyadmin phppgadmin mysql-server mysql-client postgresql libapache2-mod-php5
- /etc/cron.d/php5を編集。
phpをインストールすると、30分ごとにセッション破棄を行うcronが動作するようになるので1日1回(毎朝6時)だけ動くように変更する。# vi /etc/cron.d/php5
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm ↓ 0 6 * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 20 0 -r -0 rm
- MySQL設定。
- /etc/mysql/my.cnfを編集
# vi /etc/mysql/my.cnf
##[mysqld]の項目へ追加 character-set-server = utf8 collation-server = utf8_unicode_ci init-connect = 'SET NAMES utf8' skip-character-set-client-handshake ##[mysqldump]の項目へ追加 default-character-set = utf8 ##[mysql]の項目へ追加 default-character-set = utf8
- MySQL再起動
# /etc/init.d/mysql restart
- mysqlへ接続出来るか確認。(インストール時にパスワード設定するとパスワード無しでのログインは出来ない。)
# mysql -u root -p
- 登録済みユーザーとパスワードを確認。(パスワード無しユーザーが居ないか確認。)
mysql> select user,host,password from mysql.user;
- ※もしパスワード無しユーザーが居た場合は以下で設定。
mysql> set password for ユーザー名@ホスト名=password('パスワード'); mysql> exit
- /etc/mysql/my.cnfを編集
- MySQLバックアップ設定
- MySQLバックアップスクリプト作成
# vi mysql-backup.sh
#!/bin/bash PATH=/usr/local/sbin:/usr/bin:/bin # バックアップ先ディレクトリ BACKDIR=/backup/mysql # MySQLrootパスワード ROOTPASS=****** # バックアップ先ディレクトリ再作成 rm -rf $BACKDIR mkdir -p $BACKDIR # データベース名取得 DBLIST=`ls -p /var/lib/mysql | grep / | tr -d /` # データベースごとにバックアップ for dbname in $DBLIST do table_count=`mysql -u root -p$ROOTPASS -B -e "show tables" $dbname|wc -l` [ $table_count -ne 0 ] && mysqlhotcopy $dbname -u root -p $ROOTPASS $BACKDIR | logger -t mysqlhotcopy done - バックアップ先作成
# mkdir /backup # mkdir /backup/mysql
- mysql-backup.shへ実行権を付与。
# chmod 700 mysql-backup.sh
- バックアップスクリプト実行
# ./mysql-backup.sh
- バックアップ確認。
# ls -la /backup/mysql
- cronへ登録
# crontab -e
0 5 * * * /root/mysql-backup.sh
- MySQLバックアップスクリプト作成
- phpmyadmin設定
- シンボリックリンクを作成。
# ln -s /usr/share/phpmyadmin /var/www/admin/
- ブラウザで「http://admin.サーバー名/phpmyadmin」へアクセスする。
- シンボリックリンクを作成。
- PostgreSQL設定
- postgresユーザーのパスワードを設定。
# passwd postgres # su postgres $ psql template1 template1=# alter user postgres with password '******'; ← ******は適当なパスワードを設定。 template1=# \q
- 一般ユーザへのデータベース作成権限設定。(hogeは適当な一般ユーザーへ)
$ createuser -AdPE hoge
- /etc/postgresql/8.3/main/postgresql.confを編集
$ vi /etc/postgresql/8.3/main/postgresql.conf
listen_addresses = 'localhost' ↓ listen_addresses = '*'
- /etc/postgresql/8.3/main/pg_hba.confを編集。(↓こんな感じで。192.168.0.1は各自ネットワーク環境へ。)
$ vi /etc/postgresql/8.3/main/pg_hba.conf
# Database administrative login by UNIX sockets #local all postgres ident sameuser # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only #local all all ident sameuser # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 local all all trust host all all 192.168.0.1 255.255.255.255 trust host all all 0.0.0.0 0.0.0.0 password crypt
- PostgreSQL再起動
$ exit # /etc/init.d/postgresql-8.3 restart
- PostgreSQLのチューニングは[PostgreSQL]PostgreSQLチューニング方法まとめサイト[Ubuntu]を参照して各自で勝手にやってね。
- postgresユーザーのパスワードを設定。
- PostgreSQLバックアップ設定
# su - postgres $ mkdir /var/lib/postgresql/8.3/main/backups/ $ pg_dumpall -c > /var/lib/postgresql/8.3/main/backups/pgsql-backup $ crontab -e
30 3 * * * pg_dumpall -c > /var/lib/postgresql/8.3/main/backups/pgsql-backup
$ exit
- phppgadmin設定
- シンボリックリンクを作成
# ln -s /usr/share/phppgadmin /var/www/admin/
- /etc/phppgadmin/config.inc.phpを編集
# vi /etc/phppgadmin/config.inc.php
$conf['extra_login_security'] = true; ↓ $conf['extra_login_security'] = false; $conf['owned_only'] = false; ↓ $conf['owned_only'] = true;
- /etc/phppgadmin/apache.confを編集
# vi /etc/phppgadmin/apache.conf
allow from 127.0.0.0/255.0.0.0 ::1/128 ↓ #allow from 127.0.0.0/255.0.0.0 ::1/128 #allow from all ↓ allow from all
- apache再起動
# /etc/init.d/apache2 restart
- ブラウザで「http://admin.サーバー名/phppgadmin」へアクセスする。
- シンボリックリンクを作成
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – Postfix+Clam AntiVirus+SpamAssassinでウィルス&スパムチェック
Postfix+Clam AntiVirus+SpamAssassinでウィルス&スパムチェック
- amavisとspamassassinをインストール
# aptitude install amavisd-new spamassassin
- spamassassinをデーモンとして動かす。
# vi /etc/default/spamassassin
ENABLED=0 ↓ ENABLED=1
- postfix設定
# vi /etc/postfix/main.cf
# amavis setting content_filter = smtp-amavis:[127.0.0.1]:10024 ← 追加
# vi /etc/postfix/master.cf
# 以下をファイル最下部へ追加↓↓ # # amavisd-new + clamav. # smtp-amavis unix - - n - 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes -o max_use=20 127.0.0.1:10025 inet n - n - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_delay_reject=no -o smtpd_client_restrictions=permit_mynetworks,reject -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o smtpd_data_restrictions=reject_unauth_pipelining -o smtpd_end_of_data_restrictions= -o mynetworks=127.0.0.0/8 -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 -o smtpd_client_connection_count_limit=0 -o smtpd_client_connection_rate_limit=0 -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks
- amavis設定
# vi /etc/amavis/conf.d/15-content_filter_mode
#@bypass_virus_checks_maps = ( # \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re); ↓ @bypass_virus_checks_maps = ( \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re); #@bypass_spam_checks_maps = ( # \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re); ↓ @bypass_spam_checks_maps = ( \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
# vi /etc/amavis/conf.d/20-debian_defaults
$sa_spam_subject_tag1 = '***possible SPAM*** '; ← 追加 $sa_tag_level_deflt = 2.0; ↓ $sa_tag_level_deflt = 4.0; $sa_tag2_level_deflt = 6.31; ↓ $sa_tag2_level_deflt = 20.0; $sa_kill_level_deflt = 6.31; ↓ $sa_kill_level_deflt = 20.0; $sa_dsn_cutoff_level = 10; ↓ $sa_dsn_cutoff_level = 30.0; $sa_local_tests_only = 0; ↓ #$sa_local_tests_only = 0;
# vi /etc/amavis/conf.d/50-user
use strict; # # Place your configuration directives here. They will override those in # earlier files. # # See /usr/share/doc/amavisd-new/ for documentation and examples of # the directives you can use in this file # $log_level = 2; $X_HEADER_TAG = 'X-Virus-Scanned'; $remove_existing_x_scanned_headers = 0; $remove_existing_spam_headers = 1; $replace_existing_extension = 1; $sa_local_tests_only = 1; # (default: false) $sa_auto_whitelist = 1; # turn on AWL (default: false) $sa_debug = 1; $max_servers = 4; # number of pre-forked children (default 2) $max_requests = 16; # retire a child after that many accepts (default 10) #------------ Do not modify anything below this line ------------- 1; # ensure a defined return
- spamassassin設定
# mkdir /var/lib/amavis/.spamassassin # cd /var/lib/amavis/.spamassassin # wget -O user_prefs_tlec http://tlec.linux.or.jp/docs/user_prefs
/var/lib/amavis/.spamassassin/user_prefsを作成。
# vi /var/lib/amavis/.spamassassin/user_prefs
include user_prefs_tlec required_score 15.0 use_auto_whitelist 0 score GB2312_CHARSET 1.0 score BIG5_CHARSET 1.0 score WINDOWS_CHARSET 1.0 score GB2312ENC 0 score MIMEQENC 0 score QENCPTR1 0 score QENCPTR2 0 score X_MAILER 1.0
-
# cd /var/lib/amavis # chown -R amavis.amavis .spamassassin # /etc/init.d/amavis restart # /etc/init.d/spamassassin restart # /etc/init.d/postfix restart # vi /etc/group
clamav:x:108:amavis amavis:x:114:clamav
※ ↓のエラーが/var/log/mail.logに出てたので↑の/etc/groupを弄る。(108や114っていうIDは触らないよ。)
Aug 7 18:05:37 debian amavis[10436]: (10436-01) (!!)run_av (ClamAV-clamd) FAILED - unexpected , output="/var/lib/amavis/tmp/amavis-20090807T180537-10436/parts: lstat() failed: Permission denied. ERROR\n" Aug 7 18:05:37 debian amavis[10436]: (10436-01) (!!)ClamAV-clamd av-scanner FAILED: CODE(0xa252768) unexpected , output="/var/lib/amavis/tmp/amavis-20090807T180537-10436/parts: lstat() failed: Permission denied. ERROR\n" at (eval 86) line 527. Aug 7 18:05:37 debian amavis[10436]: (10436-01) (!!)WARN: all primary virus scanners failed, considering backups
# /etc/init.d/clamav-daemon restart
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – postfixへバーチャルホストを設定する
- postfixへバーチャルホストを設定する(例:virtualhost.netというドメインの場合)
# vi /etc/postfix/main.cf
#配送を追加したいドメイン名を指定します。 virtual_alias_domains = virtualhost.net ← 追加 #バーチャルドメイン用のエイリアステーブルを指定します。 virtual_alias_maps = hash:/etc/postfix/virtual ← 追加
# vi /etc/postfix/virtual
# set saizensen.net hoge@saizensen.net hoge # set virtualhost.net virtualhost.net anything hogehoge@virtualhost.net hogehoge # こんな風にしてもいい。(hogehoge@virtualhost.netのメールはhogeへ配送) hogehoge@virtualhost.net hoge
# postmap /etc/postfix/virtual # /etc/init.d/postfix restart
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – postfixとdovecotをインストール
- メールサーバー構築(PostfixとDovecotをインストール)
Debianの場合、デフォルトでexim4メールサーバがインストールされているので、まずこれらを消す。# aptitude remove exim4 exim4-base exim4-config
exim4を消したら、makeまで消されたので再度インストール。
# aptitude install make
postfix、saslをインストール。
# aptitude install postfix sasl2-bin libsasl2-modules # aptitude clean
メール名を確認(ここで表示されたものがメールアドレスの@以降に使われます。思ったものと違うときは編集する。)
# vi /etc/mailname
saizensen.net
- /etc/postfix/main.cfを編集(↓全部載せ)
# vi /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname #smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) smtpd_banner = $myhostname ESMTP unknown biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters #smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem #smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key #smtpd_use_tls=yes #smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache #smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. myhostname = mail.saizensen.net alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname #mydestination = saizensen.net, localhost.localdomain, localhost.localdomain, localhost mydestination = $myorigin, $myhostname, localhost.$myorigin, localhost relayhost = #mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mynetworks = 192.168.0.0/24 127.0.0.0/8 #mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all home_mailbox = Maildir/ smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination broken_sasl_auth_clients = yes unknown_local_recipient_reject_code = 550 message_size_limit = 10485760 # MobileMail setting([-] start address) allow_min_user = yes - /etc/postfix/master.cfを編集
# vi /etc/postfix/master.cf
smtp inet n - - - - smtpd ↓ smtp inet n - n - - smtpd #submission inet n - - - - smtpd ↓ submission inet n - n - - smtpd
- /etc/default/saslauthdを編集。
# vi /etc/default/saslauthd
START=no ↓ START=yes #OPTIONS="-c -m /var/run/saslauthd" ↓ OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"
↓これをやる必要があるのか微妙。色々やりすぎて忘れた。
# dpkg-statoverride --add root sasl 710 /var/spool/postfix/var/run/saslauthd
- /etc/postfix/sasl/smtpd.confを作成。
# vi /etc/postfix/sasl/smtpd.conf
pwcheck_method: auxprop
-
# chgrp postfix /etc/sasldb2 # adduser postfix sasl # /etc/init.d/saslauthd restart # /etc/init.d/postfix restart
- ルータの設定でPort25(TCP)を開けます。Submissionポート(587番)を使う場合はPort587(TCP)を開けます。
- Submissionポート(587番)を使う場合は以下を参照。
- Dovecotをインストール && 設定。
# aptitude install dovecot-imapd dovecot-pop3d # vi /etc/dovecot/dovecot.conf
#disable_plaintext_auth = yes ↓ disable_plaintext_auth = no #mail_location = ↓ mail_location = maildir:~/Maildir
# /etc/init.d/dovecot restart
- ポート110番(POPの場合)または143番(IMAPの場合)のOPEN
- Maildir形式メールボックス作成。
rootユーザーで以下を行う# mkdir -p /etc/skel/Maildir/{new,cur,tmp} # chmod -R 700 /etc/skel/Maildir/それぞれの一般ユーザーで以下を行う。(作成済ユーザー全員分)
$ mkdir Maildir $ mkdir Maildir/{new,cur,tmp} $ chmod -R 700 Maildir - メールユーザ追加(hogeは適当な一般ユーザーへ)
- sshなどでログインしないユーザー追加の場合
# useradd -s /sbin/nologin hoge # passwd hoge
この場合、/home/以下にhoge用ディレクトリが作成されない為、手動で作成。
# mkdir /home/hoge # mkdir /home/hoge/Maildir # mkdir /home/hoge/Maildir/new # mkdir /home/hoge/Maildir/cur # mkdir /home/hoge/Maildir/tmp # chown -R hoge.hoge /home/hoge # chmod -R 700 /home/hoge/Maildir
- sshなどでログインするユーザー追加の場合
# useradd hoge # passwd hoge
- SMTP-Auth用ユーザ/パスワード登録(ホスト名は/etc/postfix/main.cfのsmtpd_sasl_local_domainでした物を指定すること。)
# echo "******" | saslpasswd2 -p -u mail.saizensen.net -c hoge
- SMTP-Auth用ユーザ名、パスワード確認
# sasldblistusers2
- ※SMTP-Auth用ユーザ名、パスワードを削除する場合
# saslpasswd2 -d hoge -u mail.saizensen.net
- sshなどでログインしないユーザー追加の場合
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – apacheへバーチャルホストを設定する
- apacheへバーチャルホストを設定する。(例:virtualhost.netというドメインの場合)
# cd /etc/apache2/sites-available # cp default virtualhost.net # vi virtualhost.net
コピペするときは< /directory>の /は半角に修正してください。
<virtualhost *:80> ServerAdmin webmaster@virtualhost.net ServerName virtualhost.net:80 ServerAlias www.virtualhost.net DocumentRoot /var/www/virtualhost.net <directory /> Options FollowSymLinks AllowOverride None < /directory> <directory /var/www/virtualhost.net> Options Includes ExecCGI FollowSymLinks AllowOverride All Order allow,deny allow from all </directory> ・・・ ・・・ ErrorLog /var/log/apache2/virtualhost_net-error.log ・・・ ・・・ CustomLog /var/log/apache2/virtualhost_net-access.log combined env=!no_log ・・・ </virtualhost>
# mkdir /var/www/virtualhost.net # chown hoge.hoge /var/www/virtualhost.net # a2ensite virtualhost.net # /etc/init.d/apache2 restart
- DNSサーバー(bind)へvirtualhost.netを登録する。
参考:[Debian]Debian lennyで1からサーバーを作ってみる – bindをインストールのページ最下部「バーチャルホスト用にドメインを設定する。」項
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – opensslをインストール
- OpenSSLをインストール。
# aptitude install openssl # aptitude clean openssl # cd /etc/ssl/ # cp openssl.cnf openssl.cnf.default # vi openssl.cnf
[usr_cert] ・・・ #nsCertType = server ↓ nsCertType = server ・・・ [v3_ca] ・・・ #nsCertType = sslCA, emailCA ↓ nsCertType = sslCA, emailCA
- 秘密鍵の作成
# cd /usr/lib/ssl/misc/ # ./CA.sh -newca
CA certificate filename (or enter to create) このままEnter Making CA certificate ... Generating a 1024 bit RSA private key ................++++++ ..........++++++ writing new private key to './demoCA/private/./cakey.pem' Enter PEM pass phrase: パスフレーズを入力 Verifying - Enter PEM pass phrase: もう一度パスフレーズを入力 ----- (省略) ----- Country Name (2 letter code) [AU]: JPと入力 State or Province Name (full name) [Some-State]: Tokyoなど Locality Name (eg, city) []: 地域名(Edogawaなど) Organization Name (eg, company) [Internet Widgits Pty Ltd]: Enter Organizational Unit Name (eg, section) []: Enter Common Name (eg, YOUR name) []: WEBサーバー名 Email Address []: Enter Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: Enter An optional company name []: Enter Using configuration from /usr/lib/ssl/openssl.cnf Enter pass phrase for ./demoCA/private/./cakey.pem: またパスフレーズ - このままではApacheの起動の度にパスフレーズの入力を求められるのでパスフレーズを消す
# openssl rsa -in demoCA/private/cakey.pem -out demoCA/private/cakey.pem
- 証明書の作成
# openssl x509 -in demoCA/cacert.pem -out demoCA/cacert.crt
- 秘密鍵と証明書をコピー
# mkdir /etc/apache2/ssl # cp /usr/lib/ssl/misc/demoCA/private/cakey.pem /etc/apache2/ssl # cp /usr/lib/ssl/misc/demoCA/cacert.crt /etc/apache2/ssl
- Apache2のSSL設定ファイルの編集。
# vi /etc/apache2/sites-available/default-ssl
<ifmodule mod_ssl.c> <virtualhost _default_:443> ServerAdmin webmaster@saizensen.net Servername saizensen.net:443 DocumentRoot /var/www/html <directory /> Options FollowSymLinks AllowOverride None <directory /var/www/html> Options Includes ExecCGI FollowSymLinks AllowOverride All Order allow,deny allow from all </directory> ・・・ ・・・ CustomLog /var/log/apache2/ssl_access.log combined env=!no_log ・・・ ・・・ SSLCertificateFile /etc/apache2/ssl/cacert.crt SSLCertificateKeyFile /etc/apache2/ssl/cakey.pem ・・・ ・・・ <ifmodule mod_rewrite.c> RewriteEngine On RewriteLog "/var/log/apache2/rewrite_log" RewriteLogLevel 0 RewriteCond %{HTTP_HOST} !saizensen.net$ RewriteRule ^/(.*)?$ http://%{HTTP_HOST}/$1 [L,R] </ifmodule> </virtualhost> </ifmodule>
- SSLモジュールとSSLサイトの有効化
# a2enmod ssl # a2ensite default-ssl # /etc/init.d/apache2 restart
無効化するときは、a2dismod, a2dissite を使う。
# a2dissite default-ssl # a2dismod ssl # /etc/init.d/apache2 restart
- ルーター側の設定でポート443番をOPENする。
- Comments: 0
- Trackbacks: 0
[Debian]Debian lennyで1からサーバーを作ってみる – apacheをインストール
- Webサーバー構築(apacheをインストール)
# aptitude install apache2 # aptitude clean
- apacheを設定
# vi /etc/apache2/conf.d/security
ServerTokens Full ↓ ServerTokens Prod ServerSignature On ↓ ServerSignature Off
# vi /etc/apache2/mods-enabled/mime.conf
#AddHandler cgi-script .cgi ↓ AddHandler cgi-script .cgi .pl
# vi /etc/apache2/apache2.conf
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined ↓ LogFormat "%v:%p %h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined 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 # LogFormat設定群の下へ追記↓ # # For a single logfile with access, agent, and referer information # (Combined Logfile Format), use the following directive: # SetEnvIf Request_URI "default\.ida" no_log ← 追加(wormからのアクセスをログに記録しない) SetEnvIf Request_URI "cmd\.exe" no_log ← 〃 SetEnvIf Request_URI "root\.exe" no_log ← 〃 SetEnvIf Request_URI "Admin\.dll" no_log ← 〃 SetEnvIf Request_URI "NULL\.IDA" no_log ← 〃 SetEnvIf Remote_Addr 192.168.0 no_log ← 追加(内部からのアクセスをログに記録しない) SetEnvIf Remote_Addr 127.0.0.1 no_log ← 追加(自ホストからのアクセスをログに記録しない) CustomLog /var/log/apache2/access.log combined env=!no_log CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined ↓ CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined env=!no_log(admin.saizensen.netも作っておく。)
# vi /etc/apache2/sites-available/default
コピペするときは< /directory>の /は半角に修正してください。
<virtualhost *:80> ServerAdmin webmaster@saizensen.net ServerName saizensen.net:80 ServerAlias www.saizensen.net DocumentRoot /var/www/html <directory /> Options FollowSymLinks AllowOverride None < /directory> <directory /var/www/html> Options Includes ExecCGI FollowSymLinks AllowOverride All Order allow,deny allow from all </directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined env=!no_log Alias /doc/ "/usr/share/doc/" <directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </directory> </virtualhost> <virtualhost *:80> ServerAdmin webmaster@saizensen.net ServerName admin.saizensen.net:80 DocumentRoot /var/www/admin <directory /> Options FollowSymLinks AllowOverride None < /directory> <directory /var/www/admin> Options Includes ExecCGI FollowSymLinks AllowOverride All Order allow,deny allow from all </directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </directory> ErrorLog /var/log/apache2/admin-error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/admin-access.log combined env=!no_log Alias /doc/ "/usr/share/doc/" <directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </directory> </virtualhost>
# ln -s /usr/bin/perl /usr/local/bin/perl # mkdir /var/www/html # mkdir /var/www/admin # chown -R hoge.hoge /var/www ← hogeは適当な一般ユーザーへ # apache2ctl configtest # /etc/init.d/apache2 restart
- ルータの設定でPort80(TCP)を開ける。
- SSIを使えるようにする。
# a2enmod include # /etc/init.d/apache2 restart
- リダイレクト出来るようにする。
# a2enmod rewrite # /etc/init.d/apache2 restart
- PHPを使えるようにする。
# aptitude install libapache2-mod-php5 # aptitude clean # vi /etc/php5/apache2/php.ini
post_max_size = 8M ↓ post_max_size = 64M magic_quotes_gpc = On ↓ magic_quotes_gpc = Off upload_max_filesize = 32M ↓ upload_max_filesize = 64M
# /etc/init.d/apache2 reload
- .htpasswdを作る。
- .htpasswdファイルを新規作成する場合(hogeは適当な一般ユーザーへ)
# htpasswd -b -c /etc/apache2/.htpasswd hoge ******
- 既存の.htpasswdファイルへユーザーを追加する場合(hogehogeは適当な一般ユーザーへ)
# htpasswd -b /etc/apache2/.htpasswd hogehoge ******
- ユーザー登録確認
# cat /etc/apache2/.htpasswd
- .htaccess作成
# vi /var/www/admin/.htaccess
AuthUserFile /etc/apache2/.htpasswd AuthGroupFile /dev/null AuthName "secret page" AuthType Basic #require valid-user ←.htpasswdに登録してある全てのユーザー名で認証できるようにする場合 require user hoge ←.htpasswdに登録してある特定のユーザー名でのみ認証できるようにする場合
- apache再起動
# /etc/init.d/apache2 reload
- .htpasswdファイルを新規作成する場合(hogeは適当な一般ユーザーへ)
- mod_deflate設定
# vi /etc/apache2/mods-enabled/deflate.conf
<ifmodule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml # 送信先ブラウザがNetscape 4.xの場合はtext/htmlのみ圧縮 BrowserMatch ^Mozilla/4 gzip-only-text/html # 送信先ブラウザがNetscape 4.06-4.08の場合は圧縮しない BrowserMatch ^Mozilla/4\.0[678] no-gzip # 送信先ブラウザがMSIEの場合は全て圧縮する BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html </ifmodule>
# /etc/init.d/apache2 restart
- Comments: 9
- Trackbacks: 5
[Debian]Debian lennyで1からサーバーを作ってみる – bindをインストール
- DNSサーバーを構築(bindをインストール)
# aptitude install bind9 # aptitude clean
- bindを設定
# vi /etc/bind/named.conf.options
options { directory "/var/cache/bind"; version "unknown"; // If there is a firewall between you and nameservers you want // to talk to, you may need to fix the firewall to allow multiple // ports to talk. See http://www.kb.cert.org/vuls/id/800113 // If your ISP provided one or more IP addresses for stable // nameservers, you probably want to use them as forwarders. // Uncomment the following block, and insert the addresses replacing // the all-0's placeholder. // forwarders { // 0.0.0.0; // }; allow-query { localhost; localnets; }; forward first; forwarders { 192.168.0.1; }; auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; }; };# vi /etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server named. // // Please read /usr/share/doc/bind9/README.Debian.gz for information on the // structure of BIND configuration files in Debian, *BEFORE* you customize // this configuration file. // // If you are just adding zones, please do that in /etc/bind/named.conf.local include "/etc/bind/named.conf.options"; // prime the server with knowledge of the root servers //zone "." { // type hint; // file "/etc/bind/db.root"; //}; // be authoritative for the localhost forward and reverse zones, and for // broadcast zones as per RFC 1912 //zone "localhost" { // type master; // file "/etc/bind/db.local"; //}; //zone "127.in-addr.arpa" { // type master; // file "/etc/bind/db.127"; //}; //zone "0.in-addr.arpa" { // type master; // file "/etc/bind/db.0"; //}; //zone "255.in-addr.arpa" { // type master; // file "/etc/bind/db.255"; //}; include "/etc/bind/named.conf.local";# vi /etc/bind/named.conf.local
// // Do any local configuration here // // Consider adding the 1918 zones here, if they are not used in your // organization //include "/etc/bind/zones.rfc1918"; view "internal" { match-clients { localhost; localnets; }; match-destinations { localnets; }; recursion yes; zone "." { type hint; file "/etc/bind/db.root"; }; zone "localhost" { type master; file "/etc/bind/db.local"; }; zone "127.in-addr.arpa" { type master; file "/etc/bind/db.127"; }; zone "0.in-addr.arpa" { type master; file "/etc/bind/db.0"; }; zone "255.in-addr.arpa" { type master; file "/etc/bind/db.255"; }; include "/etc/bind/named.saizensen.net.zone"; }; view "external" { match-clients { any; }; match-destinations { any; }; recursion no; zone "." { type hint; file "/etc/bind/db.root"; }; include "/etc/bind/named.saizensen.net.zone.wan"; };# vi /etc/bind/named.saizensen.net.zone
zone "saizensen.net" { type master; file "/etc/bind/saizensen.net.db"; #allow-update { none; }; }; zone "0.168.192.in-addr.arpa" { type master; file "/etc/bind/0.168.192.in-addr.arpa.db"; #allow-update { none; }; };# vi /etc/bind/named.saizensen.net.zone.wan
zone "saizensen.net" { type master; file "/etc/bind/saizensen.net.db.wan"; allow-query { any; }; #allow-transfer { 123.50.202.226; 38.110.146.192; }; ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) #notify yes; ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) #allow-update { none; }; }; zone "239.249.122.in-addr.arpa" { type master; file "/etc/bind/239.249.122.in-addr.arpa.db"; #allow-update { none; }; };# vi /etc/bind/saizensen.net.db
$TTL 86400 @ IN SOA saizensen.net. root.saizensen.net.( 2009080401 ; Serial 3600 ; Refresh 900 ; Retry 604800 ; Expire 86400 ; Minimum ) IN NS saizensen.net. IN MX 10 saizensen.net. IN A 192.168.0.2 @ IN A 192.168.0.2 mail IN A 192.168.0.2 ns IN A 192.168.0.2 www IN A 192.168.0.2 admin IN A 192.168.0.2 test IN A 192.168.0.2 * IN A 192.168.0.2# vi /etc/bind/saizensen.net.db.wan
$TTL 86400 @ IN SOA ns.saizensen.net. root.saizensen.net.( 2009080401 ; serial 3600 ; refresh (1 hour) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; negative (1 day) ) IN NS ns.saizensen.net. ; IN NS ns1.maihama-net.com. ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) ; IN NS ns2.maihama-net.com. ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) IN MX 10 mail.saizensen.net. ns IN A 122.249.239.71 @ IN A 122.249.239.71 www IN A 122.249.239.71 mail IN A 122.249.239.71 admin IN A 122.249.239.71 test IN A 122.249.239.71 saizensen.net. IN TXT "v=spf1 a mx ~all"# vi /etc/bind/0.168.192.in-addr.arpa.db
$TTL 86400 ; 1 day @ IN SOA ns.saizensen.net. root.saizensen.net.( 2009080401 ; serial 3600 ; refresh (1 hour) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) IN NS ns.saizensen.net. 2 IN PTR ns.saizensen.net. 2 IN PTR www.saizensen.net. 2 IN PTR mail.saizensen.net. 2 IN PTR admin.saizensen.net. 2 IN PTR test.saizensen.net.# vi /etc/bind/239.249.122.in-addr.arpa.db
$TTL 86400 @ IN SOA ns.saizensen.net. root.saizensen.net.( 2009080401 ; serial 3600 ; refresh (1 hour) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; negative (1 day) ) IN NS ns.saizensen.net. 71 IN PTR saizensen.net.# /etc/init.d/bind9 restart
- 動作確認
# dig saizensen.net # dig -x 192.168.0.2 # dig www.google.co.jp # dig -x ***.***.***.*** ← グローバルIP
- ネットワーク設定を編集
# vi /etc/network/interfaces
dns-nameservers 192.168.0.1 ← この行を消す
- システム再起動
# reboot
- ルータの設定でPort53(TCP/UDP)を開ける。
- バーチャルホスト用にドメインを設定する。(例:virtualhost.netというドメインの場合)
# vi /etc/bind/named.conf.local
// // Do any local configuration here // // Consider adding the 1918 zones here, if they are not used in your // organization //include "/etc/bind/zones.rfc1918"; view "internal" { ・・・ ・・・ include "/etc/bind/named.saizensen.net.zone"; include "/etc/bind/named.virtualhost.net.zone"; ← 追記 }; view "external" { ・・・ ・・・ include "/etc/bind/named.saizensen.net.zone.wan"; include "/etc/bind/named.virtualhost.net.zone.wan"; ← 追記 };# vi /etc/bind/named.virtualhost.net.zone
zone "virtualhost.net" { type master; file "/etc/bind/virtualhost.net.db"; #allow-update { none; }; };# vi /etc/bind/named.virtualhost.net.zone.wan
zone "virtualhost.net" { type master; file "/etc/bind/virtualhost.net.db.wan"; allow-query { any; }; #allow-transfer { 123.50.202.226; 38.110.146.192; }; ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) #notify yes; ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) #allow-update { none; }; };# vi /etc/bind/virtualhost.net.db
$TTL 86400 @ IN SOA virtualhost.net. root.virtualhost.net.( 2009080401 ; Serial 3600 ; Refresh 900 ; Retry 604800 ; Expire 86400 ; Minimum ) IN NS virtualhost.net. IN MX 10 virtualhost.net. IN A 192.168.0.2 @ IN A 192.168.0.2 mail IN A 192.168.0.2 ns IN A 192.168.0.2 www IN A 192.168.0.2 admin IN A 192.168.0.2 test IN A 192.168.0.2 * IN A 192.168.0.2# vi /etc/bind/virtualhost.net.db.wan
$TTL 86400 @ IN SOA ns.virtualhost.net. root.virtualhost.net.( 2009080401 ; serial 3600 ; refresh (1 hour) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; negative (1 day) ) IN NS ns.virtualhost.net. ; IN NS ns1.maihama-net.com. ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) ; IN NS ns2.maihama-net.com. ← セカンダリーネームサーバーとしてマイハマネットを使う場合はコメントアウトを外す。(マイハマネットへ登録後) IN MX 10 mail.virtualhost.net. ns IN A 122.249.239.71 @ IN A 122.249.239.71 www IN A 122.249.239.71 mail IN A 122.249.239.71 admin IN A 122.249.239.71 test IN A 122.249.239.71 virtualhost.net. IN TXT "v=spf1 a mx ~all"# /etc/init.d/bind9 restart
- Comments: 0
- Trackbacks: 2
[Debian]Debian lennyで1からサーバーを作ってみる – clamavをインストール
- clamavをインストール。
# aptitude install clamav clamav-daemon clamav-testfiles clamassassin clamav-freshclam unrar lha
- 手動でアップデート
# freshclam
- デーモンとして実行し、1日に24回更新のチェックを行う
# freshclam -d -c 24
- clamav cron設定
# vi clamscan
#!/bin/bash LANG=C PATH=/usr/bin:/bin # excludeopt setup excludelist=/root/clamscan.exclude if [ -s $excludelist ]; then for i in `cat $excludelist` do if [ $(echo "$i"|grep \/$) ]; then i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d` excludeopt="${excludeopt} --exclude-dir=$i" else excludeopt="${excludeopt} --exclude=$i" fi done fi # signature update freshclam > /dev/null # virus scan CLAMSCANTMP=`mktemp` clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1 [ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \ # report mail send grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root rm -f $CLAMSCANTMP - clamscanへ実行権を付与。
# chmod +x clamscan
- スキャン対象外設定。
# echo "/backup/" >> clamscan.exclude # echo "/proc/" >> clamscan.exclude # echo "/sys/" >> clamscan.exclude
- cron.dailyへ移動。
# mv clamscan /etc/cron.daily/
- Comments: 0
- Trackbacks: 2
- Search
- Feeds
- Meta