S小魚仔S 網誌搜尋

2017年10月27日 星期五

S小魚仔S Centos 7 搭建 ELK (ElasticSearch) 叢集 (Cluster )

Elasticsearch 叢集(Cluster) 中的三種角色

Master Node: 幾點主要用於元數據(metadata)的處理,比如索引的新增、刪除、分片分配等。

Data Node: 節點上保存了數據分片。它負責數據相關操作,比如分片的 CRUD,以及搜索和整合操作。這些操作都比較消耗 CPU、內存和 I/O 資源。

Client Node: 節點起到路由請求的作用,實際上可以看做負載均衡器。

搭建版本「ElasticSearch - 5.6.3」首先我們先看一下架構圖


搭建「ElasticSearch」Cluster 請先滿足下列條件
PS. 記憶體不能小於「4G

#==關閉「Selinux 」======

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

#====設定連線「最大值」默認「1024」====

echo "ulimit -SHn 65536" >> /etc/profile
source /etc/profile

#======開啟「最大線程」(262144)======

vi /etc/sysctl.conf

vm.max_map_count = 262144
vm.swappiness = 1

#重啟生效
sysctl -p

#==Elasticsearch - Firewall========

#ElasticSearch Mapping API  9200/TCP
sudo firewall-cmd --add-port=9200/tcp --permanent 

#ElasticSearch Unicast  9300/TCP
sudo firewall-cmd --add-port=9300/tcp --permanent 

#重新啟動「防火牆
sudo firewall-cmd --reload

#=====Elasticsearch.yml 設定檔(Config)========

#=====Master 配置=======

# 叢集「名稱
cluster.name: es_cluster
 # Hostname(主機名)
node.name: Elasticsearch_M
# 允許連線 IP ,也可以使用「0.0.0.0
network.host: 192.168.8.28
 # 開啟「TCP-9200」協議
http.port: 9200

#如果「Elasticsearch」節點(Node)只有「2台」才需要配置,默認都是「True」。
# master =「主節點」,data =「存放資料
node.master: true
node.data: true

 #設定「自動發現節點主機」Unicast
discovery.zen.ping.unicast.hosts: ["192.168.8.28","192.168.8.29"] 

#防止「Node」節點故障,節點(Node)「2台」設定數值「1」。
#防止「Node」節點故障,節點(Node)「3台」設定數值「2」。
discovery.zen.minimum_master_nodes: 1

#支援「跨網段」連線 並 獲取「數據」
http.cors.enabled: true
http.cors.allow-origin: "*"




#=====節點 Node 配置 (以此類推) =======

配置完成以後透過下面指令確認「狀態

#==檢查「端口」===
netstat -ltunp | grep -e "9200" -e "9300"


#==查詢「群集」狀態=======

查询集群状态
curl -XGET 'http://192.168.8.28:9200/_cat/nodes?v'

查询集群中的「Master」
curl -XGET 'http://192.168.8.28:9200/_cat/master?v'

查询集群中的「健康狀態
curl -XGET 'http://192.168.8.28:9200/_cat/health?v'

到這邊為止「ElasticSearch」Cluster 基本搭建完成,後續可以依照需求搭建「Client Node - Load Blance」做「負載均衡

參考資料
www.cnblogs.com」-「ELK + KafKa 开发集群环境搭建
www.blog-wuchen.cn」-「ES集群安装

2017年10月26日 星期四

S小魚仔S Influxdb 搭配 Grafana 完成簡易 Web UI Admin 管理

首先「本篇」不會講解「Influxdb」和「Grafana」搭建,這是最基本的知識基礎,在一個巧合之下發現「Grafana Influx Admin」Panel,開發公司為「Natel Energy」。

Influxdb」和「Grafana」需要搭建在「相同服務器」因為使用「localhost:8088」連線。

1. 安裝「nodes」相關「套件

yum install nodejs -y
yum install openssl -y
npm install -g yarn
npm install -g grunt-cli

2.安裝「Grafana - influx admin」 Plugins

grafana-cli plugins install natel-influx-admin-panel

sudo systemctl restart grafana-server


3. 設定「Data Sources


點選「+Add data Source

1. 輸入「名稱
2. 選擇「InfluxDB
3. 輸入「http://localhost:8086」(Default)
4. 選擇「Proxy
5. 輸入 InfluxDB「資料庫
6. 輸入 InfluxDB「帳戶」、「密碼

點選「Save & Test

成功連結「InfluxDB


4. 配置「DashBoard」套用「Influx Admin」插件

點選「Home

點選「+ New DashBoard

選擇「Influx Admin」插件

編輯「Influx Admin」插件

移動 畫面 最下面
1. 點選「Options
2. 選擇「Query Windows

點選「紅色圖形」就會有「UI」功能

點選「Show Databases」就可以查詢「資料庫

2017年10月11日 星期三

S小魚仔S Centos 7 安裝 Ntopng 進行 網路監控

ntopng」是原始「ntop」的下一代版本,監視網絡使用情況的網絡流量探測器。「ntopng」基於「libpcap」,它以便攜式方式編寫,以便在每個 Unix 平台,MacOSX 和 Windows 上虛擬運行,支持 sFlowNetFlow (v5/v9) 和 IPFIX,此版本「ntopng-3.1.171009」同時結合「Grafana - Ntopng Datasource」。

==修改「電腦」名稱====

hostnamectl set-hostname Ntopng
                                       
==Grafana- Firewall========

#Ntopng-Http (Server) 3000/TCP
sudo firewall-cmd --add-port=3000/tcp --permanent 

#重新啟動「防火牆
sudo firewall-cmd --reload

==關閉「selinux 」======

#關閉「Selinux」為「disabled」才不會阻擋「服務連線」服務
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

#重新啟動
reboot -h now

==== Install Ntopng 3.1 版本(Yum 源) ============

#切換「Yum」源,根目錄
cd /etc/yum.repos.d/

#「Wget」下載「ntop.repo」修改檔名「ntop.repo
wget http://packages.ntop.org/centos/ntop.repo -O ntop.repo

#「Rpm」下載「epel-release-latest-7.noarch.rpm」並「安裝
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

#清理「暫存
yum clean all

#「更新」所有「Yum」源
yum update -y

======安裝「Ntopn」===========

#安裝「Pfring」、「n2disk」、「nprobe」、「ntopng」、「ntopng-data」、「cento」、「tcpdump」。
yum install pfring n2disk nprobe ntopng ntopng-data cento tcpdump -y

#安裝「pfring」驅動程式
yum install pfring-drivers-zc-dkms -y

#開啟「redis」服務
sudo systemctl start redis.service
#重開機「redis」自動開啟「服務
sudo systemctl enable redis.service

#開啟「ntopng」服務,啟動「會有錯誤」不用擔心,因為需要「重啟」。
sudo systemctl start ntopng.service

輸入「journalctl -xe」會出現「Failed to start ...」無須理會,繼續往下

#重開機「ntopng」自動開啟「服務
sudo systemctl enable ntopng.service

#重新啟動
reboot -h now

#檢查「ntopng」狀態
sudo systemctl status ntopng.service

#檢查「redis」狀態
systemctl status redis.service

#因「ntopn」是「商業軟件」需要修改「License」授權 為「--community」(通用版) Version。

#修改「ntopng.conf」編輯檔
sudo vi /etc/ntopng/ntopng.conf

;內容如下
-G=/var/tmp/ntopng.pid\
--community

#重新啟動「ntopng.service
sudo systemctl restart ntopng.service

#檢查「ntopng」狀態
sudo systemctl status ntopng.service

輸入「Http://IP:3000」即可正常「使用
PS.預設「帳號」和「密碼」( admin / admin )

參考資料
肥佳洛的學習網」-「建立 Ntopng 來作為收集與分析 SFlow 訊息
亞索數位筆記」-「在 CentOS 7.x 上安裝 ntopng
「Web Site」-「http://www.ntop.org/