Hatena::ブログ(Diary)

konbuizmの日記

2010-07-11

00:21

Postfix で同一ホストに master を 25, 10025 の2つ起動させ、10025 は 25 向けに relayhost する設定

00:21

$ postconf mail_version
mail_version = 2.6.5
$ cat /etc/postfix_10025/main.cf
inet_interfaces = loopback-only
mydestination = 
myhostname = not-exists-domain.example.com
mynetworks_style = host
smtp_bind_address = 127.0.0.1

relayhost = [127.0.0.1]

data_directory = /var/lib/postfix_10025
queue_directory = /var/spool/postfix_10025
syslog_name = postfix_10025/smtpd

$ cat /etc/postfix_10025/master.cf | grep 10025
10025      inet  n       -       -       -       -       smtpd
$

tips.

  • Postfix が Listen する port 番号は master.cf に記載する。
  • smtp_bind_address で 127.0.0.1 を指定しても inet_interfaces のデフォルト all を野放しにしておくと、 relayhost 設定が “mail for [127.0.0.1] loops back to myself" となり配送できない。
  • 起動方法は...いろいろあるが... postfix -c /etc/postfix_10025 start が使える。
  • myhostname を 25 の postfix と異なるものにしてやらないと、ループと判定され配送できない。
  • syslog_name を変更させないと mail.log を見ても 25 の postfix か 10025 の postfix かの判別ができず、困る。
  • data_directory はあまり調べてない。 25 と 10025 の postfix で共有させていない設定だがもしかしたら設定誤っているかもしれない。とはいえ、分離しておいたほうが問題は無いだろう。

2010-07-08

00:28

logrotate と連携して圧縮ローテートを実施するスクリプト

00:28

#!/bin/bash

#---------------------------------------------------------------------
# config

declare -r  logrotate_logfile=/var/log/local0.log
declare -ir logrotate_start=0
declare -ir logrotate_rotate=3

declare -ir mylogrotate_rotate=4

#---------------------------------------------------------------------
# sub

usage() {
    echo "usage: mylogrotate.bash [-d]" >&2
    exit 1
}

confess() {
    local mess max i line src

    mess=$1
    let max=${#BASH_LINENO[@]}-1

    line=${BASH_LINENO[0]}
    src=${BASH_SOURCE[1]}
    echo "$mess at $src line $line" >&2

    i=1
    while [ $i -lt $max ]; do
        line=${BASH_LINENO[$i]}
        src=${BASH_SOURCE[`expr $i + 1`]}
        echo "	${FUNCNAME[$i]}() called at $src line $line" >&2
        let i=$i+1
    done

    exit 1
}

#---------------------------------------------------------------------
# main

opt_debug=0
while getopts "d" flag; do
    case $flag in
        \?) usage;;
        d) opt_debug=1;;
    esac
done

let last=$logrotate_start+$logrotate_rotate+$mylogrotate_rotate-1
let first=$logrotate_start+$logrotate_rotate-1
for i in `seq $last -1 $first`; do
    let dst_index=$i+1
    dst=$logrotate_logfile.$dst_index.gz
    if [ $i -ne $first ]; then
        src=$logrotate_logfile.$i.gz
        if [ $opt_debug -ne 0 ]; then
            echo "mv -f $src $dst"
        else
            if [ -f $src ]; then
                mv -f $src $dst || confess "rename failed"
            fi
        fi
    else
        src=$logrotate_logfile.$i
        if [ $opt_debug -ne 0 ]; then
            echo "gzip < $src > $dst"
            echo "chmod 600 $dst"
        else
            if [ -f $src ]; then
                gzip < $src > $dst || confess "gzip failed"
                chmod 600 $dst || confess "chmod failed"
            fi
        fi
    fi
done

let dst_index=$last+1
dst=$logrotate_logfile.$dst_index.gz
if [ $opt_debug -ne 0 ]; then
    echo "rm -f $dst"
else
    if [ -f $dst ]; then
        rm -f $dst || confess "remove failded"
    fi
fi

exit

次のようなlogrotate.conf とあわせて使う。

$ cat logrotate.conf 
/var/log/local0.log {
    daily
    start 0
    rotate 3
    create 0600 root root
    sharedscripts
    postrotate
	/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /path/to/mylogrotate.bash 2> /dev/null || true
    endscript
}

2010-02-08

GW-DS54GR on Ubuntu 9.10 Desktop i386 で無線LAN接続

00:00

1. GW-DS54GR を PCI スロットに刺した後、 Ubuntu が起動しなくなった。日本語フォーラムで解消方法を見つけた。少しカスタマイズして設定したところ起動するようになった。

$ cp -pi /etc/modprobe.d/blacklist.conf{,.`date +%F`}
$ vim /etc/modprobe.d/blacklist.conf
$ diff /etc/modprobe.d/blacklist.conf.2010-02-07 /etc/modprobe.d/blacklist.conf
55a56,60
> 
> # Sun Feb  7 22:04:17 JST 2010
> blacklist r8180
> blacklist rtl8180
> blacklist rtl8187
$ 

2. ndiswrapper を使用して Windowsドライバを使ってデバイスの認識を試みる。試したところ、製品付属CDROM内の Windows 2000 ドライバがうまく動くことがわかった。ちなみに、Webからダウンロードした WinXP 用のドライバは /var/log/messages に Can't load driver と出力されて利用できなかった。

$ sudo ndiswrapper -i ~/WIN2000/net8185.inf
$ sudo ndiswrapper -l
net8185 : driver installed
	device (10EC:8185) present (alternate driver: rtl8180)
$ sudo depmod -a
$ sudo modprobe ndiswrapper

3. WPA の設定は以下の通り。設定は ubuntu 英語フォーラムから。設定するにあたって、 iwlist scan の出力が参考になる。CCMP にするのか TKIP にするのか等の判断/確認に便利。

$ cat /etc/network/interfaces 
auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.1.20
netmask 255.255.255.0
gateway 192.168.1.1
wpa-driver wext
wpa-ssid ひみつ
wpa-ap-scan 1
wpa-proto RSN
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk ひみつ
$

4. 接続APAppleTimeCapsule 2.0TB で成功を確認。なお、沖電気の UG01OK とは接続できなかった。

副作用ワークアラウンド

上記一連の作業後に気づいた副作用が1点。無線LANカードを認識させた後からか、マシンをリブートできなくなった。 shutdown -r を実行したり、本体のリセットボタンを押すと、 ビデオボードメモリチェック→BIOS画面→GRUB画面→OS起動となるはずが、 ビデオボードメモリチェック→BIOS画面→ビデオボードメモリチェック→...と無限ループになる。しかし、おもちゃサーバなので気にしない。つながればいいってことで。

副作用、とは違うかもしれないが。無線LAN接続がたまに切断する事象を確認した。別のサーバから ubuntu への ping が届かなくて困った。 ubuntu からデフォルトGWあたりに ping を飛ばしてやるとうまく接続できるようになることがわかった。そのため、以下の行を crontab に追加した。

0 * * * * ping -c 1 192.168.1.1 2&>1 >/dev/null

参考文献

  • GW-DS54GR 装着後、ブートできなくなった問題を解消した

https://forums.ubuntulinux.jp/viewtopic.php?id=909

https://help.ubuntu.com/community/WifiDocs/Driver/Ndiswrapper

  • /etc/networking/interfaces の記述方法がある

http://ubuntuforums.org/showthread.php?t=202834

EURDAサイタマEURDAサイタマ 2010/02/14 13:04 ありがとう!これでうちも9.10に乗り換えできたお( ^ω^)
今までフリーズしてて諦めていましたorz
こちらではRealtekのLinux用ドライバで問題なく認識しました。( ^ω^)ニコッ

2010-02-06

ubuntu 9.10 desktop i386 に Oracle XE をインストール

20:23

$ sudo dpkg -i oracle-xe_10.2.0.1-1.0_i386.deb 
Selecting previously deselected package oracle-xe.
(Reading database ... 129671 files and directories currently installed.)
Unpacking oracle-xe (from oracle-xe_10.2.0.1-1.0_i386.deb) ...
Setting up oracle-xe (10.2.0.1-1.0) ...
update-rc.d: warning: /etc/init.d/oracle-xe missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Executing Post-install steps...
-e You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.


Processing triggers for desktop-file-utils ...
Processing triggers for man-db ...
Processing triggers for sreadahead ...
sreadahead will be reprofiled on next reboot
$
  • sreadahead は起動していないらしい。sreadahead は SSD 用の前方よみこみ実装らしい。依存関係でインストールしただけだろう。まあいいや、無視する。
  • oracle-xe configure を実行
$ sudo /etc/init.d/oracle-xe configure

Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express 
Edition.  The following questions will determine whether the database should 
be starting upon system boot, the ports it will use, and the passwords that 
will be used for database accounts.  Press <Enter> to accept the defaults. 
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of 
different passwords for each database account.  This can be done after 
initial configuration: password
Confirm the password: password

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to "http://127.0.0.1:8080/apex"
$

ここで http://127.0.0.1:8080/apex を表示すると何やら Oracle の画面に接続できるようになる。この画面が何なのかはまだ謎のまま。

ドキュメントをあさって見る。明後日見る、かも?

2010-01-30

perl -x のお勉強

01:10

-x というオプションがあるらしい。

shebang (#!perl)が先頭に無くとも ファイル内から検索して perl スクリプトを認識させることができる。

なのでこんなことができる。

bash-3.2$ cat hoge.bash 
#!bash
<<__END__ >/dev/null
#!perl
printf <DATA>
__DATA__
in perl
__END__
perl -x $0
printf "in bash\n"
bash-3.2$ bash hoge.bash 
in perl
in bash
bash-3.2$

ひどいなあ。可読性が。絶対やら無いけど、まあ手段として覚えておくくらいならいいかも。