忍者ブログ
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

splunkのようなログ解析ツールにgraylogというのがあるらしい。

それを動かすには2つの方法があり、1つは仮想アプライアンスで
出来合いのものを動かす方法。
もう一つは、rpm等を使ってサーバにインストールする方法だそうだ。

仮想アプライアンスは後で試すとして、とりあえず、CentOS7にインストールしてみる。

インストールする際には、JDKとElasticsearch、MongoDBのインストールが必要らしい。

1.JDKのインストール
まず、jdk-8u101-linux-x64.rpmのダウンロード

# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-x64.rpm

ダウンロードしたらインストールする
# rpm -ihv jdk-8u101-linux-x64.rpm

2.elasticsearchのインストール
次にElasticsearchをインストールする。

まず、リポジトリを追加
# rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
# cat << EOF > /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=https://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF

用意ができたらインストール
# yum install elasticsearch

# systemctl daemon-reload
# systemctl enable elasticsearch

確認してみる。
# systemctl list-unit-files | grep elastic
elasticsearch.service                         enabled

elasticsearchの設定変更

# cp /etc/elasticsearch/elasticsearch.yml{,.bk}
# cat <<EOF >> /etc/elasticsearch/elasticsearch.yml
cluster.name: graylog
script.inline: false
script.indexed: false
script.file: false
EOF

elasticsearch再起動
# service elasticsearch restart

ちゃんと起動しているかどうか確認
# curl -X GET http://localhost:9200
{
  "name" : "Fallen One",
  "cluster_name" : "graylog",
  "cluster_uuid" : "XWGjyKT6QaOSixynaJLG_A",
  "version" : {
    "number" : "2.4.4",
    "build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",
    "build_timestamp" : "2017-01-03T11:33:16Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"
}

# curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
{
  "cluster_name" : "graylog",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}
#

3.MongoDBのインストール

# cat <<"EOF" > /etc/yum.repos.d/mongodb-org-3.2.repo
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
EOF
# yum install mongodb-org

サービス起動
# systemctl start mongod
# systemctl enable mongod

4.graylogのインストール

リポジトリの取得
# wget https://packages.graylog2.org/repo/packages/graylog-2.0-repository_latest.rpm

リポジトリをインストール
# rpm -ivh graylog-2.0-repository_latest.rpm

# yum install graylog-server

# yum -y install epel-release
# yum -y install pwgen
# sed -e "/^password_secret/c password_secret = $(pwgen -N 1 -s 96)" \
    -e "/^root_password_sha2 /c root_password_sha2 = $(echo -n P@ssw0rd | sha256sum | awk '{print $1}')" \
    -e "/^#root_email/c root_email = root@localhost" \
    -e "/^root_timezone/c root_timezone = Japan" \
    -e "/^elasticsearch_discovery_zen_ping_unicast_hosts/c elasticsearch_discovery_zen_ping_unicast_hosts = $(hostname -I | xargs -n 1 | xargs -I{} echo {}:9300 | tr '\n' ',' | sed 's/,$//g')" \
    -e "/^elasticsearch_max_docs_per_index/c elasticsearch_max_docs_per_index = 20000000" \
    -e "/^elasticsearch_shards/c elasticsearch_shards = 1" \
    -e "/^elasticsearch_replicas/c elasticsearch_replicas = 0" \
    -e "/^rest_listen_uri/c rest_listen_uri = http://192.168.1.10:12900/" \
    -e "/#web_listen_uri/c web_listen_uri = http://192.168.1.10:9000/" \
    -i.bk /etc/graylog/server/server.conf

設定できたらサービスの再起動

# systemctl daemon-reload
# systemctl restart graylog-server
# systemctl enable graylog-server
# systemctl enable elasticsearch

firewallの穴あけをする
# firewall-cmd --permanent --zone=public --add-port=9000/tcp
# firewall-cmd --permanent --zone=public --add-port=12900/tcp
# firewall-cmd --permanent --zone=public --add-port=1514/tcp
# firewall-cmd --reload

ブラウザで、
http://192.168.1.10:9000 にアクセスする。
ID/パスワードは admin と P@ssw0rd ← 上で設定したパスワードにする

PR
rsyslog.confの設定を変更する

# vi /etc/rsyslog.conf

# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

# 送信元を限定設定の追加
# Sender
$AllowedSender UDP, 127.0.0.1, 192.168.1.0/24
$AllowedSender TCP, 127.0.0.1, 192.168.1.0/24

設定が終了したら、Firewalldの設定を変更と、rsyslogdの再起動
# firewall-cmd --permanent --add-port=514/tcp # firewall-cmd --permanent --add-port=514/udp # firewall-cmd --reload # systemctl restart rsyslog

syslogクライアント側の設定

# vi /etc/rsyslog.conf

# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$ActionQueueFileName fwdRule1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList   # run asynchronously
$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
*.* @192.168.1.10:514
*.* @@192.168.1.10:514

# systemctl restart rsyslog

syslogデータは /var/log/messages に保存される。
これだと、ログが混在してしまうので、IPアドレス毎に分離する。
以下の2行を追加。

# vi /etc/rsyslog.conf
$template ClinetMessage,"/var/log/rsyslog/%fromhost%/messages.log"
*.* -?ClinetMessage

さらに日ごとに分けるなら、/var/log/rsyslog以下を
/var/log/rsyslog/%fromhost%/%$year%%$month%%$day%_messages.log
とする。


wgetをインストールする

# yum install wget

fluentdからRedhat7用のRPMをダウンロードする
# wget http://packages.treasuredata.com.s3.amazonaws.com/2/redhat/7/x86_64/td-agent-2.3.4-0.el7.x86_64.rpm

依存性を保つため、redhat-lsb-coreをインストールする
# yum install redhat-lsb-core

ダウンロードしたtd-agentをインストールする
# rpm -ivh td-agent-2.3.4-0.el7.x86_64.rpm

バージョンを確認する
# td-agent --version
td-agent 0.12.31
IPアドレスを固定する

# less /etc/sysconfig/network-scripts/ifcfg-enp0s3

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=91c800a4-5144-41da-a10c-53c555035f9b
DEVICE=enp0s3
ONBOOT=yes
IPADDR0=192.168.1.10
PREFIX=24
GATEWAY0=192.168.1.1
家ネットワークを大きく見直した。
コンセプトは以下のとおり
  1. ブロードバンドルータ-DMZ-FW-プライベートNW という構成に変更
  2. DMZ内にサーバを設置
  3. syslogを一か所に集めるため、syslogサーバを立てる
  4. syslog管理をするため何か(splunkまたはkibana)を設定する
  5. Webサーバで公開する内容は、音データ、blogデータ、アクセスログデータ

ここまでやったこと
  1. 家のネットワーク構成修正(済)
  2. サーバ系はDMZに設置(済)
  3. CentOS6を新規仮想サーバとして作成
  4. selinuxの設定をdisableに設定
  5. iptables で、sshとsyslog(udp,tcp)を許可
  6. syslogサーバを設定
これからやること
  1. Webサーバの再構築
  2. blogサーバ構築
  3. 音楽データ配信用設定
  4. Webalizerの設定
  5. kibanaを試す
悩みどころ
  1. CentOS6のデータ領域が小さい→大きくするか?新規に作り直すか?
  2. blogサーバはwiki?wordpress?tdiary?
  3. データ配信用に特別な設定をするか?今のようにWebサーバの機能で行くか?
  4. splunkは再度インストールできないものか?
  5. メールサーバはどうするか?
  6. DNSサーバはどうするか?
カレンダー
04 2024/05 06
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
ブログ内検索
 次のページ

material:web*citron  template:ゆずろぐ

忍者ブログ [PR]