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/

2017年9月25日 星期一

S小魚仔S Influxdb 設定 Https 證書加密

1. 下載「Win32OpenSSL」產生「Private Key」(私鑰) 和「Ceritficate」(證書) 接著合併「Private Key」與「Ceritficate」。



切換「Bin」目錄夾
CD C:\OpenSSL-Win64\bin


使用「openssl.exe」產生「Private Key
openssl genrsa -out D:\influxdb_key.pem 2048

使用「openssl.exe」導入「Private Key」 產生「csr
openssl req -new -key D:\influxdb_key.pem -out D:\influxdb_cert.csr



合併「Private Key 與「Ceritficate
openssl x509 -req -days 3650 -in D:\influxdb_cert.csr -signkey D:\influxdb_key.pem -out D:\influxdb_cert_key.pem




2. 編輯「influxdb.conf」配置「加密

編輯「vi /etc/influxdb/influxdb.conf

啟用「加密
https-enabled = true

載入「influxdb_cert_key.pem」( 合併 Ceritficate 與 Private Key )
https-certificate = "/opt/influxdb_cert_key.pem"

載入「Private Key
https-private-key = "/opt/influxdb_key.pem"




#重新啟動「InfluxDB
systemctl restart influxd

#檢查「InfluxDB」狀態
systemctl status influxd


3. 設定「Telegraf (客戶端)」使用「Https」加密傳輸

編輯「vi /etc/telegraf/telegraf.conf

urls = ["https://192.168.8.26:8086"]

insecure_skip_verify = true

#重啟「telegraf」客戶端
systemctl restart telegraf

#檢查「telegraf」狀態
systemctl status telegraf


參考資料
RiCo技術農場」-「Enable https for influxdb
RiCo技術農場」-「How to set up HTTPS with Telegraf

2017年9月19日 星期二

S小魚仔S PowerShell 執行 Exchange 2013 EMS Script 腳本

1. 設定「PowerShell」賦予「執行」權限


檢查「Get-ExecutionPolicy」權限,若如下圖「所示」,接著往下繼續..
Get-ExecutionPolicy –List | FL

修改為「RemoteSigned」執行權限
Set-ExecutionPolicy "RemoteSigned"

2. 建立「Exchange - PowerShell」( xxx.ps1)

#==載入「Exchange-2013」模組==
PS. 這裡「紅色」部份「需要」輸入 Exchange Server「FQDN
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://mail.jumi.com/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

#===設定「日期」變數=====

$CurrentDate = Get-Date
#===設定「日期」轉「字串」=====
$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hh-mm-ss')

#==輸入「Exchange Script」指令==
PS. 指令不多做「解釋」有需要「自行學習
Get-MessageTrackingLog -Server mail -ResultSize Unlimited -Start "9/18/2017 00:00 AM" -End "9/19/2017 11:00 PM" -Sender "xxxxx@gmail.com" | Select-Object timestamp,source,eventid,sender,recipients,messagesubject,recipientstatus,originalclientip,clientip,serverip | sort-object -Property timestamp | Out-File C:\Ex_Log\exchange_$CurrentDate.log

執行「PowerShell」腳本


成功輸出「Exchange」Log

3. 設定 PowerShell 「排程」(schedule) 執行

選擇「創建基本任務

輸入「任務名稱

選擇「排程」每天何時執行

選擇「開始」時間

選擇「啟動程序

1.輸入「powershell
2. 添加參數 輸入「-file "C:\Users\Mail\Exchange.ps1"
PS. PowerShell 檔案,不要用中文命名

這裡非常重要
1. 選擇「不管用戶是否登入都要運行
2. 使用「最高權限運行
3. 配置「Windows Server 2012 R2

1.選點「觸發器」頁面
2. 點選「觸發器」排程,可以修改「執行時間


最後輸入有執行權限「帳號和「密碼」即可

參考資料

2017年9月14日 星期四

S小魚仔S Centos 7 安裝 Influxdb

最近剛好在測試日誌服務器,搭建了「Influxdb」,InfluxDB是一個由 InfluxData 開發的開源時序型資料庫,它由 Go語言寫成,著力於高性能地查詢與存儲時序型數據。InfluxDB被廣泛應用於存儲系統的監控數據,IoT行業的實時數據等場景。


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

hostnamectl set-hostname Influxdb

==關閉「selinux 」======
開機 不「啟用」selinux 才不會阻擋「服務連線」服務
vi /etc/sysconfig/selinux
SELINUX=disabled
reboot

==Influxdb- Firewall========

Influxdb Web 8083/TCP

#加入「防火牆」規則
sudo firewall-cmd --add-port=8083/tcp --permanent

Influxdb API 8086/TCP

#加入「防火牆」規則
sudo firewall-cmd --add-port=8086/tcp --permanent 

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

#檢查「Firewall」設定「規則」
firewall-cmd --list-all --permanent


======InfluxDB v1.3.5 (Server)==========

#更新「yum」資料庫來源
yum install epel-release -y

#加入「influxdb」yum 資料庫來源
vi /etc/yum.repos.d/influxdb.repo

[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

#安裝「influxdb
sudo yum install influxdb -y

#啟動「InfluxDB
systemctl start influxd

#開機自動啟動「InfluxDB
systemctl enable influxdb.service


#進入「influx」設定「資料庫
/usr/bin/influx

#建立「帳號」(admin) 和「密碼」(admin) 允許最高權限
CREATE USER "admin" WITH PASSWORD 'admin' WITH ALL PRIVILEGES

#建立「資料庫」為「collections
CREATE DATABASE "collections"

#編輯「influxdb.conf」允許「透過」Web API 獲取數據。
PS. 可搭配「Grafana」下載「Grafana Dashboard」套用。

vi  /etc/influxdb/influxdb.conf

[http]
  enabled = true
  bind-address = ":8086"
  auth-enabled = true
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/influxdb.pem"

#重新啟動「InfluxDB」
systemctl restart influxd

#檢查「端口」服務
netstat -ltunp | grep -e 8086

參考資料

2017年9月7日 星期四

S小魚仔S Centos 7 啟用 SSH 公鑰 與 私鑰 設定

1. 使用「ssh-keygen -f root」產生 公鑰 和 私鑰,會產生「root」和「root.pub」兩份檔案。

輸入「ll」檢查「root」、「root.pub

2. 下載「Putty_Key_Generator」載入「root」並 產生「Private Key」( *.ppk )
PS. 使用「Win Scp」工具,即可登入下載

載入「root」key

儲存「私鑰」( Private Key)


3. 佈署  Centos「KEY」 公鑰 授權「帳號」和「主機
PS.「root」是「帳號」,「192.168.2.101」主機 IP

ssh-copy-id -i root.pub root@192.168.2.101

4. 編輯「vi /etc/ssh/sshd_config」配置檔 啟用「Key」認證

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys


5. 重啟「sshd」服務,檢查「KEY」位置

systemctl restart  sshd.service

ll /root/.ssh



6. 使用「遠端登入工具」PuttyRoyalts..等載入「Private Key」( *.ppk ) 使用「帳戶」登入即可。


參考資料
史帝芬心得筆記」-「ssh 公鑰認證登入