SSブログ

Syslogサーバー設定メモ [Linux]

◆/etc/rsyslog.confの編集

次の行のコメントを外して保存する。

# Provides UDP syslog reception
#$ModLoad imudp (←ここと)
#$UDPServerRun 514 (←ここ)

◆/etc/rsyslog.d/hoge.confの作成

以下を記述して保存。local6で受ける。Log Levelを表示する。

$template ShowLogLevel,"%timegenerated% %hostname% %syslogpriority-text% %programname%:%msg%\n"
local6.* /var/log/hoge.log;ShowLogLevel

◆rsyslogdに設定を反映

rsyslogdを再起動して変更を反映する。

# service rsyslog restart

◆Firewall(iptables)設定

[CentOS6]
514/udpを通すようにするため、/etc/sysconfig/iptablesの、
通信をREJECTするINPUTルールよりも前に次の行を追加して保存する。

-A INPUT -m state --state NEW -m udp -p udp --dport 514 -j ACCEPT

以下を実行して変更を反映する。

# /etc/init.d/iptables restart

[CentOS7]
次のコマンドを実行する。

# firewall-cmd --add-service=syslog --zone=public --permanent

◆ログが吐かれていることの確認

# tail -f /var/log/hoge.log

◆logrotateの設定

/etc/logrotate.d/syslogの"{"の直前に次の行を追加する。

/var/log/hoge

次のコマンドを実行するとlogrotateが実行され結果を確認できる。

# logrotate -f /etc/logrotate.conf

nice!(0)  コメント(0) 

Amazon EC2でのPostfixリレー設定 with SASL認証 [Linux]

実はまだうまくいっていない。gmailだとできるけどFromがgmailアドレスになってしまう…。

[環境]
t2.micro with RHEL7

[事前準備]
タイムゾーンをJSTに設定
# timedatectl set-timezone Asia/Tokyo
procmailをインストール
# yum install procmail
cyrus関係をインストール
# yum install cyrus-*

[/etc/hosts]
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#
172.xxx.xxx.xxx mail.tabuyan.site www.tabuyan.site tabuyan.site

[main.cf]
myhostname = mail.tabuyan.site
mydomain = tabuyan.site
myorigin = $mydomain
inet_interfaces = $myhostname, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 450
mynetworks_style = host
relayhost = [mail.so-net.ne.jp]:587
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mail_spool_directory = /var/spool/mail
mailbox_command = /bin/procmail -a $DOMAIN -d $LOGNAME
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)

# for ":include:", etc.
allow_mail_to_commands = alias,forward,include

# smtp auth
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain, login
smtp_sasl_type = cyrus
smtp_use_tls = yes
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt

# transport
transport_maps = hash:/etc/postfix/transport

# anti spam
smtpd_recipient_restrictions =
permit_mynetworks,
check_client_access regexp:/etc/postfix/client_restrictions,
reject_unauth_destination,
reject_unknown_client

# verify
disable_vrfy_command = yes

[sasl_passwd]
[mail.so-net.ne.jp]:587 user@xxx.so-net.ne.jp:password

# chmod 600 sasl_passwd
# postmap sasl_passwd

[transport]
* smtp:[mail.so-net.ne.jp]:587

# postmap transport

[postfixの再起動]
# systemctl restart postfix

[OS起動時にpostfixも自動起動させる]
# systemctl enable postfix

[client_restrictions]
/^[^\.]*[0-9][^0-9\.]+[0-9]/ 450 may not be mail exchanger
/^[^\.]*[0-9]{5}/ 450 may not be mail exchanger
/^([^\.]+\.)?[0-9][^\.]*\.[^\.]+\..+\.[a-z]/ 450 may not be mail exchanger
/^[^\.]*[0-9]\.[^\.]*[0-9]-[0-9]/ 450 may not be mail exchanger
/^[^\.]*[0-9]\.[^\.]*[0-9]\.[^\.]+\..+\./ 450 may not be mail exchanger
/^(dhcp|dialup|ppp|adsl)[^\.]*[0-9]/ 450 may not be mail exchanger

[ログの時刻がずれているのを修正]
# mkdir /var/spool/postfix/etc
# cp -p /etc/localtime /var/spool/postfix/etc
# systemctl restart postfix
# systemctl restart rsyslog

nice!(1)  コメント(0) 
共通テーマ:パソコン・インターネット

smtp認証を有効にしたpostfixのインストールメモ(その3) [Linux]

※OSがVine Linux 5.0の場合。

最新版を入れたいので、rpmで提供されているpostfixは削除する。
/etc/init.d/postfixはバックアップしておく。
mdadmがpostfixに依存しているのでそのままでは削除できない。
mdadmも不要なので合わせて削除した。
# cp -p /etc/init.d/postfix /etc/init.d/postfix.bak
# rpm -e mdadm
# rpm -e postfix

rpmを削除すると、ユーザーpostfixが消えてしまうので再登録する。
# /usr/sbin/groupadd -g 101 postfix
# /usr/sbin/groupadd -g 102 postdrop
# /usr/sbin/useradd -u 100 -g 101 -s /bin/false postfix
 (postfixでログインできないようにする ↑)
# passwd postfix (一応パスワードは設定)
# vi /etc/ftpusers (postfixでftpアクセスもできないように以下を追加)

postfix


SMTP認証に必要なモジュールをインストールする。
# apt-get install db4 db4-devel
# apt-get install cyrus-sasl cyrus-sasl-devel cyrus-sasl-md5 cyrus-sasl-plain

★postfix-2.6.5
http://www.postfix.org/download.html
$ make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl" AUXLIBS="-lsasl2"
$ make
# make install
パラメーターを聞かれるがすべてデフォルトのまま[Enter]を叩く。

# vi /etc/postfix/main.cf (以下を追加)

relayhost = [mail.so-net.ne.jp]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/isp_auth
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain, login


# vi /etc/postfix/isp_auth

mail.so-net.ne.jp hoge@aa2.so-net.ne.jp:password


# /usr/sbin/postmap /etc/postfix/isp_auth

バックアップしておいた/etc/init.d/postfixを元に戻し、
chkconfigで自動起動するように設定する。
# mv /etc/init.d/postfix.bak /etc/init.d/postfix
# /sbin/chkconfig --add postfix
# /sbin/chkconfig postfix on


smtp認証を有効にしたpostfixのインストールメモ(その2) [Linux]

※OSがVine Linux 4.2の場合。

最新版を入れたいので、rpmで提供されているpostfixは削除する。
# rpm -e postfix

rpmを削除すると、ユーザーpostfixが消えてしまうので再登録する。
# /usr/sbin/groupadd -g 101 postfix
# /usr/sbin/groupadd -g 102 postdrop
# /usr/sbin/useradd -u 100 -g 101 -s /bin/false postfix
 (postfixでログインできないようにする ↑)
# passwd postfix (一応パスワードは設定)
# vi /etc/ftpusers (postfixでftpアクセスもできないように以下を追加)

postfix


SMTP認証に必要なモジュールをインストールする。
# apt-get install db4 db4-devel
# apt-get install cyrus-sasl cyrus-sasl-devel cyrus-sasl-md5 cyrus-sasl-plain

★postfix-2.6.2
http://www.postfix.org/download.html
$ make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl" AUXLIBS="-lsasl2"
$ make
# make install
パラメーターを聞かれるがすべてデフォルトのまま[Enter]を叩く。

# vi /etc/postfix/main.cf (以下を追加)

relayhost = [mail.so-net.ne.jp]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/isp_auth
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain, login


# vi /etc/postfix/isp_auth

mail.so-net.ne.jp hoge@aa2.so-net.ne.jp:password


# /usr/sbin/postmap /etc/postfix/isp_auth

ntpdの設定メモ [Linux]

※OSはVine Linux 4.2。

# rpm -q ntp
ntp-4.2.0-10vl4

# vi /etc/ntp.conf

server ntp.nict.jp server ntp.jst.mfeed.ad.jp server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 driftfile /etc/ntp/drift multicastclient # listen on default 224.0.1.1 broadcastdelay 0.008 authenticate no

# touch /etc/ntp/drift

# /etc/init.d/ntpd start

# /sbin/chkconfig ntpd on

# /usr/sbin/ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp.nict.jp     .NICT.           1 u   23   64  377   12.929  -11.842   2.287
+ntp.jst.mfeed.a 210.173.160.86   2 u   17   64  377    8.081   -9.032   2.538
 LOCAL(0)        LOCAL(0)        10 l    9   64  377    0.000    0.000   0.004

# /sbin/iptables -I RH-Firewall-1-INPUT 13 -p udp -m state --state NEW -m udp --dport 123 -j ACCEPT
※REJECTの前、13番目に入れるように設定。

davfs2でWebDAVサーバーをファイルシステムとしてマウントする [Linux]

※OSはVine Linux 4.2。

davfs2のソースを入手する。

http://ftp.twaren.net/Unix/NonGNU/davfs2/
( http://savannah.nongnu.org/projects/davfs2 )
⇒davfs2-1.4.1.tar.gz

Vine 4.2は標準ではfuse-develが入っていないのでインストールする。

# apt-get install fuse-devel

aptでインストールできるneonではdavfsのconfigure時に
バージョンが古いと怒られるのでソースからmakeする。
 
http://www.webdav.org/neon/
⇒neon-0.28.5.tar.gz

$ cd neon-0.28.5
$ ./configure --with-ssl=openssl --enable-shared
$ make
# make install

neonは/usr/local/libにインストールされる。
システムのライブラリパスが通っていなければ下記を行う。

# vi /etc/ld.so.conf

/usr/local/lib ←追加

# ldconfig

davfsのmake前にソースを一部修正する。
→webdavサーバー(https)のSSL証明書が古いなどの場合に出る
 先に進むかどうかの確認入力をスキップしたいため。
※接続先が安全なサーバーであることが確認されていること!!

$ cd davfs2-1.4.1/src
$ cp -p webdav.c webdav.c.org
$ vi webdav.c
/* 以下の部分をコメントアウトする */
        /*
        if (!ret) {
            printf(_("You only should accept this certificate, if you can\n"
                     "verify the fingerprint! The server might be faked\n"
                     "or there might be a man-in-the-middle-attack.\n"));
            printf(_("Accept certificate for this session? [y,N] "));
            char *s = NULL;
            size_t n = 0;
            ssize_t len = 0;
            len = getline(&s, &n, stdin);
            if (len < 0)
                abort();
            if (rpmatch(s) < 1)
                ret = -1;
            free(s);
        }
        */

$ cd ..
$ ./configure
$ make
# make install

# cd /usr/local/etc/davfs2
# vi davfs.conf

dav_user root ←修正 (rootでmountする場合)
dav_group root ←修正 (rootでmountする場合)
proxy fqdn.of.proxy.server:port ←修正 (proxyサーバー利用の場合)
ask_auth 0 ←修正 (proxyサーバーが認証不要の場合)

# vi secret

https://fqdn.of.webdav.server username password

以上で設定は完了。次のようにしてマウントできる。(rootの場合!)

# mount -t davfs https://fqdn.of.webdav.server /mnt/webdav

SMTP認証を有効にしたpostfixのインストールメモ [Linux]

★db-4.7.25
http://www.oracle.com/technology/software/products/berkeley-db/index.html
$ cd build_unix
$ ../dist/configure
$ make
# make install

★cyrus-sasl-2.1.22
http://cyrusimap.web.cmu.edu/downloads.html#sasl
$ ./configure -with-dblib=berkeley --with-bdb-libdir=/usr/local/BerkeleyDB.4.7/lib --with-bdb-incdir=/usr/local/BerkeleyDB.4.7/include
$ make check
# make install
# ln -s /usr/local/lib/sasl2 /usr/lib

★postfix-2.5.6
http://www.postfix.org/download.html
$ make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/include/sasl" AUXLIBS="-L/usr/local/lib -lsasl2"
$ make
# make install
※パラメーターを聞かれるがすべてデフォルトのまま[Enter]

# vi /etc/postfix/main.cf
relayhost = [mail.so-net.ne.jp]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/isp_auth
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain, login

# vi /etc/postfix/isp_auth
mail.so-net.ne.jp hoge@aa2.so-net.ne.jp:password

# /usr/sbin/postmap /etc/postfix/isp_auth


Apache2でのDigest認証 インストール&設定覚え書き [Linux]

$ ./configure --enable-auth-digest=shared --enable-so
$ make
$ su
# make install
# ln -s /usr/local/httpd-2.x.x /usr/local/apache
# cd modules/aaa
# /usr/local/apache/bin/apxs -D DEV_RANDOM -c -a -i ./mod_auth_digest.c

# vi /usr/local/apache/conf/httpd.conf

<Directory "/usr/local/httpd-2.x.x/htdocs">
    :
    AllowOverride AuthConfig FileInfo Limit ←修正
    :
</Directory>

LoadModule auth_digest_module modules/mod_auth_digest.so ←追加


# htdigest -c /usr/local/apache/.htdigest REALM USERNAME

# mkdir /usr/local/apache/htdocs/HOGE
# vi /usr/local/apache/htdocs/HOGE/.htaccess

AuthType Digest
AuthName "REALM"
AuthDigestDomain /HOGE/
AuthDigestProvider file
AuthUserFile /usr/local/apache/.htdigest
Satisfy any
order deny,allow
deny from all
require user USERNAME



この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。