nemunemu_zzzの日記

備忘録的な何かになればいいな

サーバをブリッジとして扱う

サーバ3台を2台ホスト, 1台ブリッジとして構成する

ブリッジの設定についてメモしておく

 

環境

  • CentOS7

 

参考サイト

http://kashigeru.hatenablog.com/entry/2014/02/12/224728

http://d-net.robata.org/inetbuild-bridge.html

 

まず, bridge-utilsをインストー

# yum install bridge-utils

インストールするとbrctlコマンドが使える

ブリッジの設定を行っていく

ブリッジを追加

# brctl addbr br0

 

Interfaceを設定する

# brctl addif br0 enp3s0
# brctl addif br0 enp5s0

 

ブリッジにIPを振る

# ip addr add 10.0.0.2/24 dev br0

 

Interfaceも設定

ip addr add 0.0.0.0/24 dev enp3s0
ip addr add 0.0.0.0/24 dev enp5s0

 

ブリッジを有効にする

ip link set br0 up

 

これでホスト間での同じネットワーク帯での通信が行えた

elasticsearchのtimestampとkibanaでのtimestampがずれてしまう

filebeatのmoduleを使っていて, Kibanaで見てみると未来のデータありました(笑)

サーバーのlogは JST,
Elasticsearchは UTC,
Kibanaは JST
となる

未来のデータを見てみると, どれも/var/log/messages, /var/log/secure だけだった.

よくよく見ると, サーバーのlogの時刻をUTCに変換せずにElasticsearchに入り, Kibanaに+09:00されたデータが入っているようだ.

syslogのmoduleがおかしそうだな

調べて見ると, moduleはIngest Nodeというものを使っていて, 各moduleの下のingest/ 以下の.jsonに設定があるようだ

参考にしたサイト

https://discuss.elastic.co/t/filebeat-assumes-utc/80896

上記のサイト参考に /usr/share/filebeat/module/system/syslog/ingest/pipeline.json を書き換えてみる

# vi /usr/share/filebeat/module/system/syslog/ingest/pipeline.json

変更前

   
    "date": {
        "field": "system.syslog.timestamp",
        "target_field": "@timestamp",
        "formats": [
                        "MMM  d HH:mm:ss",
                        "MMM dd HH:mm:ss"
        ],
        "ignore_failure": true
    }

変更後

   
    "date": {
        "field": "system.syslog.timestamp",
        "target_field": "@timestamp",
        "timezone": "Asia/Tokyo",
        "formats": [
                        "MMM  d HH:mm:ss",
                        "MMM dd HH:mm:ss"
        ],
        "ignore_failure": true
    }

ちなみに"timezone": "JST"だとエラーが出てダメだった...orz

上記のように編集したらElasticsearchの古いpipeline情報を削除します

# curl -XDELETE http://<yourIP>:9200/_ingest/pipeline/filebeat-5.5.0-system-syslog-pipeline

次にfilebeatを再起動してお終い!

# systemctl restart filebeat

一度elasticsearch側に登録さえしてしまえば, 他のサーバのfilebeatは再起動するだけでok

僕は,サーバごとでfilebeatのバージョンが違って少し詰まってしまいました(笑)

起動しているかも確認

# systemctl status filebeat

pipelineがちゃんと設定されてたかも見てみる

# curl -XGET http://<yourIP>:9200/_ingest/pipeline/filebeat-5.5.0-system-syslog-pipeline
    {"filebeat-5.5.0-system-syslog-pipeline":{"description":"Pipeline for parsing Syslog messages.","on_failure":[{"set":{"field":"error","value":"{{ _ingest.on_failure_message }}"}}],"processors":[{"grok":{"field":"message","ignore_missing":true,"pattern_definitions":{"GREEDYMULTILINE":"(.|\n)*"},"patterns":["%{SYSLOGTIMESTAMP:system.syslog.timestamp} %{SYSLOGHOST:system.syslog.hostname} %{DATA:system.syslog.program}(?:\\[%{POSINT:system.syslog.pid}\\])?: %{GREEDYMULTILINE:system.syslog.message}","%{SYSLOGTIMESTAMP:system.syslog.timestamp} %{GREEDYMULTILINE:system.syslog.message}"]}},{"remove":{"field":"message"}},{"date":{"field":"system.syslog.timestamp","formats":["MMM  d HH:mm:ss","MMM dd HH:mm:ss"],"ignore_failure":true,"target_field":"@timestamp","timezone":"Asia/Tokyo"}}]}}

設定が反映されていることがわかる

kibanaからもちゃんとできていることが確認できた

Elastic Stack導入してみた

備忘録的に残します.

 

今回ログサーバーを構築しようと思い, Elasic stack(beats + Logstash + Elasticsearch + Kibana)を使ってみようと思いました.

まだ細かい設定とかは全然してないけど, installと一通りの流れだけまとめときます.

まぁ,公式のドキュメント通りでした(笑)

 

環境

  • Kibana 5.4.1
  • Elasticsearch 5.4.1
  • Logstash 5.4.1
  • Filebeat 5.4.1
  • CentOS7系

 

私はrpmで導入したため, 下記のドキュメントを参考にしました

Kibana

elasticsearch

logstash

filebeat

 

基本的な流れとしては

 

鍵をもってきて

# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

 

レポジトリを作って

# vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

 

インストールするだけ

yum install elasticsearch

 

インストールが終わった自動起動の設定やサービスの起動

# yum enable elasticsearch
# yum start elasticsearch

 

elasticserachのstartでハマッてしまってつらかった...

statusを見るとメモリーが足りないというエラーが発生してました

私はelasticsearch4系のときはすんなり起動してくれていたからうまくいくはずだ...!ってずっとハマってしまいました(笑)

元はメモリは1Gだったのですが, 4Gに上げたら起動してくれました

このサイトを参考にしました. デフォルト2Gもあればそりゃむりよね(笑)

http://www.karakaram.com/elasticsearch-memory-usage-reduce

 

 

設定ファイル関連

 

elasticsearch.yml

# vi /etc/elasticsearch/elasticsearch.yml
    #network.host: 192.168.0.1
    network.host: 
        
    #http.port: 9200
    http.port: 9200

 

kibana.yml

# vi /etc/kibana/kibana.yml
    #server.host: "localhost"
    server.host: ""

filebeat.yml

# vi /etc/filebeat/filebeat.yml
    output.elasticsearch:
  # Array of hosts to connect to.
  hosts: [":9200"]

 

portの開放

    
    firewall-cmd --add-port=5601/tcp --zone=public --permanent
    firewall-cmd --add-port=9200/tcp --zone=public --permanent
    firewall-cmd --reload

 

これでkibana上での可視化までの流れは見えたので, 転送するファイルや, indexの設定やらの細かいのはまた今度!

beatsが色々できるっぽいのでzabbixとの比較だったり色々試していきたいなぁ

KVMの拡張!

何かとKVMの拡張をすることがあるのでメモ代わりに...

 

環境は CentOS7

 

1. 拡張前のディスクパーティションを確認

まず, fdiskでパーティションの確認をします.

※ sudoに上がらないと何も表示されない

rootで作業するからsudoは省いてます.

# fdisk -l

 

 出力結果は他にも長々とでるけど今回みたいのは上の方にあるここ

/dev/vda の容量が10.7GBなのが確認できると思います

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008ce71

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    20971519     9972736   8e  Linux LVM

 

2. 仮想領域の拡張

拡張する出来るだけのスペースを空ける

VMを一度止める

# virsh shutdown <VM名>

 

VMの領域を拡張する

ここでは50G容量をプラスしている

# qemu-img resize <VM名> +50G
結果

 

Image resized.

とでればOK

 

VMを起動する

# virsh start <VM名>

VMを起動させながらでも拡張することは出来るが再起動をしないと反映されない

 

 

3.パーティションの設定

では、ちゃんと領域が増えているかを確認してみましょう!

# fdisk -l

拡張前と違い, /dev/vdaの領域が増えていることが確認できましたね

Disk /dev/vda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008ce71

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    20971519     9972736   8e  Linux LVM

 

ファイルシステムの容量を確認するコマンド「df」を使ってみます

# df

dev/mapper/centos-root が拡張されてないことがわかります.
つまり, ファイルシステムには反映されていません.


Filesystem              1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root   8869888 3891612   4978276  44% /
devtmpfs                   498388       0    498388   0% /dev
tmpfs                      508456       0    508456   0% /dev/shm
tmpfs                      508456    6808    501648   2% /run
tmpfs                      508456       0    508456   0% /sys/fs/cgroup
/dev/vda1                  508588  166788    341800  33% /boot
tmpfs                      101692       0    101692   0% /run/user/1000

では, 実際にパーティションテーブルの設定を行ってきます.

サイトによってvdaだったり, sdaだったりするけど仮想なのか物理なのか違いでしかないらしい


# fdisk /dev/vda

すると

Command (m for help):

このように表示されると思います. まずはpを押してみてください.

Command (m for help): p
Disk /dev/vda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008ce71

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    20971519     9972736   8e  Linux LVM

先程までやってたfdisk -lと同じ結果が出てきますね.

pでパーティションの状態がわかります.

次に

 

Command (m for help): n

パーティションを新規作成します.



Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):  
Using default response p
Partition number (3,4, default 3):
First sector (20971520-125829119, default 20971520):
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-125829119, default 125829119):
Using default value 125829119
Partition 3 of type Linux and of size 50 GiB is set

拡張されたことがわかりますね.
基本的にdefaultの設定があるのでenterを押すだけでいいのですが, それでも確認はしてください.特に開始セクターがちゃんと前のやつと続いているかなど.
ではもう一度パーティションの状況を確認してみましょう.

Command (m for help): p


Disk /dev/vda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008ce71

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    20971519     9972736   8e  Linux LVM
/dev/vda3        20971520   125829119    52428800   83  Linux

/dev/vda3が追加されているのがわかりますね.
そして/dev/vda3のパーティションタイプをLinux LVMに変更します


Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

確認してもちゃんと変更されていますね
Command (m for help): p

Disk /dev/vda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008ce71

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048    20971519     9972736   8e  Linux LVM
/dev/vda3        20971520   125829119    52428800   8e  Linux LVM

最後はwで設定を反映させて終わります

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

 

ここで一度, 再起動をしておきましょう.

# reboot

4. 物理ボリュームを作成, ボリュームグループを拡大して, 論理ボリュームを拡張する

さっき作った/dev/vda3を物理ボリュームに追加します

# pvcreate /dev/vda3

Physical volume "/dev/vda3" successfully created

と出ればOK

 

物理ボリュームに/dev/vda3が追加されているかを確認する

# pvdisplay

 

ちゃんと/dev/vda3が50Gで入っていることが確認できますね

  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               centos
  PV Size               9.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              2434
  Free PE               7
  Allocated PE          2427
  PV UUID               ZDBL6e-IAxE-rI3V-E5Tp-fiAC-0Zw2-RYgKYV
   
  "/dev/vda3" is a new physical volume of "50.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vda3
  VG Name               
  PV Size               50.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               NYol9g-mc0r-Vodf-G5k4-XEZd-2Wm0-06xccb
   

 

次にボリュームグループの確認をする.

# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.51 GiB
  PE Size               4.00 MiB
  Total PE              2434
  Alloc PE / Size       2427 / 9.48 GiB
  Free  PE / Size       7 / 28.00 MiB
  VG UUID               ETrNs9-H1yq-Ccvp-YBnV-F5eg-YmbU-RYY5ew

 

次に、ボリュームグループに/dev/vda3を追加して拡張します

vgextend centos /dev/vda3

Volume group "centos" successfully extended

 

が出ればOK

 

論理ボリューム名を確認する.

※今回は/dev/centos/rootだけが必要なので他は省略している

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                TdCtD6-vJuj-8WMS-ahZU-XtOV-dBqJ-4Hluqe
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-09-20 19:54:35 +0900
  LV Status              available
  # open                 1
  LV Size                8.47 GiB
  Current LE             2168
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

 

すでにある論理ボリュームに追加した50G分を当てていきます

# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 8.47 GiB (2168 extents) to 58.49 GiB (14974 extents). Logical volume root successfully resized.

がでればOK

 

最後にファイルシステムの拡張を行います

ここで少しやっかいなのが, centOS7は今までのresize2fsではなくxfs_growfsに変わったこと

わかっていればそんな詰まることではないのだけれど,僕はここで悩まされました(笑)

# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=555008 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=2220032, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2220032 to 15333376

がでればOK


あとはdfで確認すれば

# df
Filesystem              1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root  61323264 3893524  57429740   7% /
devtmpfs                   498388       0    498388   0% /dev
tmpfs                      508456       0    508456   0% /dev/shm
tmpfs                      508456    6812    501644   2% /run
tmpfs                      508456       0    508456   0% /sys/fs/cgroup
/dev/vda1                  508588  166788    341800  33% /boot
tmpfs                      101692       0    101692   0% /run/user/1000

拡張されていることがわかりますね!