2017年10月28日土曜日

lsync+rsyncの手順









■Server間(A <->B )でファイル同期ができる方法を記載してみる。

OS:CentOS 7.x
Server(A) :192.168.1.130
Server(B) :192.168.1.131

■最低限、以下は、停止の状態にする。
selinux off
systemctl stop firewalld


1)以下、インストールを行う
# yum -y install epel-release
# yum --enablerepo=epel -y install lsyncd
# yum -y install rsync
# yum -y install xinetd


2)lsyncdの設定をする
ファイル交換相手のIPアドレスを記載する。


# vi /etc/lsyncd.conf
---------192.168.1.130--------------------------------------
settings{
logfile = "/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.stat",
statusInterval = 1,
}


sync{
default.rsync,
source="/var/www/html",
target="root@192.168.1.131:/var/www/html",
rsync = {
    archive = true,
    links = true,
    update = true,
    verbose = false
}
}
-------------------------------------------------------------------------


# vi /etc/lsyncd.conf
ファイル交換相手のIPアドレスを記載する。
---------192.168.1.131--------------------------------------------
settings{
logfile = "/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.stat",
statusInterval = 1,
}


sync{
default.rsync,
source="/var/www/html",
target="root@192.168.1.130:/var/www/html",
rsync = {
    archive = true,
    links = true,
    update = true,
    verbose = false
}
}
-------------------------------------------------------------------------------


3)xinetの設定をする
# vi /etc/xinetd.conf
------192.168.1.130/192.168.1.131-----------
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
---------------------------------------------------------


4)rsyncの設定を行う
# vi /etc/rsyncd.conf
ファイル交換相手のIPアドレスを記載する。
-----------192.168.1.130-----------------------
uid = root
gid = root
read only = no
log file = /var/log/rsyncd.log
pid file = /var/log/rsyncd.pid
port = 873
[sync]
path = /var/www/html
hosts allow = localhost 192.168.1.131
read only = false
----------------------------------------------------



# vi /etc/rsyncd.conf
ファイル交換相手のIPアドレスを記載する。
-----------192.168.1.131---------------------
uid = root
gid = root
read only = no
log file = /var/log/rsyncd.log
pid file = /var/log/rsyncd.pid
port = 874
[sync]
path = /var/www/html
hosts allow = localhost 192.168.1.130
read only = false
-----------------------------------------------------


※交互に、lsyncを使って同期をとりたい場合は
port = 873以外にすること!


5)サービスの起動を行う


# systemctl start lsyncd
# systemctl enable lsyncd
# systemctl start rsyncd
# systemctl enable rsyncd
# systemctl start xinetd
# systemctl enable xinetd

MySQL routerのヘルスチェックファイル作成方法

以下の方法で、MySQL routerプロセスのヘルスチェックをしてみる。


1)ヘルスチェックファイルを作成する

------------mysqlrouter_check.sh---------
#!/usr/bin/sh
while true
do
#ここではftpdのプロセス監視
check=`ps -ef | grep "mysqlrouter" | \
grep -v grep | wc -l`
if [ $check = 1 ]; then
echo "プロセスは生きています"

else

echo "プロセスは死んでいます"
mysqlrouter &

fi
sleep 3
done
--------------———————————————

2)cront登録する
crontab -e


3)以下、追加する。

-------------------------------------------------------------------------------------------------------------
* * * * * for i in `seq 0 10 59`;do (sleep ${i} ; /root/mysqlrouter_check.sh) & done;
------------------------------------------------------------------------------------------------------------


cronで、数秒間隔でプロセスを監視していて
ダウンしたら起動するように設計した。

mysqlrouterのサービスの起動方法

# systemctl start mysqlrouter

# systemctl enable mysqlrouter

mysql routerサービスの不具合について


以下の手順で、サービスを起動してもMysql routerのバグで
サービスが安定した起動ができないようだ。

[root@mysql1 ~]# systemctl start mysqlrouter
[root@mysql1 ~]# systemctl enable mysqlrouter



実際に、再起動後に、以下のコマンドを投入すると
mysql routerのプロセスが起動していないことが分かる

# ps -ax | grep mysql 


そこで、以下のように所有権を変更すると、解決するようだ。

 [root@mysql1 ~]# chown mysqlrouter. /var/lib/mysqlrouter/

postfix3.2.2の導入方法

1)導入前に以下の作業を行う。
# systemctl stop postfix
# yum remove postfix


2)以下の手順で、ソースコードからコンパイルしてpostfixの導入を行う。

①以下のサイトからソースコードをダウンロードする。
wget ftp://ftp.riken.jp/net/postfix/postfix-release/official/postfix-3.2.2.tar.gz


②解凍を行う
tar zxfv postfix-3.2.2.tar.gz


③ディレクトリに移動する。
cd postfix-3.2.2


④デベロッパーツールを導入する。
yum install httpd-devel


⑤コンパイルとインストールを行う。
make
make install


⑥以下、聞かれる質問内容についてEnterKeyを押す。
------------------------------------------------------------------------------------------------------------------------
install_root: [/]   EnterKeyを押す
tempdir: [/root/postfix-3.2.2]   EnterKeyを押す 
config_directory: [/etc/postfix]  EnterKeyを押す
command_directory: [/usr/sbin]     EnterKeyを押す
daemon_directory: [/usr/libexec/postfix]  EnterKeyを押す
data_directory: [/var/lib/postfix]  EnterKeyを押す
html_directory: [no]       EnterKeyを押す
mail_owner: [postfix]      EnterKeyを押す
mailq_path: [/usr/bin/mailq.postfix]    EnterKeyを押す
manpage_directory: [/usr/share/man]    EnterKeyを押す
newaliases_path: [/usr/bin/newaliases.postfix]  EnterKeyを押す
queue_directory: [/var/spool/postfix]       EnterKeyを押す
readme_directory: [/usr/share/doc/postfix-2.10.1/README_FILES]  EnterKeyを押す
sendmail_path: [/usr/sbin/sendmail.postfix]            EnterKeyを押す
setgid_group: [postdrop]     EnterKeyを押す
shlib_directory: [no]       EnterKeyを押す
meta_directory: [/etc/postfix]   EnterKeyを押す

--------------------------------------------------------------------------------------------------------------------------


3)以下、サービスの登録を行う

# vi /etc/systemd/system/postfix.service
---------postfix.service-----------------------------------------
[Unit]
Description=Postfix Mail Transport Agent
After=syslog.target network.target
Conflicts=sendmail.service exim.service

[Service]
Type=forking
PIDFile=/var/spool/postfix/pid/master.pid
EnvironmentFile=-/etc/sysconfig/network
ExecStartPre=-/usr/libexec/postfix/aliasesdb
ExecStartPre=-/usr/libexec/postfix/chroot-update
ExecStart=/usr/sbin/postfix start
#ExecReload=/usr/sbin/postfix reload
ExecStop=/usr/sbin/postfix stop

[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------------


4)以下、aliasesdbを作成する

# vi /usr/libexec/postfix/aliasesdb
------------------- aliasesdb ------------------------------------------------------------
#!/bin/bash

ALIASESDB_STAMP=/var/lib/misc/postfix.aliasesdb-stamp

make_aliasesdb() {
    if [ "$(/usr/sbin/postconf -h alias_database)" == "hash:/etc/aliases" ]
    then
            # /etc/aliases.db may be used by other MTA, make sure nothing
            # has touched it since our last newaliases call
            [ /etc/aliases -nt /etc/aliases.db ] ||
                    [ "$ALIASESDB_STAMP" -nt /etc/aliases.db ] ||
                    [ "$ALIASESDB_STAMP" -ot /etc/aliases.db ] || return 0
            /usr/bin/newaliases
            touch -r /etc/aliases.db "$ALIASESDB_STAMP"
    else
            /usr/bin/newaliases
    fi
}

make_aliasesdb
-------------------------------------------------------------------------------------------------


5)chroot-updateを作成します。

# vi /usr/libexec/postfix/chroot-update
-----------------------chroot-update---------------------------------------------------------
#!/bin/bash

[ -x /etc/postfix/chroot-update ] && exec /etc/postfix/chroot-update
exit 0
---------------------------------------------------------------------------------------------------

6)上記で作成したファイルの権限の変更を行う。

chmod 0750 /usr/libexec/postfix/chroot-update
# chmod 0750 /usr/libexec/postfix/aliasesdb

viエディター(文字:置換方法)

ファイル全体で、置換機能を使いたい場合


以下の方法で解決する。
:%s/置換対象文字列/置換後文字列/g
例):%s/ccc/eee/g



ハッキングツール一覧(ホワイトハッカー編)

  1. ポート・ネットワークスキャン系 Nmap :標準。ポート・サービス検出・OS推定まで。 # 単純なポートスキャン nmap 192.168.1.10 # 開いているポートとサービスを詳細にスキャン nmap -sV -O 192.168.1.10 # 複数ホストをスキャ...