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



2017年5月17日水曜日

メモ:haas/paas/saas





IaaS
PaaS
SaaS
アプリケーション


✔
ミドルウェア(DB等)

✔
✔
OS
✔
✔
✔
ハードウェア
✔
✔
✔
ネットワーク
✔
✔
✔

2017年4月30日日曜日

記号

;(セミコロン)
前のコマンドが終わり次第、次のコマンドが実行される。


&(アンパサンド)
;(セミコロン)は前のコマンドの完了を待っていたが、&は待たない。

&&
前のコマンドがうまく終了した(終了ステータスが0)なら、次のコマンドを実行。
そうでないなら次のコマンドは実行しない。

||
&&とは逆で前のコマンドに失敗(終了コード0以外)したら、次のコマンドを実行する。

2017年4月29日土曜日

保守用コマンド

以下のコマンドは、改めてメモしておく。

①w
②ps
③top
④free
⑤vmstat

◻️wコマンド
現在のサーバの状態を確認できる

[root@kube-admin ~]# w
 09:32:17 up 21 min,  1 user,  load average: 5.69, 4.64, 2.45
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.2.110    09:10    1.00s  2.94s  0.00s w


◻️psコマンド
プロセス一覧を表示

[root@kube-admin ~]# ps auxwwf 
========================================================================================
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         2  0.0  0.0      0     0 ?        S    09:10   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    09:10   0:01  \_ [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   09:10   0:00  \_ [kworker/0:0H]
                                    .
                                    .
                                    .                                
========================================================================================


◻️topコマンド 
実行中のプロセスを確認できる。
=======================================================================================
Processes: 343 total, 5 running, 1 stuck, 337 sleeping, 1357 threads                                                                                                                                                     09:34:35
Load Avg: 3.80, 3.43, 2.81  CPU usage: 20.96% user, 64.9% sys, 14.93% idle   SharedLibs: 366M resident, 66M data, 45M linkedit. MemRegions: 44695 total, 6943M resident, 210M private, 1061M shared.
PhysMem: 11G used (5145M wired), 13G unused. VM: 1707G vsize, 1297M framework vsize, 0(0) swapins, 0(0) swapouts. Networks: packets: 52615/43M in, 49709/7119K out. Disks: 607103/8819M read, 837808/4432M written.

PID   COMMAND      %CPU  TIME     #TH   #WQ  #PORT MEM    PURG   CMPR PGRP PPID STATE    BOOSTS         %CPU_ME %CPU_OTHRS UID  FAULTS   COW    MSGSENT  MSGRECV  SYSBSD    SYSMACH  CSW       PAGEIN IDLEW   POWER INSTRS
1135  kcm          0.0   00:00.01 3     3    21    2220K  0B     0B   1135 1    sleeping *0[1]          0.00000 0.00000    0    1942     143    87       33       548       198      147       0      0       0.0   0
1133  top          2.7   00:00.75 1/1   0    26    4212K  0B     0B   1133 690  running  *0[1]          0.00000 0.00000    0    5985+    110    222464+  111183+  19152+    142696+  431+      20     1       2.7   84571351
1132  diskmanageme 0.0   00:00.01 2     1    31    1248K  0B     0B   1132 1    sleeping *0[1]          0.00000 0.00000    0    1829     205    245      77       502       476      93        0      0       0.0   0
1128  backupd      0.0   00:00.03 2     1    44    1688K  0B     0B   1128 1    sleeping *0[1]          0.00000 0.00000    0    7681     204    353      137      1345      595      227       0      0       0.0   0
1126  ReportMemory 0.0   00:00.02 2     2    50    1200K  0B     0B   1126 1    sleeping  0[0]          0.00000 0.00000    269  1903     155    173      56       736       375      188       0      1       0.0   0
1125  com.apple.ph 0.0   00:00.11 4     4    60    6724K  0B     0B   1125 1    sleeping  0[0]          0.00000 0.00000    501  7968     606    434      136      2286      819      879       70     1       0.0   0
========================================================================================


◻️freeコマンド
メモリ使用率を確認できる。

[root@kube-admin ~]# free -m
===================================================================================================
              total        used        free      shared  buff/cache   available
Mem:           1838         554         375           8         909         945
Swap:             0           0           0
===================================================================================================

◻️vmstatコマンド
各種リソースの使用状況を最短で表示できる

[root@kube-admin ~]# vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
14  0      0 291680   2104 1035004    0    0  1097   678 3624 7227 31 27 39  4  0
 3  0      0 314180   2104 1034592    0    0    36  1183 6951 14111 28 24 45  3  0

 1  1      0 319732   2104 1035680    0    0     0  1069 6911 15572 34 29 36  1  0

Lambda + SSM Run Commandで、数十台のEC2のuserdata結果を一括確認する

コードを1枚貼って、テストイベントを実行するだけで、 全台の確認結果が返ってくる手順です。 [ゴール] Nameタグが web-* / api-* / batch-* のEC2すべてに確認コマンドを流し、 NGの台だけ を結果に表示します。確認対象のuserdata(Ubu...