S小魚仔S 網誌搜尋

2018年7月25日 星期三

S小魚仔S Centos 7 搭建 Ansible awx 套件 提供 UI 介面操作

Ansible Awx (免費) 提供可視化操作介面,開始進行佈署「Ansible Awx」。

#==修改「電腦」名稱 ( SVN )====
hostnamectl set-hostname ansible_awx

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

#==設定 Firewall========

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

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


#==更新「Yum」源
yum install -y epel-release

#安裝「postgresq.rpm」更新「yum」源
yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

#安裝「postgresql」
yum install postgresql96-server -y

#安裝「rabbitmq-server」、「wget」、「memcached」、「nginx」、「ansible」
yum install -y rabbitmq-server wget memcached nginx ansible

#下載「mrmeee-awx-epel-7.repo」套件
wget -O /etc/yum.repos.d/awx-rpm.repo https://copr.fedorainfracloud.org/coprs/mrmeee/awx/repo/epel-7/mrmeee-awx-epel-7.repo

#安裝「awx」
yum install -y awx

#初始化「postgresql」資料庫
/usr/pgsql-9.6/bin/postgresql96-setup initdb

#启动rabbitmq服务
systemctl enable rabbitmq-server
systemctl start rabbitmq-server

#启动Mpostgresql服务
systemctl enable postgresql-9.6
systemctl start postgresql-9.6

#启动Memcached服务
systemctl enable memcached
systemctl start memcached

#创建Postgres用户
sudo -u postgres createuser -S awx

#创建Postgres 数据库
sudo -u postgres createdb -O awx awx

#将数据导入数据库
sudo -u awx /opt/awx/bin/awx-manage migrate

#===初始化 Ansible AWX ====
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'root@localhost', 'password')" | sudo -u awx /opt/awx/bin/awx-manage shell

sudo -u awx /opt/awx/bin/awx-manage create_preload_data

sudo -u awx /opt/awx/bin/awx-manage provision_instance --hostname=$(hostname)

sudo -u awx /opt/awx/bin/awx-manage register_queue --queuename=tower --hostnames=$(hostname)


#===配置Nginx===

#備份來源「nginx.conf」
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bkp

#替换nginx conf文件
wget -O /etc/nginx/nginx.conf https://raw.githubusercontent.com/sunilsankar/awx-build/master/nginx.conf

#啟動「Nginx」
systemctl start nginx
systemctl enable nginx


#==========啟動「Awx」相關「程序」
systemctl start awx-cbreceiver
systemctl start awx-celery-beat
systemctl start awx-celery-worker
systemctl start awx-channels-worker
systemctl start awx-daphne
systemctl start awx-web

#=========開機自動啟動「Awx」相關「程序」
systemctl enable awx-cbreceiver
systemctl enable awx-celery-beat
systemctl enable awx-celery-worker
systemctl enable awx-channels-worker
systemctl enable awx-daphne
systemctl enable awx-web

#====需要「Reboot」重開機====
reboot -h now


接下來輸入「http://ip」 ( User: admin Password: password )


Ansible Awx 安裝完成


#===Ansible AWX 有 Bug 必須使用以下指令修復 ( 2019/09/25 ) 更新 ===
PS. 如果不修復任務會一直處於「pending」狀態 

sudo -u awx scl enable rh-python36 rh-postgresql10 "awx-manage create_preload_data"
sudo -u awx scl enable rh-python36 rh-postgresql10 "awx-manage provision_instance --hostname=$(hostname)"
sudo -u awx scl enable rh-python36 rh-postgresql10 "awx-manage register_queue --queuename=tower --hostnames=$(hostname)"
  
systemctl restart awx-cbreceiver
systemctl restart awx-dispatcher
systemctl restart awx-channels-worker
systemctl restart awx-daphne
systemctl restart awx-web

參考資料

2018年7月17日 星期二

S小魚仔S ELK 5.6.8 支持 sentinl 告警服務 ( E-mail、Wechat....等)

在「Github」發現「sentinl」套件 並支持「Elasticsearch」、「Logstash」、「Kibana」5.6.8 版本,「sentinl」依賴於「kibana」角色並安裝「plugin」。
PS. 「sentinl」與「elk」版本必須對應否則安裝起來會無法使用。

如何安裝「sentinl」?

切換至 kibana 內 bin 資料夾
 cd /opt/kibana-5.6.8-linux-x86_64/bin

執行「安裝」plugin  (在線安裝)
./kibana-plugin install https://github.com/sirensolutions/sentinl/releases/download/prerelease/sentinl-v5.6.8.zip

離線安裝方式
/opt/kibana-5.6.8-linux-x86_64/bin/kibana-plugin install file:/opt/sentinl-v5.6.8.zip

安裝完成會顯示如下畫面

編輯「kibana.yml」(加入最後面即可)



                     #====設定「sentinl plugin」===
                      sentinl:
                         es:
                         host: localhost                      elasticsearch server
                         port: 9200                             # elasticsearch port
                      settings:
                         email:
                              active: true
                              user: "456839"                  #使用「QQ」帳號
                              password: "scdiosdcm3"  #使用「QQ」密碼
                              host: smtp.qq.com           #設定「QQ」smtp
                              ssl: true                             #使用「SSL」加密
                              timeout: 100000                #mail server  timeout

接著重啟「kibana

netstat -ltunp | grep "5601"

kill -9 3409

/opt/kibana-5.6.8-linux-x86_64/bin/kibana &

登入「kibana Web UI

接下來就是 Sentinl Web Ui 相關設置 和 告警服務

建立新的「Watchers」(觀察者)

點選「Watcher

1. 點選「General」建立「標題」和「循環執行時間

這裡就是最關鍵也是最困難,初學者一定看不懂這是什麼意思,簡單的話就是把 需要查詢 ES 條件語句 ( JSON ) 寫入進去,這個預設語句是查詢所有筆數。

多少筆數發生告警

 在「Action」建立「email

輸入「E-mail」相關資訊

點選「SAVE」這個很重要..不然之前做的設定會清空

點選「三角形」圖案 進行單次循環測試

 出現「Executed watcher」表示成功

檢查「信箱」確認 Sentinl Alarm 內容

相關參考資料
seeker的博客」-「Sentinl插件安装及使用
Truman's Blog」-「Sentinl-(Kibana Alert & Report App for Elasticsearch)
玖分博客」-「elk告警插件sentinl安装使用
ELK 6.2.3」-「Kibana 插件 sentinl 使用教程
ELK + Sentinl 日志实时监控报警 钉钉、邮件-「ELK + Sentinl 日志实时监控报警 钉钉、邮件

2018年7月10日 星期二

S小魚仔S Ansible Roles 簡易攻略

Ansible 提供 Roles 寫法 平常很少使用,作筆記避免忘記
什麼是「Ansible」Roels ?
Roles 是 Ansible自1.2版本引入的新特性,用於層次性,結構化地組織 Playbook 簡單來說就是讓程式井然有序。

我們先來看一下 「Roles」基本 資料夾 結構


metricbeat.yml (呼叫程序)

「tasks」 folder ( main.yml ) 執行程序

templates」 folder ( metricbeat_cfg.j2 ) 存放設定檔

vars」 folder ( main.yml ) 存放變數
# 如何呼叫 ansible 變數  => {{kafka_version}}