Nibelungen Code

Category Archives: サーバー構築

etckeeperでetc配下をバージョン管理をしよう

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

/etc配下をバージョン管理をしよう!

ということでetckeeperをインストール、する前にバージョン管理はgitで行いたいので、先にgitのインストールをする。
etckeeperを先にインストールすると一緒にbzrがインスト-ルされることになるので注意。

gitのインストール

sudo aptitude install git

これだけです。簡単ですね。

etckeeperのインストール

sudo aptitude install etckeeper

これだけです。k(ry

etckeeperはデフォルトでbzrで管理するように設定されているので、これをgitに変更する。

etckeeperの設定変更

sudo nano /etc/etckeeper/etckeeper.conf
# The VCS to use.
#VCS="hg"
VCS="git"
#VCS="bzr"
#VCS="darcs"

# Options passed to git commit when run by etckeeper.
GIT_COMMIT_OPTIONS=""

# Options passed to hg commit when run by etckeeper.
HG_COMMIT_OPTIONS=""

# Options passed to bzr commit when run by etckeeper.
BZR_COMMIT_OPTIONS=""

# Options passed to darcs record when run by etckeeper.
DARCS_COMMIT_OPTIONS="-a"

# Uncomment to avoid etckeeper committing existing changes
# to /etc automatically once per day.
#AVOID_DAILY_AUTOCOMMITS=1

# Uncomment the following to avoid special file warning
# (the option is enabled automatically by cronjob regardless).
#AVOID_SPECIAL_FILE_WARNING=1

# Uncomment to avoid etckeeper committing existing changes to
# /etc before installation. It will cancel the installation,
# so you can commit the changes by hand.
#AVOID_COMMIT_BEFORE_INSTALL=1

# The high-level package manager that's being used.
# (apt, pacman-g2, yum etc)
HIGHLEVEL_PACKAGE_MANAGER=apt

# The low-level package manager that's being used.
# (dpkg, rpm, pacman-g2, etc)
LOWLEVEL_PACKAGE_MANAGER=dpkg

リポジトリ作成と初回コミット

sudo etckeeper init
sudo etckeeper commit "init add"

あとはaptを使った更新時には自動的にコミットされるし、etckeeperインストール時に/etc/cron.daily/配下にetckeeperが作成されるので毎日自動コミットされるし、手動でコミットしたいときは

sudo etckeeper commit "コメント"

でコミットすればいいし楽ちんだね!

サブコマンドの追加

参考URL:etckeeperのつかいかた(インストール、サブコマンド追加) | http://blog.udzura.jp
etckeeperの用意されていないサブコマンドが自作できるみたい。

サブコマンド logのディレクトリ作成

sudo mkdir -p /etc/etckeeper/log.d

サブコマンドのスクリプト作成

sudo nano /etc/etckeeper/log.d/10git-log
#!/bin/sh
set -e
if [ "$VCS" = git ] && [ -d .git ]; then
    git --git-dir=/etc/.git log \
        --graph \
        --all \
        --color \
        --pretty='%x09%h %cn%x09%C(yellow)(%cr)%Creset%x09%s %Cred%d%Creset'
fi

サブコマンドのスクリプトに実行権限付与

sudo chmod +x /etc/etckeeper/log.d/10git-log

実際にコマンドを実行してみる

sudo etckeeper log
*       f256560 root    (49 minutes ago)        init add  (HEAD, master)

※実際には(49 minutes ago)の文字は黄色、(HEAD, master)の文字は赤色になってマス。

 | 
このエントリーをはてなブックマークに追加

lsyncd2+rsyncdでのミラーサーバー構築

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

いつの間にかlsyncdのバージョンが2に上がってたー。ということで設定手順をまとめねば。
前提としてOSはUbuntu 11.10以降で。

lsyncdのバージョンが1系ならlsyncd+rsyncdでのミラーサーバー構築をどうぞ。

ミラー先設定

まず、rsyncdの設定から。

sudo nano /etc/rsyncd.conf
#
# Global options
#
log file = /var/log/rsyncd/rsyncd.log
uid = root
gid = root

#
# Module options
#
[www]
path = /var/www
hosts allow = 192.168.1.101/32
hosts deny = *
read only = false

uidとgidを設定をしないとそれぞれnobody、nogroupとなります。
次にログローテートの設定。

sudo nano /etc/logrotate.d/rsyncd
/var/log/rsyncd/rsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

ログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/rsyncd
sudo logrotate -d /etc/logrotate.conf

rsyncをxinetdで動かしたいのでxinetdが入っていなければインストールする。

sudo aptitude install xinetd

そしてxinetdで動かすrsyncdの設定。
only_fromのところにはミラー元のIPを記述しておきます。

sudo nano /etc/xinetd.d/rsyncd
service rsync
{
 disable = no
 socket_type = stream
 user = root
 wait = no
 server = /usr/bin/rsync
 server_args = --daemon --config=/etc/rsyncd.conf
 only_from = 192.168.1.101/32 127.0.0.1
 log_on_failure += USERID
}

xinetdを再起動

sudo /etc/init.d/xinetd restart

ミラー元設定

いよいよミラー元の設定。
lsyncd2をインストールする。
Ubuntu 11.10 (Oneiric)以降でないとlsyncd2になっていないので注意。

sudo aptitude install lsyncd

設定ファイルのサンプルをコピーして編集する。バージョン2からはxmlではなくluaに変更になっています。
起動スクリプトの中を見てみると

sudo nano /etc/init.d/lsyncd
CONFIG=/etc/lsyncd/lsyncd.conf.lua

とあるので、/etc/lsyncd/lsyncd.conf.luaにコピーします。

sudo mkdir -p /etc/lsyncd
sudo cp -p /usr/share/doc/lsyncd/examples/lrsync.lua /etc/lsyncd/lsyncd.conf.lua

そして編集。
sourceにはミラーしたいパス、targetにはミラー先のIPとrsyncdに記述したモジュール名(今回の例ではwww)を記述しておく。
パスの最後に/がついていればその配下、ついていなければディレクトリそのものになります

sudo nano /etc/lsyncd/lsyncd.conf.lua
settings = {
	logfile = "/var/log/lsyncd/lsyncd.log",
	statusFile = "/var/run/lsyncd.stat",
	statusInterval = 1,
}

sync{
	default.rsync,
	rsyncOps = {
		"-ltr",
		"-p",
		"-avz",
		"--delete"
	},
	source="/var/www/",
	target="192.168.1.99::www/",
}

lsyncdのログローテート設定

sudo nano /etc/logrotate.d/lsyncd
/var/log/lsyncd/lsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

lsyncdのログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/lsyncd
sudo logrotate -d /etc/logrotate.conf

lsyncdをスタートさせる。

sudo /etc/init.d/lsyncd start

これでミラーされるか試してみる。

sudo touch /var/www/test

ミラー先にtestができてれば成功。
できていなければログを確認して解決してください。
ちなみにポートは873なのでiptables等で制限してる場合は許可するようにしてください。

ミラー元

iptables -A OUTPUT -p tcp -d ミラー先IP --sport 873 -j ACCEPT

ミラー先

iptables -A INPUT -p tcp -s ミラー元IP --dport 873 -j ACCEPT
 | 
このエントリーをはてなブックマークに追加

sudoersを変更してsudo時に毎回パスワードを聞かれないようにする

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

OSインストール直後にいろいろ設定を書き換えたりしていると、パスワードを入れるのが面倒になります。

通常は15分間は聞かれないのですが、これを1日に変更してみます。

sudo visudo

で編集します。

Defaults        env_reset

Defaults        env_reset,timestamp_timeout=1440

分単位なので1440は24時間のことですね。
これで1回パスワードを入力すれば24時間は再度聞かれないようになります。

 | 
このエントリーをはてなブックマークに追加

lsyncd+sshでのミラーサーバー構築

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

以前、lsyncd+rsyncdでのミラーサーバー構築にて
lsyncd+rsyncdでのミラーサーバー構築を書いたけど、やっとSSHを使用したやりかたを確認したので以下に。

秘密鍵と公開鍵を作成

ミラー元で

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hogehoge/.ssh/id_rsa):
Created directory '/home/hogehoge/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hogehoge/.ssh/id_rsa.
Your public key has been saved in /home/hogehoge/.ssh/id_rsa.pub.
The key fingerprint is:
75:28:f4:77:3f:68:93:d2:c5:7d:2a:5c:96:c9:2f:17 hogehoge@TestServer

できた公開鍵をミラー先へ

scp .ssh/id_rsa.pub hogehoge@ミラー先:/home/hogehoge/

ミラー先で

mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

ミラー元からパスワードなしでログインできることを確認

ssh hogehoge@ミラー先

ミラー元、ミラー先のid_rsa.pubを削除する

rm id_rsa.pub

ミラー元設定

lsyncdをインストールする。
Ubuntu10.10(maverick)以降でないとUbuntu公式リポジトリにないので注意。

sudo aptitude install lsyncd

設定ファイルのサンプルをコピーして編集する。
source pathにはミラーしたいパス、target pathにはミラー先のユーザ名@IP:ミラー先パスを記述しておく。(scpでファイル送るときの宛先指定と同じですね)
パスの最後に/がついていればその配下、ついていなければディレクトリそのものになります。

sudo cp -p /usr/share/doc/lsyncd/examples/lsyncd.conf.xml /etc/
sudo nano /etc/lsyncd.conf.xml
<lsyncd version="1">

<!--
This is a default config file template for lsyncd.
Actually all settings are optional, if you delete them
lsyncd will use the option value (which is likely identical
to the values specified as defaults in this template)

                                  - Happy Syncing! -

-->

<settings>
        <!--uncomment to log all debug messages.-->
        <!--debug/-->

        <!--uncomment to log only errors.-->
        <!--scarce/-->

        <!--uncomment to not detach, log to stdout/stderr.-->
        <!--no-daemon/-->

        <!--uncomment to not call any actions, run dry only.-->
        <!--dryrun/-->

        <!--uncomment to exclude file handled to rsync.-->
        <!--exclude-from filename="/tmp/exclude"/-->

        <!-- the file to log messages -->
        <logfile      filename="/var/log/lsyncd/lsyncd.log"/>

        <!--Specify the rsync (or other) binary to call-->
        <binary       filename="/usr/bin/rsync"/>

        <!--uncomment to create a file containing pid of the daemon-->
        <pidfile      filename="/var/run/lsyncd.pid"/>

        <!--this specifies the arguments handled to the rsync (or other)
                binary.

                option is the default literal.
                only '%r' will be replaced with r when recursive
                operation is wanted, d when not.

                exclude-file will be replaced with -exclude-from FILE

                source will be the source path to sync from

                destination will be the destination path to sync to -->
        <callopts>
                <option text="-lt%r"/>
                <option text="-p"/>
                <option text="-avz"/>
                <option text="--delete"/>
                <option text="--rsh=ssh"/>
                <exclude-file/>
                <source/>
                <destination/>
        </callopts>
</settings>


<directory>
        <source path="/var/www/"/>
        <target path="hogehoge@ミラー先IP:/var/www/"/>
        <!--
        or it can also be an absolute path for localhost
        <target path="/absolute/path/to/target">
        -->
</directory>

<!--
     You can specify even more than one source/destination pair,
     all will be synced.

         Please take care you do not make any with other source/target pairs.
-->
<!--directory>
        <source path="/home/axel/lsyncd-svn/3"/>
        <target path="/home/axel/lsyncd-svn/4"/>
</directory-->

</lsyncd>

lsyncdの自動起動スクリプトを作成する。

cd /etc/init.d/
sudo nano lsyncd
#!/bin/sh
### BEGIN INIT INFO
# Provides:          lsyncd
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: fast remote file copy program daemon
# Description:       start and stop lsyncd
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

PATH=$PATH:/usr/bin

# Source networking configuration.
[ -r /etc/lsyncd ] && . /etc/lsyncd

option="$SHORT_LOG $IGNORE_START_ERRORS $DEBUG"

RETVAL=0

prog="lsyncd"

start(){
        echo -n $"Starting $prog: "
        $prog $option
        RETVAL=$?
        echo
        touch /var/lock/lsyncd
        return $RETVAL
}

stop(){
        echo -n $"Stopping $prog: "
        killproc $prog
        RETVAL=$?
        echo
        rm -f /var/lock/lsyncd
        return $RETVAL
}

reload(){
        echo -n $"Reloading configuration: "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

condrestart(){
        [ -e /var/lock/lsyncd ] && restart
        return 0
}

# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status $prog
                ;;
        restart)
                restart
                ;;
        reload)
                reload
                ;;
        condrestart)
                condrestart
                ;;
        *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        RETVAL=1
esac

exit $RETVAL
sudo chmod +x lsyncd

lsyncdの起動オプションファイルを作成

sudo nano /etc/lsyncd
IGNORE_START_ERRORS="--stubborn"
#SHORT_LOG="--scarce"
#DEBUG="--debug"

lsyncdの自動起動の設定

sudo update-rc.d lsyncd defaults 56 50

たぶん以下でも可だと思う。

sudo update-rc.d lsyncd start 56 2 3 4 5 . stop 50 0 1 6  .

lsyncdのログローテート設定

sudo nano /etc/logrotate.d/lsyncd
/var/log/lsyncd/lsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

lsyncdのログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/lsyncd
sudo logrotate -d /etc/logrotate.conf

lsyncdをスタートさせる。

sudo /etc/init.d/lsyncd start

これでミラーされるか試してみる。

sudo touch /var/www/test

ミラー先にtestができてれば成功。
できていなければログを確認して解決してください。
ちなみにポートは22なのでiptables等で制限してる場合は許可するようにしてください。

 | 
このエントリーをはてなブックマークに追加

GRUBブートローダの再インストール

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

なにやらUbuntuをアップグレード(10.10から11.04)して、再起動したら

GRUB>

で止まってしまった。
ブートローダェ・・・

root ほげほげ
kernel ほげほげ
initrd ほげほげ
boot

とかやっても起動できずbusy boxがw

いろいろ試した結果(2時間くらい)、GRUBの再インストールで起動できたので、作業した手順を以下に記載。

Ubuntu Live CDから起動

サーバーが32Bitなら、32BitのLive CD、
64Bitなら、64BitのLive CDを用意する。

LVM環境なので、端末を表示させてlvm2をインストールする

sudo apt-get install lvm2

LVMボリュームをアクティブにする

sudo lvm
lvm>vgchange -ay
lvm>quit

とりあえず/mntにマウントする

sudo mount /dev/mapper/UbuntuServer-root /mnt
sudo mount /dev/sda1 /mnt/boot
sudo mount --bind /dev  /mnt/dev
sudo mount --bind /dev/pts  /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys  /mnt/sys

/dev/mapper/UbuntuServer-rootの部分は各環境に合わせて読み替えてください。

sudo vgdisplay

とか

sudo lvm vgscan

で確認したり、/dev/mapper/
の中を見てみたり。

GRUBの再インストール

sudo chroot /mnt
grub-install /dev/sda
sudo update-grub

/dev/sdaの部分は各環境に合わせて読み替えてください。

sudo fdisk -l

で確認してみたり。

再起動

一応これで、自分の環境では起動できました。

アップグレード等の作業するときはバックアップを取ってからにしましょうということで。

 | 
このエントリーをはてなブックマークに追加

lsyncd+rsyncdでのミラーサーバー構築

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

前提としてOSはUbuntu10.10以降で。

ミラー先設定

まず、rsyncdの設定から。rsyncdは標準で入ってると思います。

sudo nano /etc/rsyncd.conf
log file = /var/log/rsyncd/rsyncd.log
uid = root
gid = root

[www]
path = /var/www
hosts allow = 192.168.1.101/32
read only = false

uidとgidを設定をしないとそれぞれnobody、nogroupとなります。
次にログローテートの設定。

sudo nano /etc/logrotate.d/rsyncd
/var/log/rsyncd/rsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

ログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/rsyncd
sudo logrotate -d /etc/logrotate.conf

rsyncをxinetdで動かしたいのでxinetdが入っていなければインストールする。

sudo aptitude install xinetd

そしてxinetdで動かすrsyncdの設定。
only_fromのところにはミラー元のIPを記述しておきます。

sudo nano /etc/xinetd.d/rsyncd
service rsync
{
disable = no
socket_type = stream
user = root
wait = no
server = /usr/bin/rsync
server_args = --daemon --config=/etc/rsyncd.conf
only_from = 192.168.1.101/32 127.0.0.1
log_on_failure += USERID
}

xinetdを再起動

sudo /etc/init.d/xinetd restart

ミラー元設定

いよいよミラー元の設定。
lsyncdをインストールする。
Ubuntu10.10(maverick)以降でないとUbuntu公式リポジトリにないので注意。

sudo aptitude install lsyncd

設定ファイルのサンプルをコピーして編集する。
source pathにはミラーしたいパス、target pathにはミラー先のIPとrsyncdに記述したモジュール名(今回の例ではwww)を記述しておく。
パスの最後に/がついていればその配下、ついていなければディレクトリそのものになります。

sudo cp -p /usr/share/doc/lsyncd/examples/lsyncd.conf.xml /etc/
sudo nano /etc/lsyncd.conf.xml
<lsyncd version="1">

<!--
This is a default config file template for lsyncd.
Actually all settings are optional, if you delete them
lsyncd will use the option value (which is likely identical
to the values specified as defaults in this template)

                                  - Happy Syncing! -

-->

<settings>
        <!--uncomment to log all debug messages.-->
        <!--debug/-->

        <!--uncomment to log only errors.-->
        <!--scarce/-->

        <!--uncomment to not detach, log to stdout/stderr.-->
        <!--no-daemon/-->

        <!--uncomment to not call any actions, run dry only.-->
        <!--dryrun/-->

        <!--uncomment to exclude file handled to rsync.-->
        <!--exclude-from filename="/tmp/exclude"/-->

        <!-- the file to log messages -->
        <logfile      filename="/var/log/lsyncd/lsyncd.log"/>

        <!--Specify the rsync (or other) binary to call-->
        <binary       filename="/usr/bin/rsync"/>

        <!--uncomment to create a file containing pid of the daemon-->
        <pidfile      filename="/var/run/lsyncd.pid"/>

        <!--this specifies the arguments handled to the rsync (or other)
                binary.

                option is the default literal.
                only '%r' will be replaced with r when recursive
                operation is wanted, d when not.

                exclude-file will be replaced with -exclude-from FILE

                source will be the source path to sync from

                destination will be the destination path to sync to -->
        <callopts>
                <option text="-lt%r"/>
                <option text="-p"/>
                <option text="-avz"/>
                <option text="--delete"/>
                <exclude-file/>
                <source/>
                <destination/>
        </callopts>
</settings>


<directory>
        <source path="/var/www/"/>
        <target path="192.168.1.99::www/"/>
        <!--
        or it can also be an absolute path for localhost
        <target path="/absolute/path/to/target">
        -->
</directory>

<!--
     You can specify even more than one source/destination pair,
     all will be synced.

         Please take care you do not make any with other source/target pairs.
-->
<!--directory>
        <source path="/home/axel/lsyncd-svn/3"/>
        <target path="/home/axel/lsyncd-svn/4"/>
</directory-->

</lsyncd>

lsyncdの自動起動スクリプトを作成する。

cd /etc/init.d/
sudo nano lsyncd
#!/bin/sh
### BEGIN INIT INFO
# Provides:          lsyncd
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Should-Start:      $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: fast remote file copy program daemon
# Description:       start and stop lsyncd
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

PATH=$PATH:/usr/bin

# Source networking configuration.
[ -r /etc/lsyncd ] && . /etc/lsyncd

option="$SHORT_LOG $IGNORE_START_ERRORS $DEBUG"

RETVAL=0

prog="lsyncd"

start(){
        echo -n $"Starting $prog: "
        $prog $option
        RETVAL=$?
        echo
        touch /var/lock/lsyncd
        return $RETVAL
}

stop(){
        echo -n $"Stopping $prog: "
        killproc $prog
        RETVAL=$?
        echo
        rm -f /var/lock/lsyncd
        return $RETVAL
}

reload(){
        echo -n $"Reloading configuration: "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

condrestart(){
        [ -e /var/lock/lsyncd ] && restart
        return 0
}

# See how we were called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        status)
                status $prog
                ;;
        restart)
                restart
                ;;
        reload)
                reload
                ;;
        condrestart)
                condrestart
                ;;
        *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
        RETVAL=1
esac

exit $RETVAL
sudo chmod +x lsyncd

lsyncdの起動オプションファイルを作成

sudo nano /etc/lsyncd
IGNORE_START_ERRORS="--stubborn"
#SHORT_LOG="--scarce"
#DEBUG="--debug"

lsyncdの自動起動の設定

sudo update-rc.d lsyncd defaults 56 50

たぶん以下でも可だと思う。

sudo update-rc.d lsyncd start 56 2 3 4 5 . stop 50 0 1 6  .

lsyncdのログローテート設定

sudo nano /etc/logrotate.d/lsyncd
/var/log/lsyncd/lsyncd.log {
        daily
        missingok
        rotate 30
        compress
        delaycompress
        dateext
        notifempty
}

lsyncdのログの保存先のディレクトリを作成してローテートのテスト。

sudo mkdir -p /var/log/lsyncd
sudo logrotate -d /etc/logrotate.conf

lsyncdをスタートさせる。

sudo /etc/init.d/lsyncd start

これでミラーされるか試してみる。

sudo touch /var/www/test

ミラー先にtestができてれば成功。
できていなければログを確認して解決してください。
ちなみにポートは873なのでiptables等で制限してる場合は許可するようにしてください。

ミラー元

iptables -A OUTPUT -p tcp -d ミラー先IP --sport 873 -j ACCEPT

ミラー先

iptables -A INPUT -p tcp -s ミラー元IP --dport 873 -j ACCEPT

rsyncの経路は暗号化されていないので、SSH経由での方法はまた後日(後日っていつだ(滝汗)
書いたよ

lsyncd2の場合はこちら

 | 
このエントリーをはてなブックマークに追加

Squid配下でのApacheでアクセス元のIPを取得する

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

何も設定しないとApacheのログにはSquidのIPが書かれてしまう。

Squidの設定に

forwarded_for on

を記述する。

そしてApache側のサーバーに
X-Forwarded-ForヘッダからIPアドレスを取得するモジュールをインストールする。

sudo aptitude install libapache2-mod-rpaf

mod_rpafの設定を変更する。RPAFproxy_ipsにはSquidサーバーのIPを記述しておく。

sudo nano /etc/apache2/mods-available/rpaf.conf
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 192.168.1.201

mod_rpafが組み込まれていなければ

sudo a2enmod rpaf

Apacheを再起動

sudo service apache2 restart

これでApacheのログにアクセス元のIPが書かれてるはず。

とりあえずApacheのログさえちゃんとなればどうでもいいんです!
っていう場合にはSquidの設定はせずにmod_rpafだけインストールすればいい。
もしくはApacheのログの設定で対処しましょう。

LogFormatの%hを%{X-Forwarded-For}iに変更する。
combinedが他でも使っていて変更できない!という場合は別の名前で新たに記述しておく。reverseproxyとか。

sudo nano /etc/apache2/apache2.conf
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

Apacheを再起動

sudo service apache2 restart

ただこれだとREMOTE_ADDRがSquidのサーバーのIPなのかな?わからん。

 | 
このエントリーをはてなブックマークに追加

Zabbixシンプルチェックのicmppingについて

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

ZabbixでシンプルチェックのICMP Pingをするときにエラーになることがある。
これはZabbix ServerからPingをするときにデフォルトで

/usr/sbin/fping

を使用する設定になっているから。

OSによっては/usr/sbin/ではなく、/usr/bin/中にfpingがある場合があるので
その場所に合わせてzabbix_server.confのFpingLocationの部分を変更する。
IPv6を使用しているのであればFping6Locationも変更する。

変更後、Zabbix Serverのサービスを再起動し、反映させる。

sudo /etc/init.d/zabbix-server restart

これでシンプルチェックでPing監視が出来るはず。

 | 
このエントリーをはてなブックマークに追加

秘密鍵・公開鍵を使用したSSH接続

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

参考URL:http://www.server-memo.net/server-setting/ssh/ssh-key.html
詳しくは参考URLを参照してもらうとして、以下メモ。

秘密鍵と公開鍵を作成

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hogehoge/.ssh/id_rsa):
Created directory '/home/hogehoge/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hogehoge/.ssh/id_rsa.
Your public key has been saved in /home/hogehoge/.ssh/id_rsa.pub.
The key fingerprint is:
75:28:f4:77:3f:68:93:d2:c5:7d:2a:5c:96:c9:2f:17 hogehoge@TestServer

authorized_keysが無い場合

cd ~/.ssh
mv id_rsa.pub authorized_keys
chmod 600 authorized_keys

既にauthorized_keysがある場合

cat id_dsa.pub >> authorized_keys

WinSCP等でid_rsaをローカルに持ってきてPuTTYgenに喰わせる。

(略)

sshdの設定変更

sudo cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config_yyymmdd
sudo nano /etc/ssh/sshd_config
--- sshd_config_20110218        2011-02-17 23:07:29.804689290 +0900
+++ sshd_config 2011-02-18 00:34:08.837514406 +0900
@@ -23,12 +23,12 @@

 # Authentication:
 LoginGraceTime 120
-PermitRootLogin yes
+PermitRootLogin no
 StrictModes yes

 RSAAuthentication yes
 PubkeyAuthentication yes
-#AuthorizedKeysFile    %h/.ssh/authorized_keys
+AuthorizedKeysFile     %h/.ssh/authorized_keys

 # Don't read the user's ~/.rhosts and ~/.shosts files
 IgnoreRhosts yes
@@ -47,7 +47,7 @@
 ChallengeResponseAuthentication no

 # Change to no to disable tunnelled clear text passwords
-#PasswordAuthentication yes
+PasswordAuthentication no

 # Kerberos options
 #KerberosAuthentication no
sudo /etc/init.d/sshd restart
 | 
このエントリーをはてなブックマークに追加

WordPressの日本語ローカライズ

このエントリをはてなブックマークに追加このエントリをGoogle bookmarkに追加このエントリをdel.icio.usに追加このエントリをfacebookに追加

WordPressの日本語ローカライズはwp-content/languagesの下のja.mo、ja.poがそうだが
ググってみるとPoeditというのを使って編集してja.moを生成、というのが多かった。

Windows環境やレンタルサーバーの場合はPoeditでやらないといけないが
自宅鯖等のサーバーがLinuxで自由に触れる環境にあればコマンドでいける。

nano等でja.poを編集した後、

sudo msgfmt -c --statistics ja.po -o ja.mo

これでja.moを生成することができる。

 | 
このエントリーをはてなブックマークに追加

iphone6ケース ルイヴィトン iphone6ケース シャネル 手帳型 シャネル iphone6ケース タバコ ブランドスマホケース