顯示文章

這裡允許您檢視這個會員的所有文章。請注意, 您只能看見您有權限閱讀的文章。


主題 - sakana

頁: [1] 2 3 ... 6
1
報名網址

https://studyarea.kktix.cc/events/2f263587-77f30d-2013ed-ae4341-fc4884-d02efc-e152b0

時間: 2017/7/22 14:00 ~ 17:00

議題簡介

1.經驗分享

2.廣電級專業系統介紹

3.影音技術基礎

4.直播系統規劃

5.提昇直播品質

6.Q&A

 

講師:Deanger

資歷:廣電級數位影音系統方案顧問

地點: Gandi / 台北市內湖區洲子街196號


2
活動報名頁面 https://opensuse-tw.kktix.cc/events/ansible-opensuse-101

[簡介]
 

Ansible 自動化組態工具 workshop with openSUSE 101

本活動由 openSUSE Taiwan x Study Area  共同主辦

* Study Area 酷學園 FB: https://www.facebook.com/sataiwan/

* openSUSE Taiwan FB: https://www.facebook.com/groups/opensuse.zh/

場地由摩茲工寮 https://moztw.org/space/ 提供

 

請自備筆電參加 workshop,  建議安裝 openSUSE 版本的桌面系統
 

[課程說明]

簡介:
Ansible 為目前 Configuration Management 四大金釵( Puppet / Salt / Chef / Ansible )之一.

希望利用3個小時的時間跟大家聊聊或是讓大家動手玩 Ansible ( 自己動手, 豐衣足食 ) ( 暫定, 主辦單位有更動內容的權力,  好像都是這樣寫 :stuck_out_tongue: ) .

主要是希望有接觸資訊系統的人可以一起聊聊及討論了解相關想法.  ( 其實也不需要俱備先備知識 )

 

可能會聊聊下面的東西 ^^

    Ansible ? Why Ansible?

    預備知識

    安裝 Ansible

    The role of Ansible

    與 shell script 的差異??

    Hello Ansible!! 第一個 ansible 指令

    Inventory file / ansible.cfg 介紹

    Ansible Module 介紹與實作

    Playbook 介紹與實做

    Reference


講師: sakana

講師簡介:
Study-Area 酷學園 小雜工  / GNOME.Asia Committee Member / openSUSE Member

    喜歡社群自由無私的分享、熱愛自由軟體及 Linux 所帶來的方便性

 

[注意事項]
由於內容將為工作坊,請參加者攜帶筆記型電腦並充滿電力 (安裝 openSUSE Leap 42.2 or openSUSE Tumbleweed 者大感謝。)(使用虛擬機或是遠端桌面亦可)

取得 openSUSE 版本: https://www.opensuse.org/

 

[適合對象]

開放原始碼愛好者
想要了解  Ansible 安裝以及入門的社群朋友
 

[課程時程]

14:00 - 17:00  Workshop 工作坊

3
Linux 討論版 / nagios with openSUSE Leap 42.2 小記
« 於: 2017-01-02 16:06 »
原文網址 : http://sakananote2.blogspot.tw/2016/12/nagios-with-opensuse-leap-422.html

目的: 監控 目前專案還有自己的設備
監控公共服務或是主機是否活著

OS: openSUSE Leap 42.2

安裝 nagios 相關套件, plugins 套件的名稱也改了, 現在叫 monitoring-plugins

代碼: [選擇]
# zypper  install   nagios  monitoring-plugins
設定 nagiosadmin 密碼

傳統的方式
代碼: [選擇]
# htpasswd2   -c   /etc/nagios/htpasswd.users   nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

因為考慮之後自動化要結合 ansible 所以也嘗試了 -b 與 -i 選項, 這邊比較有趣的是 -b 或是 -i 都要相選項與 -c 放在一起, 也就是 -b -c 是不行的, 要 -bc 才行

-b  batch mode 密碼要放在使用者帳號後面
代碼: [選擇]
# htpasswd2  -bc   /etc/nagios/htpasswd.users    nagiosadmin    test
Adding password for user nagiosadmin

-i  read stdin, 透過 STDIN 來餵進去密碼
代碼: [選擇]
# echo  test  |  htpasswd2  -ic   /etc/nagios/htpasswd.users    nagiosadmin
Adding password for user nagiosadmin

確認 nagios 開機啟動

代碼: [選擇]
# systemctl   is-enabled   nagios
nagios.service is not a native service, redirecting to systemd-sysv-install
Executing /usr/lib/systemd/systemd-sysv-install is-enabled nagios
disabled

設定開機啟動 nagios
代碼: [選擇]
# systemctl   enable  nagios
nagios.service is not a native service, redirecting to systemd-sysv-install
Executing /usr/lib/systemd/systemd-sysv-install enable nagios


代碼: [選擇]
# systemctl   is-enabled   nagios
nagios.service is not a native service, redirecting to systemd-sysv-install
Executing /usr/lib/systemd/systemd-sysv-install is-enabled nagios
enabled

嘗試啟動 apache2, 這個時候會出現錯誤
代碼: [選擇]
# systemctl  restart  apache2.service
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

使用 status 觀察, 原因是 apache2.4 與 apache2.2 寫法不一樣
代碼: [選擇]
# systemctl  status  apache2.service
12月 31 11:11:50 template start_apache2[7143]: AH00526: Syntax error on line 15 of /etc/apache2/conf.d/nagios.conf:
12月 31 11:11:50 template start_apache2[7143]: Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration
12月 31 11:11:51 template systemd[1]: apache2.service: Main process exited, code=exited, status=1/FAILURE
可以參考
    2.2 用 Order, 但是2.4 用 Require
http://stackoverflow.com/questions/10925528/invalid-command-order-perhaps-misspelled-or-defined-by-a-module-not-included
https://lists.opensuse.org/opensuse-bugs/2015-07/msg02923.html[/list]

解法啟用 access_compat 模組 ( openSUSE / SUSE 預設 authz_host 已經啟動 )
代碼: [選擇]
# a2enmod   mod_access_compat
列出已經啟用的 apache2 module
代碼: [選擇]
# apache2ctl   -M會將設定寫入 /etc/apache2/sysconfig.d/loadmodule.conf 檔案內 LoadModule access_compat_module /usr/lib64/apache2-prefork/mod_access_compat.so

重新啟動 apache2
代碼: [選擇]
# systemctl  restart  apache2.service
觀察資訊
代碼: [選擇]
# systemctl   status  apache2.service

啟動  nagios
代碼: [選擇]
# systemctl  start  nagios
觀察資訊
代碼: [選擇]
# systemctl  status nagios
開啟 http 服務
代碼: [選擇]
#yast2   firewall
預設如果啟動 nagios, 他會去檢查本機 http 服務, 但是沒有預設網頁就會警告, 還有如果監控的項目比較多, total process 也會超標, 所以我調整了一下 /etc/nagios/objects/localhost.cfg  相關內容

代碼: [選擇]
#vi   /etc/nagios/objects/localhost.cfg
註解 HTTP, linux-servers 群組 以及調整 Total Process
# 2014/1/8 edit by sakana, temp disable HTTP monitor
#define service{
#        use         local-service         ; Name of service template to use
#        host_name                       localhost
#        service_description             HTTP
#       check_command                   check_http
#       notifications_enabled           0
#        }

# Define an optional hostgroup for Linux machines
#
#define hostgroup{
#        hostgroup_name  linux-servers ; The name of the hostgroup
#        alias           Linux Servers ; Long name of the group
#        members         localhost     ; Comma separated list of hosts that belong to this group
#        }


# 2014/1/8 edit by sakana change check_local_procs from 250 to 400, 400 to 800
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Total Processes
        check_command                   check_local_procs!400!800!RSZDT
        }

上面其實只是說明, 如果需求跟我一樣懶得動手改, 可以抓網路上我已經改好的
( 其實也是為了自己自動化 )

代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/localhost.cfg
--2016-12-31 12:21:29--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/localhost.cfg
正在查找主機 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
正在連接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 5546 (5.4K) [text/plain]
Saving to: ‘localhost.cfg’

100%[=====================================================================================================================>] 5,546       --.-K/s   in 0s     

2016-12-31 12:21:30 (28.9 MB/s) - ‘localhost.cfg’ saved [5546/5546]

目前目錄下就會有 localhost.cfg
代碼: [選擇]
# ls
bin  Desktop  Documents  Downloads  inst-sys  localhost.cfg  Music  Pictures  Public  Templates  Videos

將localhost.cfg 取代 /etc/nagios/objects/localhost.cfg ( 謎之音: 記得先備份?? )
代碼: [選擇]
# mv    localhost.cfg   /etc/nagios/objects/localhost.cfg

修改通知 e-mail 
代碼: [選擇]
# vi   /etc/nagios/objects/contacts.cfg
修改預設的  e-mail
define contact{
        contact_name    nagiosadmin    ; Short name of user
        use    generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias       Nagios Admin            ; Full name of user
        email  自己帳號@郵件 ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }


檢視 Nagios 設定有沒有問題
代碼: [選擇]
#nagios  -v   /etc/nagios/nagios.cfg
重新啟動 Nagios
代碼: [選擇]
# systemctl  restart  nagios.service
結果如下






安裝 nagios-nrpe 套件

代碼: [選擇]
# zypper  install  nrpe  monitoring-plugins-nrpe
下載之前自己建立的範本檔案
代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/templates.cfg

--2016-12-31 16:13:07--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/templates.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19833 (19K) [text/plain]
Saving to: ‘templates.cfg’

100%[=====================================================================================================================>] 19,833      --.-K/s   in 0.06s   

2016-12-31 16:13:07 (324 KB/s) - ‘templates.cfg’ saved [19833/19833]

確認目前目錄下有 templates.cfg
代碼: [選擇]
# ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  bin  inst-sys  templates.cfg


覆蓋且移動原來的設定檔
代碼: [選擇]
# mv    templates.cfg   /etc/nagios/objects/templates.cfg
下載之前自己建立的範本commands.cfg檔案
代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/commands.cfg

--2016-12-31 16:18:12--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/commands.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7876 (7.7K) [text/plain]
Saving to: ‘commands.cfg’

100%[=====================================================================================================================>] 7,876       --.-K/s   in 0s     

2016-12-31 16:18:13 (60.2 MB/s) - ‘commands.cfg’ saved [7876/7876]


確認 commands.cfg 已經下載
代碼: [選擇]
# ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  bin  commands.cfg  inst-sys

覆蓋且移動原來的設定檔
代碼: [選擇]
# mv    commands.cfg    /etc/nagios/objects/commands.cfg
建立之後存放 Server 與 一般工作站的設定檔目錄
代碼: [選擇]
#mkdir   /etc/nagios/servers
#mkdir   /etc/nagios/pcs
#mkdir   /etc/nagios/racks
#mkdir  /etc/nagios/switches
#mkdir   /etc/nagios/projects
#mkdir   /etc/nagios/labs

取得事先寫好的 linuxPublic.cfg, windowsPublic.cfg 複製給公用服務使用並複製到 /etc/nagios/objects目錄

代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/linuxPublic.cfg

--2016-12-31 16:37:12--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/linuxPublic.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2652 (2.6K) [text/plain]
Saving to: ‘linuxPublic.cfg’

100%[=====================================================================================================================>] 2,652       --.-K/s   in 0s     

2016-12-31 16:37:12 (28.7 MB/s) - ‘linuxPublic.cfg’ saved [2652/2652]

代碼: [選擇]
# mv   linuxPublic.cfg   /etc/nagios/objects/
代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/windowsPublic.cfg

--2016-12-31 16:38:37--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/windowsPublic.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2345 (2.3K) [text/plain]
Saving to: ‘windowsPublic.cfg’

100%[=====================================================================================================================>] 2,345       --.-K/s   in 0s     

2016-12-31 16:38:37 (23.4 MB/s) - ‘windowsPublic.cfg’ saved [2345/2345]

代碼: [選擇]
# mv   windowsPublic.cfg   /etc/nagios/objects/
取得事先寫好的 switchSimple.cfg, rackHost.cfg 複製給switch, 機器服務使用並複製到 /etc/nagios/objects目錄

代碼: [選擇]
# wget   https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/switchSimple.cfg

--2016-12-31 16:41:58--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/switchSimple.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3365 (3.3K) [text/plain]
Saving to: ‘switchSimple.cfg’

100%[=====================================================================================================================>] 3,365       --.-K/s   in 0s     

2016-12-31 16:41:58 (29.6 MB/s) - ‘switchSimple.cfg’ saved [3365/3365]
代碼: [選擇]
# mv   switchSimple.cfg   /etc/nagios/objects/
代碼: [選擇]
# wget   https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/rackHost.cfg

--2016-12-31 16:43:38--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/rackHost.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2716 (2.7K) [text/plain]
Saving to: ‘rackHost.cfg’

100%[=====================================================================================================================>] 2,716       --.-K/s   in 0s     

2016-12-31 16:43:38 (18.2 MB/s) - ‘rackHost.cfg’ saved [2716/2716]

代碼: [選擇]
# mv   rackHost.cfg   /etc/nagios/objects/

取得事先寫好的 windows.cfg 複製給windows 服務使用並複製到 /etc/nagios/objects目錄

代碼: [選擇]
# wget   https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/windows.cfg

--2016-12-31 16:53:25--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/windows.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4023 (3.9K) [text/plain]
Saving to: ‘windows.cfg’

100%[=====================================================================================================================>] 4,023       --.-K/s   in 0s     

2016-12-31 16:53:25 (45.9 MB/s) - ‘windows.cfg’ saved [4023/4023]

代碼: [選擇]
# mv   windows.cfg    /etc/nagios/objects/

取得事先寫好的 nagios.cfg 主要是修改使用 cfg_dir= 並複製到 /etc/nagios目錄

代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/nagios.cfg

--2016-12-31 16:48:01--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/nagios.cfg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44650 (44K) [text/plain]
Saving to: ‘nagios.cfg’

100%[=====================================================================================================================>] 44,650      --.-K/s   in 0.1s   

2016-12-31 16:48:01 (397 KB/s) - ‘nagios.cfg’ saved [44650/44650]

代碼: [選擇]
# mv    nagios.cfg   /etc/nagios/
檢視 Nagios 設定有沒有問題
代碼: [選擇]
#nagios  -v   /etc/nagios/nagios.cfg這邊可能會有警告, 因為 rack 主機我們只檢查主機不檢查服務

重新啟動 Nagios
代碼: [選擇]
# systemctl  restart  nagios.service
結果如下



Part II:   Nagios 用戶端-- Linux 伺服器用戶端建置

請於 Client 端

1.安裝 nagios-nrpe套件

代碼: [選擇]
# zypper  install  nrpe  monitoring-plugins-nrpe monitoring-plugins
2.設定nagios-nrpe 套件
(另外最好去確認 /etc/services 有沒有 nrpe 5666/tcp # nagios nrpe 的設定)
代碼: [選擇]
#grep  5666  /etc/services
修改設定檔 允許 Nagios 伺服器連線 ( 設定檔位置有改變, 目前為 /etc/nrpe.cfg )
代碼: [選擇]
# vi  /etc/nrpe.cfg

allowed_hosts=127.0.0.1,192.168.100.199

(請依照實際的IP 作為修正, 可能為 10.x.x.x )
這邊要注意 127.0.0.1後面要加上 逗點 , 然後主機 IP 不能有空格
不然會出現沒有辦法建立 SSL HandShake
(這個部份可以解釋, 如果nrpe是使用 SystemV 的形式啟動後面都會出現不能建立SSL Handshake ,但是以Xinetd 就不會)


啟動 NRPE
代碼: [選擇]
# systemctl   start   nrpe
檢查狀態 ( 這邊有看到 /run/nrpe/nrpe.pid 無法建立, 但是目前測試沒有影響查詢, 如果不放心就建立 /run/nrpe 然後給 nagios 寫入權限 )
代碼: [選擇]
# systemctl  status nrpe

● nrpe.service - Daemon to remotely execute Nagios plugins
   Loaded: loaded (/usr/lib/systemd/system/nrpe.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2016-12-31 19:17:50 CST; 3min 50s ago
  Process: 3457 ExecStart=/usr/sbin/nrpe -c /etc/nrpe.cfg -d (code=exited, status=0/SUCCESS)
 Main PID: 3461 (nrpe)
    Tasks: 1 (limit: 512)
   CGroup: /system.slice/nrpe.service
           └─3461 /usr/sbin/nrpe -c /etc/nrpe.cfg -d

12月 31 19:17:50 template systemd[1]: Starting Daemon to remotely execute Nagios plugins...
12月 31 19:17:50 template systemd[1]: Started Daemon to remotely execute Nagios plugins.
12月 31 19:17:50 template nrpe[3461]: Starting up daemon
12月 31 19:17:50 template nrpe[3461]: Cannot write to pidfile '/run/nrpe/nrpe.pid' - check your privileges.

設定開機啟動 NRPE
代碼: [選擇]
# systemctl   enable  nrpe
確認開機啟動
代碼: [選擇]
# systemctl  is-enabled    nrpe
enabled
請於Client 端
執行 check_nrpe 測試, 成功應該會出現 NRPE的版本
代碼: [選擇]
# /usr/lib/nagios/plugins/check_nrpe   -H   127.0.0.1
NRPE v2.15

*************************************************************
請於 Server 端

針對 nagios client 測試 nagios-nrpe 成功應該會出現 NRPE的版本
代碼: [選擇]
#/usr/lib/nagios/plugins/check_nrpe  -H  192.168.100.100
NRPE v2.15

(這邊請確認 firewall 是否關閉, 或是准許 nrpe 通過, 可以使用 #yast2  firewall 關閉防火牆測試  或是下指令 #rcSuSEfirewall2  stop )


*************************************************************[/color]


請於Client 端
加入相關 nrpe 指令 ( 因為目前已經沒有 hda1 了 )
代碼: [選擇]
#vi   /etc/nagios/nrpe.cfg
加入
#command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_sda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_sda2]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh   127.0.0.1
command[check_smtp]=/usr/lib/nagios/plugins/check_smtp  127.0.0.1

也可以用之前已經做好的 nrpe.cfg

代碼: [選擇]
# wget  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/nrpe.cfg

--2016-12-31 19:49:29--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/nrpe.cfg
正在查找主機 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
正在連接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 8474 (8.3K) [text/plain]
Saving to: ‘nrpe.cfg’

100%[===========================================================================>] 8,474       --.-K/s   in 0s     

2016-12-31 19:49:29 (53.1 MB/s) - ‘nrpe.cfg’ saved [8474/8474]

代碼: [選擇]
#vi   /etc/nagios/nrpe.cfg
(如果IP有改就改 allowed_hosts= 後面接的IP吧 !! )
覆蓋原來的檔案
代碼: [選擇]
# mv   nrpe.cfg   /etc/
重新啟動
代碼: [選擇]
# systemctl   restart  nrpe
測試相關指令
代碼: [選擇]
# /usr/lib/nagios/plugins/check_nrpe   -H 127.0.0.1   -c   check_sda2
DISK OK - free space: / 12753 MB (69% inode=97%);| /=5661MB;14732;16573;0;18415

代碼: [選擇]
# /usr/lib/nagios/plugins/check_nrpe  -H 127.0.0.1  -c  check_users
USERS OK - 2 users currently logged in |users=2;5;10;0

代碼: [選擇]
# /usr/lib/nagios/plugins/check_nrpe   -H 127.0.0.1   -c   check_load
OK - load average: 0.00, 0.00, 0.00|load1=0.000;15.000;30.000;0; load5=0.000;10.000;25.000;0; load15=0.000;5.000;20.000;0;

代碼: [選擇]
# /usr/lib/nagios/plugins/check_nrpe   -H 127.0.0.1   -c   check_total_procs
PROCS OK: 208 processes | procs=208;250;300;0;

另外於 Server端測試 相關的指令
代碼: [選擇]
# /usr/lib/nagios/plugins/check_nrpe  -H 192.168.100.100   -c check_sda2
DISK OK - free space: / 12753 MB (69% inode=97%);| /=5661MB;14732;16573;0;18415




Part III:   將linux 伺服器(Nagios Client)加入到 Nagios監控範圍

請於Server上面

下載事先做好的 linux.cfg 範本
代碼: [選擇]
# wget   https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/linux.cfg

--2016-12-31 20:14:49--  https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/playbook/general/nagios/files/linux.cfg
正在查找主機 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.100.133
正在連接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.100.133|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 3664 (3.6K) [text/plain]
Saving to: ‘linux.cfg’

100%[===================================================================>] 3,664       --.-K/s   in 0s     

2016-12-31 20:14:49 (19.2 MB/s) - ‘linux.cfg’ saved [3664/3664]
移動到 /etc/nagios/objects 下
代碼: [選擇]
# mv    linux.cfg   /etc/nagios/objects/
**設定 Nagios 載入 linux client 的設定檔 **

依照不同的性質將範本設定檔 linux.cfg 複製到不同目錄我們建立了
/etc/nagios/labs - 監控實驗機器
/etc/nagios/servers - 監控服務機器
/etc/nagios/pcs - 監控pc
/etc/nagios/projects - 監控專案機器
/etc/nagios/racks - 監控機架 IPMI
/etc/nagios/switches - 監控 switch

假設有台 linux 服務機器要監控
將剛剛的 linux.cfg 複製給 linux server 使用並複製到 /etc/nagios/servers目錄
代碼: [選擇]
# cp  /etc/nagios/objects/linux.cfg   /etc/nagios/servers/linux100.cfg
確認IP設定無誤
代碼: [選擇]
#vi   /etc/nagios/servers/linux100.cfg
address         192.168.3.129 請改成實際的IP
host_name     suseserver129 請改成實際的名稱
確認設定檔是否無誤
代碼: [選擇]
# nagios   -v   /etc/nagios/nagios.cfg
重新啟動 nagios 使其生效
代碼: [選擇]
# systemctl   restart    nagios
結果如下




大功告成

~ enjoy it

4
活動報名頁面 http://opensuse-tw.kktix.cc/events/docker101

[簡介]
 

Docker and openSUSE workshop 101

本活動由 openSUSE Taiwan x Study Area x NCTU 330 共同主辦

* Study Area 酷學園 FB: https://www.facebook.com/sataiwan/

* openSUSE Taiwan FB: https://www.facebook.com/groups/opensuse.zh/

* NCTU 330 KKTIX: http://nctu330.kktix.cc/

 

請自備筆電參加 workshop, 如果有 vi 或是文字編輯器更佳 :)

 

在這個  workshop 內我們會介紹

* docker 介紹

* 安裝 docker

* docker 映像檔管理

-- 下載映像檔並觀察

-- 映像檔查詢與取得

* 建立 docker 映像檔 -- 修改現有映像檔方式

* 建立 docker 映像檔 -- 使用 Dockerfile

* 硬像檔管理 - Tag 與刪除映像檔

* 交流時間


[適合對象]

開放原始碼愛好者
想要了解  Docker 安裝以及入門
 

[課程時程]

19:00 - 21:00

 

[講者]

Sakana

Study-Area 酷學園 小雜工  / GNOME.Asia Committee Member / openSUSE Member

喜歡社群自由無私的分享、熱愛自由軟體及 Linux 所帶來的方便性.

 

[系列活動資訊]
2016 年9月24日(詳情請見臉書社團公佈) - openSUSE Taiwan & Study Area
主題:Open Build Service 實作練習 Workshop 101
地點:摩茲工寮
共同主辦社群: Study-Area

預定 2016 10月(詳情請見臉書社團公佈) - openSUSE Taiwan & Study Area
主題:Docker and openSUSE workshop 101
地點:摩茲工寮(預定)
共同主辦社群: Study-Area

5
DevOps 討論版 / Spark 本機安裝 with Ansible
« 於: 2016-06-27 17:06 »
圖文並茂版本在 http://sakananote2.blogspot.tw/2016/06/spark-with-ansible.html

Spark 本機安裝 with Ansible
現在的實驗環境會透過 Ansible 來管理

 所以整理了一下 spark local 套件安裝的 ansible playbook
使用 group 方式控管
安裝 spark 相關套件, 透過變數詢問下載不同版本, 預設是 1.4.0
使用 when: 方式針對不同的 OS 來安裝, 目前有 openSUSE Leap, CentOS, 還有 ubuntu
目前已測試 openSUSE 42.1 / CentOS 7.2 / Ubuntu 14.04

 檔案 spark_local.yml

代碼: [選擇]
- name: Install spark with local
  hosts: sparkSingle
#  透過 vars_prompt 動態詢問要裝的版本, 預設是 1.4.0
  vars_prompt:
    - name: "spark_version"
      prompt: "Please enter spark version, example 1.4.0"
      private: no
      default: "1.4.0"

   tasks:
    - name: Install java, wget  with openSUSE Leap
# Use sudo before ansible 1.9
#      sudo: True
      become: True
# 使用 pkg 加上 {{ item }} 配合後面的 with_item 來安裝多個套件
      zypper: name={{ item }}
      with_items:
        - java-1.7.0-openjdk-devel
        - wget
      when: ansible_distribution == "openSUSE Leap"

     - name: Install java, wget with CentOS
      become: True
      yum: name={{ item }}
      with_items:
        - java-1.7.0-openjdk-devel
        - wget
      when: ansible_distribution == "CentOS"

     - name: Install java, wget and scala with Ubuntu
      become: True
      apt: name={{ item }} update_cache=yes
      with_items:
        - openjdk-7-jdk
        - wget
        - scala
      when: ansible_distribution == "Ubuntu"

 # ----------------------------------------------------------

     - name: Get scala
      shell: wget http://www.scala-lang.org/files/archive/scala-2.10.1.tgz
      when: ansible_distribution == "CentOS" or ansible_distribution == "openSUSE Leap"

     - name: Exact source code of scala
      shell: tar xvf scala-2.10.1.tgz
      when: ansible_distribution == "CentOS" or ansible_distribution == "openSUSE Leap"

     - name: Move scala to /usr/lib
      become: True
      shell: mv scala-2.10.1 /usr/lib
      when: ansible_distribution == "CentOS" or ansible_distribution == "openSUSE Leap"

     - name: create link for scala
      become: True
      shell: ln -s /usr/lib/scala-2.10.1/  /usr/lib/scala
      when: ansible_distribution == "CentOS" or ansible_distribution == "openSUSE Leap"

     - name: touch .bashrc
      shell: touch ~/.bashrc
      when: ansible_distribution == "CentOS" or ansible_distribution == "openSUSE Leap"

     - name: export $PATH to .bashrc
      lineinfile: dest=~/.bashrc line="export PATH=$PATH:/usr/lib/scala/bin"
      when: ansible_distribution == "CentOS" or ansible_distribution == "openSUSE Leap"

 # ----------------------------------------------------------


# 由於沒有在 general option 使用 sudo, 這邊在使用 shell module 抓下來就是使用者自己的身份額非 root
# 這邊用 spark 1.4.0 版本
    - name: Download spark with pre-build hadoop
        shell: wget    http://archive.apache.org/dist/spark/spark-{{ spark_version }}/spark-{{ spark_version }}-bin-hadoop2.6.tgz

 # 解開 source code
    - name: Exact pre-build source
      shell: tar zxvf spark-*.tgz

     - name: Rename spark folder
      shell: mv ~/spark*/ ~/spark


# 測試 jps 指令
    - name: Testing jps command
      command: jps
      register: jps
    - debug: var=jps.stdout_lines

 執行方式

 將要安裝 spark 的主機加入 sparkSingle 群組
然後執行 spark_local.yml 即可

 先記下來

 ~ enjoy it

6
圖文並茂版本
https://sakananote2.blogspot.tw/2016/06/ansible-vsphereguest-with-opensuse-2.html
https://sakananote2.blogspot.tw/2016/06/ansible-vsphereguest-module-with.html

OS: openSUSE Leap 42.1

Ansible: 2.1.0.0
Module: vsphere_guest

    http://docs.ansible.com/ansible/vsphere_guest_module.html


Requirements (on host that executes module)

    python >= 2.6
    pysphere


檢查需求
# python --version
Python 2.7.9

pysphere 的部份

    https://software.opensuse.org/package/python-pysphere?search_term=pysphere


參考之前的網誌
加入套件庫
代碼: [選擇]
# zypper  --gpg-auto-import-keys   addrepo   -f  http://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_Leap_42.1/devel:languages:python.repo
搜尋套件
代碼: [選擇]
# zypper   search   -s   sphere
Loading repository data...
Reading installed packages...

S | Name            | Type       | Version   | Arch   | Repository                         
--+-----------------+------------+-----------+--------+------------------------------------
  | python-pysphere | package    | 0.1.8-1.1 | noarch | Python Modules (openSUSE_Leap_42.1)

安裝 pysphere
代碼: [選擇]
# zypper  install   python-pysphere
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  python-pysphere

1 new package to install.
Overall download size: 891.9 KiB. Already cached: 0 B. After the operation, additional 13.8 MiB will be used.
Continue? [y/n/? shows all options] (y):  Y
建立測試 playbook
後來採用 local 的方式執行, 然後相關資訊使用 var_prompt 的方式

檔案 Test_vsphere_guest_get_facts.yml

代碼: [選擇]
- name: Testing vsphere_guest module in VMware
# 這邊自己習慣控管 VMware 的是用本機
# 配合 hosts 內的 ansible_connection=local
  hosts: localhost
# 設定使用 local connection
  connection: local
# 這種方式還不錯, 透過提示來輸入相關變數
  vars_prompt:
# 這邊的 name 就會是變數的名稱
    - name: "vcenter_hostname"
# 設定提示文字
      prompt: "Enter vcenter hostname"
# private 設定為 no 會顯示輸入的內容
      private: no
# 這邊可以設定預設值
      default: "vcsa"

    - name: "vcenter_user"
      prompt: "Enter vCenter username"
      private: no
      default: root

    - name: "vcenter_pass"
      prompt: "Enter vcenter password"
# private 設定為 yes 會顯示輸入的內容
      private: yes

    - name: "guest_name"
      prompt: "Enter guest vm name"
      private: no


  tasks:
    - name: Testing gater facts from vSphere
# 使用 vsphere_guest 來設定相關工作
      vsphere_guest:
# vCenter 的 IP 或是 FQDN, 這邊用上面的變數讓使用者輸入
        vcenter_hostname: "{{ vcenter_hostname }}"
# Ansible 2.1 以後的版本可以設定 validate_certs, 預設會檢查 SSL certs, 如果是自己架設的vC, 可以設定no
        validate_certs: no
# vCenter 上面的使用者名稱, 對應上面的變數
        username: "{{ vcenter_user }}"
# vCenter 使用者的密碼, 對應上面的變數
        password: "{{ vcenter_pass }}"
# 要針對的 VMware guest 名稱
        guest: "{{ guest_name }}"
# 是否要取回 guest 資訊
        vmware_guest_facts: yes

下指令執行還有輸出結果

代碼: [選擇]
> ansible-playbook   -v   test_vsphere_guest_get_facts.yml
Enter vcenter hostname [vcsa]:  YOURIP_FQDN
Enter vCenter username [root]:
Enter vcenter password:
Enter guest vm name: openSUSELeap_SA_Docker

PLAY [Testing vsphere_guest module in VMware] **********************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [Testing gater facts from vSphere] ****************************************
ok: [localhost] => {"ansible_facts": {"hw_eth0": {"addresstype": "manual", "ipaddresses": [“w.x.y.z", "fe80::220:5fff:fe11:1111"], "label": "Network adapter 1", "macaddress": "00:50:56:11:11:11", "macaddress_dash": "00-50-56-11-11-11", "summary": "VM Net"}, "hw_guest_full_name": "Other Linux (32-bit)", "hw_guest_id": "otherLinuxGuest", "hw_interfaces": ["eth0"], "hw_memtotal_mb": 3976, "hw_name": "openSUSELeap_SA_Docker", "hw_power_status": "POWERED ON", "hw_processor_count": 2, "hw_product_uuid": "4222b4d6-ef7b-dc72-8603-9f7cbbfc2737", "module_hw": true}, "changed": false}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0   


建立 test_vsphere_guest_delete_vm.yml

代碼: [選擇]
- name: Testing vsphere_guest module in VMware
# 這邊自己習慣控管 VMware 的是用本機
# 配合 hosts 內的 ansible_connection=local
  hosts: localhost
# 設定使用 local connection
  connection: local
# 這種方式還不錯, 透過提示來輸入相關變數
  vars_prompt:
# 這邊的 name 就會是變數的名稱
    - name: "vcenter_hostname"
# 設定提示文字
      prompt: "Enter vcenter hostname"
# private 設定為 no 會顯示輸入的內容
      private: no
# 這邊可以設定預設值
      default: "vcsa"
    - name: "vcenter_user"
      prompt: "Enter vCenter username"
      private: no
      default: root
    - name: "vcenter_pass"
      prompt: "Enter vcenter password"
# private 設定為 yes 會顯示輸入的內容
      private: yes
    - name: "guest_name"
      prompt: "Enter guest VM name your want to delete"
      private: no
  tasks:
    - name: Delete VM
# 使用 vsphere_guest 來設定相關工作
      vsphere_guest:
# vCenter 的 IP 或是 FQDN, 這邊用上面的變數讓使用者輸入
        vcenter_hostname: "{{ vcenter_hostname }}"
# Ansible 2.1 以後的版本可以設定 validate_certs, 預設會檢查 SSL certs, 如果是自己架設的vC, 可以設定no
        validate_certs: no
# vCenter 上面的使用者名稱, 對應上面的變數
        username: "{{ vcenter_user }}"
# vCenter 使用者的密碼, 對應上面的變數
        password: "{{ vcenter_pass }}"
# 要針對的 VMware guest 名稱
        guest: "{{ guest_name }}"
#
        state: absent
# 如果有使用 force: yes, 就是虛擬機不需要先關機就刪除
# 實際上觀察, 是會先關機然後刪除
        force: yes     
這樣可以用來刪除指定的 VM

 檔案 test_vsphere_guest_deploy_from_template.yml
代碼: [選擇]
- name: Testing vsphere_guest module in VMware
# 這邊自己習慣控管 VMware 的是用本機
# 配合 hosts 內的 ansible_connection=local
  hosts: localhost
  connection: local
# 這種方式還不錯, 透過提示來輸入相關變數
  vars_prompt:
# 這邊的 name 就會是變數的名稱
    - name: "vcenter_hostname"
# 設定提示文字
      prompt: "Enter vcenter hostname"
# private 設定為 no 會顯示輸入的內容
      private: no
# 這邊可以設定預設值
      default: "vcsa"

    - name: "vcenter_user"
      prompt: "Enter vCenter username"
      private: no
      default: root

    - name: "vcenter_pass"
      prompt: "Enter vcenter password"
# private 設定為 yes 會顯示輸入的內容
      private: yes

    - name: "esxi_hostname"
      prompt: "Enter esxi hostname"
      private: no

    - name: "template_name"
      prompt: "Enter Template name"
      private: no
      default: openSUSELeap42.1_Training_Template

  tasks:
    - name: Create VM from template
# 可以用 with_sequence 方式, %0x 為序號, x 為16進制, 所以我用 10進制 u
# 如果是 %02x 就是 2位數, 例如 server00
# 如果只設定 server%0x , 但是超出1位數, 例如 1 to 10, 最後一個會變成 servera
# stride=2 代表間隔是 2
      with_sequence: start=1 end=10 stride=1 format=server%02u

# 用 with_item 正面表列
#      with_items:
#        - server01
#        - server02

# 使用 vsphere_guest 來設定相關工作
      vsphere_guest:
# vCenter 的 IP 或是 FQDN, 這邊用上面的變數讓使用者輸入
        vcenter_hostname: "{{ vcenter_hostname }}"
# Ansible 2.1 以後的版本可以設定 validate_certs, 預設會檢查 SSL certs, 如果是自己架設的vC, 可以設定no
        validate_certs: no
# vCenter 上面的使用者名稱, 對應上面的變數
        username: "{{ vcenter_user }}"
# vCenter 使用者的密碼, 對應上面的變數
        password: "{{ vcenter_pass }}"
# 要針對的 VMware guest 名稱
        guest: "{{ item }}"
# 從範本複製
# 如果有 from_template 就不能設定 state
        from_template: yes
# 範本名稱
        template_src: "{{ template_name }}"
# 複製範本完是否要開機, 預設是 yes
        power_on_after_clone: no
# 要佈署的 esxi 主機
        esxi:
          datacenter: Lab
          hostname: "{{ esxi_hostname }}"
     
# 目前測試 resource_pool 沒有成功
#        resource_pool: "/Resources"
在 VMware 上面的結果



然後應用相同的方式也讓刪除 VM 可以刪除多個
測試 reconfig 功能

    目前只支援 cdroom, mem 還有 cpu 數量的更改


檔案 test_vsphere_guest_reconfig_vm.yml

代碼: [選擇]
- name: Testing vsphere_guest module in VMware
# 這邊自己習慣控管 VMware 的是用本機
# 配合 hosts 內的 ansible_connection=local
  hosts: localhost
  connection: local
# 這種方式還不錯, 透過提示來輸入相關變數
  vars_prompt:
# 這邊的 name 就會是變數的名稱
    - name: "vcenter_hostname"
# 設定提示文字
      prompt: "Enter vcenter hostname"
# private 設定為 no 會顯示輸入的內容
      private: no
# 這邊可以設定預設值
      default: "vcsa"

    - name: "vcenter_user"
      prompt: "Enter vCenter username"
      private: no
      default: root

    - name: "vcenter_pass"
      prompt: "Enter vcenter password"
# private 設定為 yes 會顯示輸入的內容
      private: yes

    - name: "esxi_hostname"
      prompt: "Enter esxi hostname"
      private: no

  tasks:
    - name: Reconfig VM
#  'reconfigured' only applies changes to 'vm_cdrom', 'memory_mb', and 'num_cpus' in vm_hardware parameter.
#
# 可以用 with_sequence 方式, %0x 為序號, 10進制是用 u, 所以用 %02u
# 如果是 %02x 就是 2位數, 例如 server00
# 如果只設定 server%0x , 但是超出1位數, 例如 1 to 10, 最後一個會變成 servera
      with_sequence: start=1 end=5 stride=1 format=server%02u

# 用 with_item 正面表列
#      with_items:
#        - server01
#        - server02

# 使用 vsphere_guest 來設定相關工作
      vsphere_guest:
# vCenter 的 IP 或是 FQDN, 這邊用上面的變數讓使用者輸入
        vcenter_hostname: "{{ vcenter_hostname }}"
# Ansible 2.1 以後的版本可以設定 validate_certs, 預設會檢查 SSL certs, 如果是自己架設的vC, 可以設定no
        validate_certs: no
# vCenter 上面的使用者名稱, 對應上面的變數
        username: "{{ vcenter_user }}"
# vCenter 使用者的密碼, 對應上面的變數
        password: "{{ vcenter_pass }}"
# 要針對的 VMware guest 名稱
        guest: "{{ item }}"

# 如果有 from_template 就不能設定 state
        state: reconfigured

        vm_hardware:
          memory_mb: 2048
#          num_cpus: 4

# 如果設定 force: yes, 就會先關機然後設定再開機
# 有些設定必須在 VM 關機的狀況才能實施
        force: yes
# 要佈署的 esxi 主機
        esxi:
          datacenter: Lab
          hostname: "{{ esxi_hostname }}"
另外就是建立 VM 設定檔

    只有建立新 VM 設定檔, 沒有包含安裝
    folder的話要是範本與機器有的folder


檔案 test_vsphere_guest_create_newvm.yml

代碼: [選擇]
- name: Testing vsphere_guest module in VMware
# 這邊自己習慣控管 VMware 的是用本機
# 配合 hosts 內的 ansible_connection=local
  hosts: localhost
  connection: local
# 這種方式還不錯, 透過提示來輸入相關變數
  vars_prompt:
# 這邊的 name 就會是變數的名稱
    - name: "vcenter_hostname"
# 設定提示文字
      prompt: "Enter vcenter hostname"
# private 設定為 no 會顯示輸入的內容
      private: no
# 這邊可以設定預設值
      default: "vcsa"

    - name: "vcenter_user"
      prompt: "Enter vCenter username"
      private: no
      default: root

    - name: "vcenter_pass"
      prompt: "Enter vcenter password"
# private 設定為 yes 會顯示輸入的內容
      private: yes

    - name: "esxi_hostname"
      prompt: "Enter esxi hostname"
      private: no


  tasks:
    - name: Create New VM
# 可以用 with_sequence 方式, %0x 為序號
# 如果是 %02x 就是 2位數, 例如 server00
# 如果只設定 server%0x , 但是超出1位數, 例如 1 to 10, 最後一個會變成 servera
# stride=2 代表間隔是 2
      with_sequence: start=0 end=1 stride=1 format=server%02x

# 用 with_item 正面表列
#      with_items:
#        - server01
#        - server02

# 使用 vsphere_guest 來設定相關工作
      vsphere_guest:
# vCenter 的 IP 或是 FQDN, 這邊用上面的變數讓使用者輸入
        vcenter_hostname: "{{ vcenter_hostname }}"
# Ansible 2.1 以後的版本可以設定 validate_certs, 預設會檢查 SSL certs, 如果是自己架設的vC, 可以設定no
        validate_certs: no
# vCenter 上面的使用者名稱, 對應上面的變數
        username: "{{ vcenter_user }}"
# vCenter 使用者的密碼, 對應上面的變數
        password: "{{ vcenter_pass }}"
# 要針對的 VMware guest 名稱
        guest: "{{ item }}"
#
# 如果有 from_template 就不能設定 state
        state: powered_off
#
        vm_extra_config:
          vcpu.hotadd: yes
          mem.hotadd:  yes
          notes: Create by Ansible
# 這邊的 Folder 必須是在虛擬機器與範本下的 folder, 不是主機與叢集下的 folder
          folder: Ansible
          resource_pool: "Resources"
        vm_disk:
          disk1:
            size_gb: 10
            type: thin
            datastore: Local_30.3
#
        vm_nic:
          nic1:
            type: vmxnet3
            network: Lab-192-168-100
            network_type: standard
#
        vm_hardware:
          memory_mb: 2048
          num_cpus: 2
# osid 可以參考 https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
          osid: sles11_64Guest
          scsi: paravirtual
          vm_cdrom:
            type: "iso"
            iso_path: "Local_30.3/ISO/SLE-12-SP1-Server-DVD-x86_64-GM-DVD1.iso"

# VMware 硬體版本
        vm_hw_version: vmx-08
# 要佈署的 esxi 主機
        esxi:
          datacenter: Lab
          hostname: "{{ esxi_hostname }}"



先記下來

~ enjoy it

7
原文在此 http://sakananote2.blogspot.tw/2016/05/ansible-consul-in-opensuse-leap-421.html

以 ansible 安裝 consul in openSUSE Leap 42.1
Consul with ansible

因為之後 docker swarm 需要用到 consul , 所以就建立 consul

 OS: openSUSE Leap 42.1

一般建立 consul 的作法

 建立使用者 consul  ( 不一定要建立這個使用者, 這個是工作上協調的結果 )
代碼: [選擇]
#useradd  -m  consul
建立相關目錄
代碼: [選擇]
#mkdir  -p  /opt/consul/bin   /opt/consul/data   /opt/consul/config
設定權限以及更改擁有人為使用者 consul
代碼: [選擇]
#chown  -R  consul   /opt/consul/

 #chmod  -R  700  /opt/consul/

 從網路取得 consul 並解壓縮 zip ( 這邊以 0.6.4 為例 )

 
代碼: [選擇]
#wget   https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip

 #unzip  consul_0.6.4_linux_amd64.zip
將 consul 複製到指定的目錄
代碼: [選擇]
#cp  consul   /opt/consul/bin
切換使用者 consul
代碼: [選擇]
#su  -  consul
編寫設定檔 ( 這邊我們是先試用官方的服務 https://atlas.hashicorp.com/consul  )
>vi   /opt/consul/config/atlas_consul.json


代碼: [選擇]
{
  "bind_addr": "請填入機器IP",
  "atlas_infrastructure": "請填入帳號/請填入名稱",
  "atlas_join": true,
  "atlas_token": "請填入自己的token",
  "bootstrap_expect": 3,
  "datacenter": "Hsinchu-NCHC",
  "data_dir": "/opt/consul/data",
  "log_level": "INFO",
  "node_name": "請填入主機名稱",
  "encrypt": "請填入加密的資訊",
  "server": true
}


啟動 consul agent
代碼: [選擇]
> /opt/consul/bin/consul   agent   -config-dir   /opt/consul/config/
目前是用 nohup 方式在背景執行, 然後離開
代碼: [選擇]
> nohup /opt/consul/bin/consul agent -config-dir /opt/consul/config/ &
停止 consul 的方式( 這樣不會產生 error )
代碼: [選擇]
/opt/consul/bin/consul  leave




 ------- Ansible 方式 ----------



 接下來自己寫了一個 ansible 的playbook 來安裝 consul

 檔案名稱 Consul_install.yml

代碼: [選擇]
---
######################################################### 
# Install consul and setup boot
- name: use when conditionals and setup module (facts)
  hosts: all
  tasks:
# 使用 setup moudule 列出 OS 種類
    - name: use setup module to list os distribution
# setup moudle 可以使用 filter 過濾相關內容
      setup: filter=ansible_distribution


######################################################### 

 - name: Install consul , add user and setting up env
# use group
  hosts: ConsulHost
  sudo: True
  tasks:
    - name: Add user consul
      user: name=consul

     - name: Create folder for consul
      file: path=/opt/consul/{{ item }} state=directory owner=consul mode=700
      with_items:
        - bin
        - data
        - config

     - name: Install wget with openSUSE Leap
      zypper: name={{ item }}
      with_items:
        - wget
      when: ansible_distribution == "openSUSE Leap"

     - name: Install wget with CentOS
      yum: name={{ item }}
      with_items:
        - wget
      when: ansible_distribution == "CentOS"

     - name: Install wget with Ubuntu
      apt: name={{ item }} update_cache=yes
      with_items:
        - wget
      when: ansible_distribution == "Ubuntu"

 #------------------------------------------------------- 

     - name: Get consul 0.6.4 zip
      shell: wget   https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip

 #------------------------------------------------------- 

     - name: Unzip consul 0.6.4 zip file
      shell: unzip consul_0.6.4_linux_amd64.zip

 #------------------------------------------------------- 

     - name: Copy consul to path
      shell: cp consul /opt/consul/bin

 ######################################################### 
# Copy config files with user consul
- name: copy config files with user consul
  hosts: ConsulHost
  tasks:
    - name: use setup module to list os distribution
      become_user: consul
      become: yes
      template: src=templates/atlas_consul.json dest=/opt/consul/config/atlas_consul.json

 # 這個部份有待討論如何在背景執行 可能要寫成服務的方式, 目前會斷
#    - name: running consul at backgroud
#      become_user: consul
#      become: yes
#      shell: nohup /opt/consul/bin/consul agent -config-dir /opt/consul/config &

檔案 templates/atlas_consul.json

代碼: [選擇]
{% for host in groups['ConsulHost'] %}
{
  "bind_addr": "{{ hostvars[host].ansible_default_ipv4.address }}",
  "atlas_infrastructure": "請填入帳號/請填入名稱",
  "atlas_join": true,
  "atlas_token": "請填入自己的token",
  "bootstrap_expect": 3,
  "datacenter": "Hsinchu-NCHC",
  "data_dir": "/opt/consul/data",
  "log_level": "INFO",
  "node_name": "{{ hostvars[host].ansible_hostname }}",
  "encrypt": "請填入加密的資訊",
  "server": true
}
{% endfor %}

8
報名網址 https://edu.nchc.org.tw/course/one_course_introduction.asp?lms_auto_course_id=2930&from_course_list_url=course_index

課程名稱: Apache Spark 建置與開發實務課程 (台中)
上課地點: 國家高速網路與計算中心(台中) 交通方式 http://www.nchc.org.tw/tw/traffic.php
上課時間: 2016/6/16 (四) ~ 2016/6/17 (五) 09:30 ~ 16:30
上課總天數:2 天,共計 12 個小時

提供午餐:   是
招生人數:   6 ~ 10  人
 
講師:   
國家高速網路與計算中心 - 軟體發展組    莊家雋  博士
國家高速網路與計算中心 - 軟體發展組    陳威宇  副研究員

 
報名費用:   
一般人士   3600 元
學生   2800 元

課程介紹:   
Hadoop是近年來為了大資料分析而發展出來的數據處理架構,其中的二個關鍵技術HDFS與MapReduce,建構出大資料分析的執行環境和服務。但隨著大資料分析的多元化,Hadoop並不能滿足新的需求,因此,針對Hadoop系統中的各種問題,柏克萊大學提出了全新統一的大數據處理架構Spark,創新的提出RDD概念,可視為MapReduce模型的擴充,可以實現在MapReduce不容易實現的計算工作,例如反覆運算、互動式和串流工作等 。
本課程將帶領學員了解大資料領域中Spark core 中最主要的RDD概念。以實作方式讓學員從無到有建置 Spark環境,並建立其叢集系統,獲得大資料處理的基礎能力,並進而了解各式Spark子系統的功用,並開發各式大資料分析的創新應用。

課程內容安排:   
01. Why Spark
02. Programming with RDD
03. Run on Cluster
04. Play with Spark Ecosystem

9
很感謝 交大資工提供社群共用空間
http://nctu330.kktix.cc/

讓社群可以有地方交流 :)

sakana 就貢獻一場 淺談 Ansible 自動化組態管理工具

報名網址
http://nctu330.kktix.cc/events/ansible-intro

活動議題:

      淺談 Ansible 自動化組態管理工具



議程簡介 :

     這次來淺談 ( 注意是淺談喔 ~ ) Ansible的相關議題.

Ansible 為目前 Configuration Management 四大金釵( Puppet / Salt / Chef / Ansible )之一.

希望利用2個小時的時間跟大家聊聊或是讓大家動手玩 Ansible ( 自己動手, 豐衣足食 ) ( 暫定, 主辦單位有更動內容的權力,  好像都是這樣寫 :p ) .

主要是希望有接觸資訊系統的人可以一起聊聊及討論了解相關想法.  ( 其實也不需要俱備先備知識 )



可能會聊聊下面的東西 ^^

     Ansible ? Why Ansible?

     預備知識

     安裝 Ansible

     The role of Ansible

     與 shell script 的差異??

     Hello Ansible!! 第一個 ansible 指令

     Inventory file / ansible.cfg 介紹

     Ansible Module 介紹與實作

     Playbook 介紹與實做

     Reference



     應用想法討論?

     也希望可以讓來參加的人一起聊聊 Ansible.

     希望大家輕鬆討論, 悠閒度過討論時光 ( 包含我自己 XD )

StudyArea酷學園
FB https://www.facebook.com/sataiwan/
討論區 http://phorum.study-area.org/
KKTIX 活動頁面 http://studyarea.kktix.cc/




講師: sakana  ( Max? )



講師簡介:

     Study-Area 酷學園 小雜工  / GNOME.Asia Committee Member / openSUSE Member

     喜歡社群自由無私的分享、熱愛自由軟體及 Linux 所帶來的方便性.



時間:

     2016年5月16日 (星期一)

     下午19:00~21:00

     時間規劃: 2 hr



地點:

     新竹交通大學工程三館330教室



費用: 免費(最貴)


活動報名網址:
   
http://nctu330.kktix.cc/events/ansible-intro

主辦單位:

     Study area酷!學園
     NCTU 330

11
原文連結 http://sakananote2.blogspot.tw/2016/03/docker-unstable-package-install-with.html

最近因為工作實驗環境需要, 需要安裝 docker 比較新的版本
寫了安裝小記還有 ansible playbook 檔案

OS: openSUSE Leap 42.1
套件安裝: docker 1.10.x 以上版本
(考慮實驗環境可能會測試 UCP 或是其他功能)

目前 docker 在 openSUSE Leap 42.1 官方版本為 1.9.x

套件版本查詢
之前進行套件查詢的時候都是使用 #zypper  search 套件名稱
為了有更多的資訊, 以後會多一些參數

代碼: [選擇]
# zypper   search   -s   --match-exact   docker
Loading repository data...
Reading installed packages...

S | Name   | Type       | Version    | Arch   | Repository               
--+--------+------------+------------+--------+--------------------------
  | docker | package    | 1.9.1-13.1 | x86_64 | openSUSE-Leap-42.1-Update
  | docker | package    | 1.9.1-10.1 | x86_64 | openSUSE-Leap-42.1-Update
  | docker | package    | 1.9.1-7.1  | x86_64 | openSUSE-Leap-42.1-Update
  | docker | package    | 1.9.0-4.1  | x86_64 | openSUSE-Leap-42.1-Update
  | docker | package    | 1.8.2-2.5  | x86_64 | openSUSE-Leap-42.1-Oss   

大概就是加上 -s 以及 --match-exact 這兩個 option
-s 顯示更多資訊, 但是沒有 -v 那麼多
--match-exact 符合後面字串的套件
感覺效果像 --match-words ^docker$

因為要安裝非穩定版本以及想要批次安裝

初步嘗試想法
*使用 OneClickInstallCLI 搭配 .ymp 方式來安裝
相關檔案如下
http://software.opensuse.org/ymp/Virtualization:containers/openSUSE_Leap_42.1/docker.ymp

但是目前 OneClickInstallCLI 不可以使用非互動方式安裝, 所以暫時作罷

目前作法
在 software.opensuse.org 搜尋 docker
http://software.opensuse.org/package/docker
點選 Virtualization:container

到專案頁面
點選 Repositories
看到 The repositories are inherited from the project Virtualization:containers.
點選 Virtualization:containers 專案 -- > 點選 Repositories

這邊可以找到各個版本的 repositories 下載


我用的是 Leap 42.1 所以 點選 openSUSE_Leap 42.1 的連結
http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1

這邊可以看到 .repo 檔案


連結為
http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1/Virtualization:containers.repo

透過 zypper 指令來新增 repo, 加入 key 以及設定 refresh

代碼: [選擇]
# zypper  --gpg-auto-import-keys   addrepo   -f http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1/Virtualization:containers.repo--gpg-auto-import-keys  是自動匯入 repo的 key
-f 為設定 auto refresh

透過 zypper repos 來查詢

代碼: [選擇]
# zypper   repos
#  | Alias                     | Name                                           | Enabled | GPG Check | Refresh
---+---------------------------+------------------------------------------------+---------+-----------+--------
 1 | Virtualization_containers | Virtualization:containers (openSUSE_Leap_42.1) | Yes     | ( p) Yes  | Yes   
 2 | openSUSE-42.1-0           | openSUSE-42.1-0                                | No      | ----      | No     

代碼: [選擇]
# zypper  -n  install  docker
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 7 NEW packages are going to be installed:
  bridge-utils docker docker-image-migrator git-core git-gui gitk perl-Error

The following recommended package was automatically selected:
  docker-image-migrator

7 new packages to install.
Overall download size: 12.9 MiB. Already cached: 0 B. After the operation, additional 59.4 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package docker-image-migrator-1.0.2-7.1.x86_64           
-n  新版的zypper 使用 -n / --non-interactive 來避免互動

接下來準備啟動服務

確認目前狀態
代碼: [選擇]
# systemctl   status  docker
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
   Active: inactive (dead)
     Docs: http://docs.docker.com

啟動 docker
代碼: [選擇]
# systemctl  start   docker
確認目前狀態
代碼: [選擇]
# systemctl  status docker
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled)
   Active: active (running) since Thu 2016-03-31 11:00:58 CST; 2s ago
     Docs: http://docs.docker.com
 Main PID: 32272 (docker)
   CGroup: /system.slice/docker.service
           └─32272 /usr/bin/docker daemon -H fd://

設定開機啟動

確認目前狀態
代碼: [選擇]
# systemctl  is-enabled  docker
disabled

設定開機啟動
代碼: [選擇]
# systemctl  enable  docker
確認目前狀態
代碼: [選擇]
# systemctl  is-enabled   docker
enabled

-------------------------------------------------

另外寫了 ansible 的 playbook .yml 來進行安裝
原始檔可以在這邊取得 https://github.com/sakanamax/LearnAnsible/blob/master/playbook/general/docker_unstable_openSUSELeap42.1_install.yml

檔案如下
# cat   docker_unstable_openSUSELeap42.1_install.yml
代碼: [選擇]
---
######################################################### 
# Install docker package and setup boot with unstable repo in openSUSE Leap 42.1
- name: use when conditionals and setup module (facts)
  hosts: all
  tasks:
# 使用 setup moudule 列出 OS 種類
    - name: use setup module to list os distribution
# setup moudle 可以使用 filter 過濾相關內容
      setup: filter=ansible_distribution

######################################################### 

- name: Install docker and run service
# use [dockerUnstable] group to install
  hosts: dockerUnstable
  sudo: True
  tasks:
# Add Virtualization:container project repo
    - name: Add Virutalization:containers repo
      shell: zypper  --gpg-auto-import-keys   addrepo   -f http://download.opensuse.org/repositories/Virtualization:/containers/openSUSE_Leap_42.1/Virtualization:containers.repo

    - name: Install docker with openSUSE Leap
      zypper: name={{ item }}
      with_items:
        - docker
        - curl
      when: ansible_distribution == "openSUSE Leap"

#------------------------------------------------------- 

    - name: Set docker enable and run
      service: name=docker state=started enabled=yes

12
好康報報 / SUSE Expert Day 2016 研討會
« 於: 2016-03-07 13:23 »
SUSE Expert Day 2016

2016年4月1日(星期五)
集思台大會議中心:蘇格拉底廳

主要會放在 SUSE 與 openstack / docker / ceph

會議資訊
http://www.bestcom.com.tw/content.aspx?RID=9406&CH_ID=579

報名網頁
https://events.suse.com/events/suse-expert-days-taipei/registration-3c9c9eed7726444c899cd6c5c99c8bb8.aspx

13
原文在 http://sakananote2.blogspot.com/2015/11/ansible-shell-module-apt-module.html

Ansible 的 Module 可以在官網找到所有的 Module, 這邊是按照分類的 Index http://docs.ansible.com/ansible/modules_by_category.html

 今天先來介紹兩個 module - shell 與 apt

 首先是 shell module

shell
* http://docs.ansible.com/ansible/shell_module.html
* 執行 shell, 適合執行多次處理
* 例如
* ansible  testserver  -m shell  -a  ' dpkg  -l  | grep nginx'     

 shell module 跟 command module 的差別就是可以處理 pipe 之類的做法
可以把在系統習慣的執行方式透過 shell module 來執行

 指令的做法
$ ansible  cenic_master -m shell   -a   'dpkg -l  |  grep ftp'
代碼: [選擇]
cenic_master | success | rc=0 >>
ii  ftp                                 0.17-28                             amd64        classical file transfer client

 範例
ansible-playbook 方式

 建立一個 yml 檔案
$ vi  test_shell_module.yml

代碼: [選擇]
- name: Test shell module
  hosts: cenic_master
  tasks:
    - name: Test shell module
      shell: dpkg -l | grep ftp
      register: dpkg
    - debug: var=dpkg.stdout_lines
 

以 ansible-playbook 指令執行
$ ansible-playbook test_shell_module.yml

代碼: [選擇]
PLAY [Test shell module] ******************************************************

 GATHERING FACTS ***************************************************************
ok: [cenic_master]

 TASK: [Test shell module] *****************************************************
changed: [cenic_master]

 TASK: [debug var=dpkg.stdout_lines] *******************************************
ok: [cenic_master] => {
    "var": {
        "dpkg.stdout_lines": [
            "ii  ftp                                 0.17-28                             amd64        classical file transfer client",
            "ii  lftp                                4.4.13-1                            amd64        Sophisticated command-line FTP/HTTP client programs",
            "ii  openssh-sftp-server                 1:6.6p1-2ubuntu2                    amd64        secure shell (SSH) sftp server module, for SFTP access from remote machines"
        ]
    }
}

 PLAY RECAP ********************************************************************
cenic_master               : ok=3    changed=1    unreachable=0    failed=0   

另外一個 module 就是 apt

apt
* http://docs.ansible.com/ansible/apt_module.html
* ubuntu 使用, 套件管理
* 要注意 update_cache=yes 使用, 來更新套件庫
* # 可以搭配 cache_valid_time=3600 來節省重複 update,

 指令的方式
例如 安裝 telnetd 套件
$ ansible cenic_master  -s   -m  apt  -a ' name=telnetd update_cache=yes '

這邊要注意兩件事情
* -s 代表 sudo , 因為要更新套件庫還有安裝, 所以需要 sudo
* apt 通常要搭配 update_cache=yes, 來更新, 以免套件安裝有問題

範例
ansible-playbook 方式

 建立一個 yml 檔案, 這邊我們透過 with_item 的方式一次安裝多個套件
$ vi  test_apt_module.yml

代碼: [選擇]
- name: Using Iteration (with_item) to install multiple packages
  hosts: cenic_master
#  sudo: True 這邊學到 sudo 不一定要放在一般選項內, 也可以放在 task 內
  tasks:
    - name: install apt packages
# 於 apt moudule 使用 sudo
      sudo: True
# 使用 pkg 加上 {{ item }} 配合後面的 with_item 來安裝多個套件
      apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
# 配合前面的 {{ item }} 來安裝多套件
      with_items:
        - openjdk-7-jdk
        - wget
        - scala

以 ansible-playbook 指令執行

 $ ansible-playbook  test_apt_module.yml

代碼: [選擇]
PLAY [Using Iteration (with_item) to install multiple packages] ***************

 GATHERING FACTS ***************************************************************
ok: [cenic_master]

 TASK: [install apt packages] **************************************************
changed: [cenic_master] => (item=openjdk-7-jdk,wget,scala)

 PLAY RECAP ********************************************************************
cenic_master               : ok=2    changed=1    unreachable=0    failed=0

okay, 今天先到這邊
~ enjoy it

14
原文在 http://sakananote2.blogspot.com/2015/11/ansible-ping-module-command-module.html

接下來就開始介紹 Ansible Module

 Ansible 的 Module 可以在官網找到所有的 Module, 這邊是按照分類的 Index http://docs.ansible.com/ansible/modules_by_category.html

 今天先來介紹兩個 module

 首先是 ping module
ping

這大概是我在使用 Ansible 第一個會執行的 module, 測試與遠端主機是否有連線成功

 使用 ansible 的指令語法就是
ansible  對象  -m  module名稱
  • -m 是 moudle 的意思

範例為對所有的主機執行 ping module, 成功就會回覆 pong
$ ansible  all   -m   ping
cenic_slave | success >> {
    "changed": false,
    "ping": "pong"
}


接下來介紹  command module
command module 適合執行單一指令, 沒有做其他處理的狀況

 command
  • http://docs.ansible.com/ansible/command_module.html
  • 執行 command, 但是如果是會用到 pipe | 這樣的方式就要透過 shell module 來執行
    • 例如
      • ansible  testserver  -m command  -a  'uptime'
    • 但是如果要執行指令進行二次處理
      • ansible  testserver  -m  command  -a  'dpkg -l | grep nginx'   這樣是不行的, 要使用 shell module

範例
ansible 指令方式

 ansible  對象  -m  module名稱  -a  “參數”
  • -m 是 module 的意思
  • -a  是 module arguments

所以這邊對機器執行 command module 去執行 uptime 指令
$ ansible  cenic_master   -m   command   -a   'uptime'
cenic_master | success | rc=0 >>
 06:38:13 up 20 days,  2:08,  2 users,  load average: 0.00, 0.01, 0.05

 範例
ansible-playbook 方式

 建立一個 yml 檔案, debug 的部分日後再講
$ vi  4_output_of_command.yml
代碼: [選擇]
- name: show return value of command module
  hosts: testserver
  tasks:
    - name: capture output of id command
      command: id -un
      register: login
# 使用 變數 {{ xxx.stdout }} 將輸入導到螢幕前
# - debug 後面的 msg 也是有規定名稱, 不能用自定命名
    - debug: msg="Logged in as user {{ login.stdout }}"

使用 ansible-playbook 指令執行

 使用 ansible 的指令語法就是

 ansible-playbook  指定的yml檔案

 $ ansible-playbook  4_output_of_command.yml

 PLAY [show return value of command module] ************************************

 GATHERING FACTS ***************************************************************
ok: [cenic_master]

 TASK: [capture output of id command] ******************************************
changed: [cenic_master]

 TASK: [debug msg="Logged in as user {{ login.stdout }}"] **********************
ok: [cenic_master] => {
    "msg": "Logged in as user maxhuang"
}

 PLAY RECAP ********************************************************************
cenic_master               : ok=3    changed=1    unreachable=0    failed=0   

 okay, 今天先到這邊

~ enjoy it

15
原文在這邊 http://sakananote2.blogspot.tw/2015/11/ansible-playbook-nginx.html

上次介紹 playbook
接下來要在沒有很了解 playbook 以及 module 的情況下, 來實驗書上的第一個 playbook - nginx 安裝.

接下來的筆記就會規劃 不同 module 的指令還有 playbook 的實作

Lab: 安裝 nginx without TLS

在 playbook 目錄下
$ vi   web-notls.yml
代碼: [選擇]
- name: Configure webserver with nginx
  hosts: webservers
  sudo: True
  tasks:
    - name: install nginx
      apt: name=nginx update_cache=yes

     - name: copy nginx config file
      copy: src=files/nginx.conf  dest=/etc/nginx/sites-available/default

     - name: enable configuration
      file: >
        dest=/etc/nginx/sites-enabled/default
        src=/etc/nginx/sites-available/default
        state=link

     - name: copy index.html
      template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html
        mode=0644

     - name: restart nginx
      service: name=nginx state=restarted


建立 預設的 conf 檔案( 對應上方的設定 )
在 playbook 目錄下
$ mkdir  files

 建立設定檔
$ vi  files/nginx.conf
代碼: [選擇]
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

         root /usr/share/nginx/html;
        index index.html index.htm;

         server_name localhost;

         location / {
                 try_files $uri $uri/ =404;
        }
}

建立 templates 目錄
在 playbook 目錄下
$ mkdir  templates

 建立首頁的範本
$ vi   templates/index.html.j2
代碼: [選擇]
<html>
 <head>
    <title>Welcome to ansible</title>
 </head>
 <body>
 <h1>nginx, configured by Ansible</h1>
 <p>If you can see this, Ansible successfully installed nginx.</p>

  <p>{{ ansible_managed }}</p>
 </body>
</html>

修改 hosts 檔案( 因為上面的 web-notls.yml 對象是 webservers 群組  )
在 playbook 目錄下
新增 webservers 群組
$ vi  hosts
代碼: [選擇]
ubuntu_utah ansible_ssh_host=pcvm2-13.utah.geniracks.net

 ubuntu_cenic ansible_ssh_host=pcvm2-28.instageni.cenic.net

 [geni]
ubuntu_utah
ubuntu_cenic

 [webservers]
ubuntu_utah

測試群組
$ ansible   webservers   -m ping
ubuntu_utah | success >> {
    "changed": false,
    "ping": "pong"
}



觀察目前目錄下物件
$ ls -R
ansible.cfg   files         hosts         templates     web-notls.yml

 ./files:
nginx.conf

 ./templates:
index.html.j2

 執行  playbook

$ ansible-playbook   web-notls.yml

驗證 webservers 主機的 port 80

成功之後來進行另外一個 Lab

Lab: 使用 TLS support 的 nginx

在 playbooks 目錄下
$ vi   web-tls.yml
代碼: [選擇]
- name: Configure webserver with nginx and tls
  hosts: webservers
  sudo: True
  vars:
    key_file: /etc/nginx/ssl/nginx.key
    cert_file: /etc/nginx/ssl/nginx.crt
    conf_file: /etc/nginx/sites-available/default
    server_name: localhost
  tasks:
    - name: Install nginx
      apt: name=nginx update_cache=yes cache_valid_time=3600

    - name: create directories for ssl certificates
      file: path=/etc/nginx/ssl state=directory

    - name: copy TLS key
      copy: src=files/nginx.key dest={{ key_file }} owner=root mode=0600
      notify: restart nginx

    - name: copy TLS certificate
      copy: src=files/nginx.crt dest={{ cert_file }}
      notify: restart nginx

    - name: copy nginx config file
      template: src=templates/nginx.conf.j2 dest={{ conf_file }}
      notify: restart nginx

    - name: enable configuration
      file: dest=/etc/nginx/sites-enabled/default src={{ conf_file }} state=link
      notify: restart nginx

    - name: copy index.html
      template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html mode=0644

  handlers:
    - name: restart nginx
      service: name=nginx state=restarted

手動建立憑證
在 playbooks 目錄下
使用 openssl 指令建立憑證
$ openssl  req  -x509  -nodes  -days 3650 -newkey rsa:2048 -subj /CN=localhost -keyout files/nginx.key -out files/nginx.crt
Generating a 2048 bit RSA private key
........................................+++
...............................................+++
writing new private key to 'files/nginx.key'
-----

驗證輸出
$ ls   files/
nginx.conf nginx.crt  nginx.key

建立 nginx.conf.j2  給支援 tls 設定檔使用 ( 跟沒有 TLS 的差異為紅色部分 )

在 playbooks 目錄下

$ vi  templatess/nginx.conf.j2
代碼: [選擇]
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        listen 443 ssl;

        root /usr/share/nginx/html;
        index index.html index.htm;

        server_name {{ server_name }};
        ssl_certificate {{ cert_file }};
        ssl_certificate_key {{ key_file }};

        location / {
                 try_files $uri $uri/ =404;
        }
}

使用之前已經安裝過的主機測試  playbook
$ ansible-playbook   web-tls.yml
PLAY [Configure webserver with nginx and tls] *********************************

GATHERING FACTS ***************************************************************
ok: [ubuntu_utah]

TASK: [Install nginx] *********************************************************
ok: [ubuntu_utah]

TASK: [create directories for ssl certificates] *******************************
ok: [ubuntu_utah]

TASK: [copy TLS key] **********************************************************
ok: [ubuntu_utah]

TASK: [copy TLS certificate] **************************************************
ok: [ubuntu_utah]

TASK: [copy nginx config file] ************************************************
changed: [ubuntu_utah]

TASK: [enable configuration] **************************************************
ok: [ubuntu_utah]

TASK: [copy index.html] *******************************************************
changed: [ubuntu_utah]

NOTIFIED: [restart nginx] *****************************************************
changed: [ubuntu_utah]

PLAY RECAP ********************************************************************
ubuntu_utah                : ok=9    changed=3    unreachable=0    failed=0

測試完全新的 ubuntu_cenic 也okay

今天先到這邊

~ enjoy it

16
原文 http://sakananote2.blogspot.com/2015/10/ansible-ansible.html


記錄一下相關練習

以下的練習,  前提是

    SSH 可以使用 Key 登入 Remote Hosts


例如 在 Control Machine 上面( Mac / Linux )

$ ssh  -l   使用者名稱   -i   key檔案位置  RemoteHost_IP
可以直接登入

SSH 建立以及複製到遠端可以參考 這篇

建立 playbooks  目錄來進行之後練習

$ mkdir   playbooks

Lab:  簡單的 ansible 指令練習

建立遠端主機相關資訊
$ vi  hosts
代碼: [選擇]
# syntax: servername  options
# ansible_ssh_host -- Remote Host IP
# ansible_ssh_user -- Remote SSH User Name
# ansible_ssh_private_key_file -- SSH Key
testserver   ansible_ssh_host=遠端主機IP   ansible_ssh_user=遠端使用者名稱


測試 ansible 指令, 這邊使用 ping 的 module
可以參考 http://docs.ansible.com/ansible/ping_module.html

$ ansible   testserver   -i   hosts   -m   ping
testserver | success >> {
    "changed": false,
    "ping": "pong"
}

$ ansible   all   -i   hosts   -m   ping
testserver | success >> {
    "changed": false,
    "ping": "pong"
}


根據上面的指令來驗證
ansible

    可以指定某台主機, 例如 testserver 或是全部 all
    -i 為 inventory 清單檔案所在
    -m 為 module name, 這個案例使用的是 ping



但是如果每台主機的使用者帳號還有 key 都是同一把, 那就可以建立 ansible.cfg 來設定成預設

Lab: 使用 ansible.cfg

建立 ansible.cfg 放在 playbook 目錄下
$ vi   ~/playbooks/ansible.cfg
代碼: [選擇]
[defaults]
# 主機清單的檔案, 這樣可以不用下 -i 選項指定
hostfile = hosts
# 遠端使用者名稱, 換成自己的使用者名稱
remote_user = cc
# SSH Key 位置, 換成自己的 key path
private_key_file = ~/.ssh/id_dsa

修改  ~/playbooks/hosts ( 因為 ansible.cfg 已經有設定 remote_user, 就不用重複設定 )

$ vi   ~/playbooks/hosts
代碼: [選擇]
# syntax: servername  options
# ansible_ssh_host -- Remote Host IP
# ansible_ssh_user -- Remote SSH User Name
# testserver   ansible_ssh_host=遠端主機IP   ansible_ssh_user=遠端使用者名稱
testserver   ansible_ssh_host=遠端主機IP

$ ansible   testserver    -m ping
testserver | success >> {
    "changed": false,
    "ping": "pong"
}



但是如果對象是要用兩種以上的 ssh key 來控制, 那就可以考慮把相關的設定寫在 hosts, 並利用 群組的做法
$ cat   hosts
代碼: [選擇]
ubuntu_utah ansible_ssh_host=遠端主機IP ansible_ssh_user=maxhuang ansible_ssh_private_key_file=~/id_ssh_rsa

ubuntu_cenic ansible_ssh_host=遠端主機IP ansible_ssh_user=maxhuang ansible_ssh_private_key_file=~/id_ssh_rsa

[geni]
ubuntu_utah
ubuntu_cenic

接下來嘗試使用 ansible 來安裝套件

Lab: 安裝套件

查詢套件是否安裝, 這邊使用 shell module
可以參考 http://docs.ansible.com/ansible/shell_module.html

$ ansible  ubuntu_utah   -m   shell   -a   "dpkg -l | grep nginx"
ubuntu_utah | FAILED | rc=1 >>


安裝套件
$ ansible ubuntu_utah  -s -m apt -a 'name=nginx update_cache=yes'

確認是否安裝
$ ansible ubuntu_utah  -m  shell  -a  "dpkg -l | grep nginx"
ubuntu_utah | success | rc=0 >>
ii  nginx                               1.4.6-1ubuntu3.3                    all          small, powerful, scalable web/proxy server


今天就先到這邊

~ enjoy it

17
原文 http://sakananote2.blogspot.com/2015/10/ansible-install-with-opensuse-132-and.html

最近因為工作的關係開始接觸 Ansible

Ansible 是利用  SSH 來進行環境部署的工具, 以 python 為基礎, 其他常見的工具有 Puppet / Chef / Salt.


先把相關的資源整理上來 Online resource

    Documentation
        http://docs.ansible.com/
    Ansible module index
        http://docs.ansible.com/ansible/modules_by_category.html
    Ansible Galaxy
        https://galaxy.ansible.com/
        Repository of Ansible roles contributed by the community
    Ansible Project Google Group
        https://groups.google.com/forum/#!forum/ansible-project
        The place to go if you have any questions about Ansible
    IRC
        #ansible on irc.freenode.net 


目前研讀的是 Oreilly - Ansible up & running

    code example 在

       https://github.com/lorin/ansiblebook

     
看一些時間了, 雖然目前只有看完 Chapter 3 但是先整理一些資料出來

先來提 安裝 Ansible

安裝 Ansible

    http://docs.ansible.com/ansible/intro_installation.html
        Mac OS 我是利用 pip 安裝
            $ sudo easy_install pip
            $ sudo pip install ansible


openSUSE 13.2 的部分( 目前應該大部份的 linux 都可以直接安裝 ansible )
查詢套件
# zypper   search   ansible
Loading repository data...
Reading installed packages...

S | Name    | Summary                                                                  | Type     
--+---------+--------------------------------------------------------------------------+-----------
  | ansible | SSH-based configuration management, deployment, and orchestration engine | package   
  | ansible | SSH-based configuration management, deployment, and orchestration engine | srcpackage

安裝 Ansible
# zypper install  -y  ansible

這樣就大功告成了

真正要裝套件的只有  Control Machine, 被部署的機器是不用安裝套件的 ( Clientless ), 這點應該是與 puppet 或是其他的工具最大的差異.

所以主要的角色有

    控制端 The control machine
        The one that you use to control remote machines
        needs to have python 2.6 or later installed. 
    遠端機器 To manage a server with Ansible
        Needs to have SSH and Python 2.5 or later installed.

基本上目前大部份的 linux 都有 SSH 以及 python 2.5 以上 ( 我觀察是 2.7 ), 所以這也是說不用裝套件的原因

那要使用 Ansible 要有那些先備知識會比較好呢? ( 從書上整理來的 ^^ )
主要是 會使用 SSH 指令連接遠端的機器, 知道如何使用 ssh key 免密碼的方式連接遠端主機, 知道 sudo 是啥 ^^

What do I need to know?

        Connect to a remote machine using SSH.
        Interact with the bash command-line shell (pipes and redirection).
        Install packages.
        Use the sudo command.
        Check and set file permissions.
        Start and stop services.
        Set environment variables.
        Write scripts ( Any language )
    You don't need to know python to use Ansible unless you want to write your own module.
    You will need to learn some YAML and Jinja2 to use Ansible.     



今天就先這樣, 下次來整理簡單的 Ansible 指令

~ enjoy it

18
【 openSUSE.Asia Summit 2015 】報名開始!
openSUSE.Asia Summit 2015 來了!



活動於 10/23 12:00 開放報名
報名網址:
http://opensuse-tw.kktix.cc/events/oas15

openSUSE.Asia 峰會的目的是在亞洲地區推廣 Linux。今年將在台灣台北舉辦,酷!學園 (Study Area) 一個知名並深耕多年的台灣社群, 長期著眼於教育與推廣 Linux 應用環境及在電腦領域的各種用途. 已確定參與並共同主辦此峰會,而此合辦將拓展此峰會能涵蓋更多的 Linux 及開放原始碼軟體 (FOSS) 領域.



請喜愛 Linux / openSUSE 以及 Study-Area 的朋友們別錯過了!

精彩的議程都在
https://events.opensuse.org/conference/summitasia15/schedule

請注意我們今年把活動三天分為兩部分,

event days 和 workshop day.

12月4日是 workshop day
Workshop 1 - AutoYast and SUSE Studio / 私人定製:AutoYast 和 SUSE Studio
報名網址: http://opensuse-tw.kktix.cc/events/oas15-worshop1

Workshop 2 - Run virtual machine with libvirt on openSUSE - step by step
報名網址: http://opensuse-tw.kktix.cc/events/oas15-worshop2

12月5-6日是 event days
報名網址: http://opensuse-tw.kktix.cc/events/oas15

兩邊的票卷不相通,報名的時候要注意喔!都要報名喔 ^^

19
圖文並茂版在這邊 http://sakananote2.blogspot.tw/2015/10/nagios-with-opensuse-131-management.html


目的: 監控 目前專案還有自己的設備



主要監控伺服器的 Management Port, 適用於財產保管人是自己, 但是系統是別的同事維運
另外透過建立 switch 以及設定 parent ( 父物件 ), 讓網路 map 更清楚

OS: openSUSE 13.1

 # zypper   install   nagios   nagios-plugins

 # htpasswd2   -c   /etc/nagios/htpasswd.users   nagiosadmin

 # chkconfig  nagios  --list
# chkconfig  nagios  on
# chkconfig  nagios  --list

 重新啟動.apache2 並設定開機啟動
#rcapache2  restart
#rcapache2  status
#systemctl    is-enabled   apache2.service
#systemctl    enable   apache2.service   
#systemctl    is-enabled   apache2.service

 6.啟動Nagios
#rcnagios   start

 #yast2 firewall
開啟 http 服務

 #vi   /etc/nagios/objects/localhost.cfg
註解 HTTP, linux-servers 群組 以及調整 Total Process
代碼: [選擇]
# 2014/1/8 edit by sakana, temp disable HTTP monitor
#define service{
#        use         local-service         ; Name of service template to use
#        host_name                       localhost
#        service_description             HTTP
#       check_command                   check_http
#       notifications_enabled           0
#        }

 # Define an optional hostgroup for Linux machines
#
#define hostgroup{
#        hostgroup_name  linux-servers ; The name of the hostgroup
#        alias           Linux Servers ; Long name of the group
#        members         localhost     ; Comma separated list of hosts that belong to this group
#        }


# 2014/1/8 edit by sakana change check_local_procs from 250 to 400, 400 to 800
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Total Processes
        check_command                   check_local_procs!400!800!RSZDT
        }

 解除http警告狀態

 檢視 Nagios 設定有沒有問題
#nagios  -v   /etc/nagios/nagios.cfg

 重新啟動 Nagios
#rcnagios   restart

 安裝 nagios-nrpe 套件
#yast  -i  nagios-nrpe  nagios-plugins-nrpe

 下載之前自己建立的範本檔案 ( 中心firewall有擋, 我是用 scp 過去的  )
#wget  https://dl.dropboxusercontent.com/u/12787647/20131227nagios/server-templates20131227.cfg

 覆蓋且移動原來的設定檔
# mv   server-templates20131227.cfg    /etc/nagios/objects/templates.cfg
 
( 中心firewall有擋, 我是用 scp 過去的  )
#wget   https://dl.dropboxusercontent.com/u/12787647/20131227nagios/server-commands.cfg

 覆蓋且移動原來的設定檔
# mv   server-commands.cfg   /etc/nagios/objects/commands.cfg
建立之後存放 Server 與 一般工作站的設定檔目錄
#mkdir   /etc/nagios/servers
#mkdir   /etc/nagios/pcs
#mkdir   /etc/nagios/racks

 取得事先寫好的 linuxPublic.cfg 複製給公用服務使用並複製到 /etc/nagios/servers目錄

 ( 中心firewall有擋, 我是用 scp 過去的  )
# wget   https://dl.dropboxusercontent.com/u/12787647/20140811Nagios/linuxPublic.cfg
#mv   linuxPublic.cfg   /etc/nagios/objects/

 修改 /etc/nagios/nagios.cfg 內的設定 讓 *.cfg 設定載入, 可以監控nagios Clinet

 #vi   /etc/nagios/nagios.cfg
加入
代碼: [選擇]
cfg_dir=/etc/nagios/servers
cfg_dir=/etc/nagios/pcs
cfg_dir=/etc/nagios/racks

 註解 /etc/nagios/objects/windows.cfg 內的 windows-servers, 因為已經定義到  templates.cfg

 # vi   /etc/nagios/objects/windows.cfg
代碼: [選擇]
#define hostgroup{
#        hostgroup_name  windows-servers ; The name of the hostgroup
#       alias           Windows Servers ; Long name of the group
#        }

 修改 templates.cfg 加入 rack-host 主機範本以及群組
# vi   /etc/nagios/objects/templates.cfg


代碼: [選擇]
# Rack host definition template - This is NOT a real host, just a template!
# 這個host 範本是為了只想監控實體主機 管理IP, 但是系統管理人不是自己的template
define host{
        name                            rack-host       ; The name of this host template
        use                             generic-host    ; This template inherits other values from the generic-host template
        check_period                    24x7            ; By default, Linux hosts are checked round the clock
        check_interval                  5               ; Actively check the host every 5 minutes
        retry_interval                  1               ; Schedule host check retries at 1 minute intervals
        max_check_attempts              10              ; Check each Linux host 10 times (max)
        check_command                   check-host-alive ; Default command to check Linux hosts
        notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day
                                                        ; Note that the notification_period variable is being overridden from
                                                        ; the value that is inherited from the generic-host template!
        notification_interval           120             ; Resend notifications every 2 hours
        notification_options            d,u,r           ; Only send notifications for specific host states
        contact_groups                  admins          ; Notifications get sent to the admins by default
        hostgroups                      rack-group      ; Host groups that Rack server should be a member of 這邊是額外加入
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

 # 這一段是新增的區段, 為了Rack Host 群組 而設定---- start-------------------------------------------------------------

 # Define host group for Rack hosts
define hostgroup{
        hostgroup_name  rack-group      ; The name of the hostgroup
        alias           Rack Hosts Group      ; Long name of the group
        }

 # 這一段是新增的區段, 為了Rack Host 群組 而設定---- end  -------------------------------------------------------------

複製範本檔案來修改為 rackHost.cfg
# cp  /etc/nagios/objects/linuxPublic.cfg   /etc/nagios/objects/rackHost.cfg

 修改檔案內容
# vi  /etc/nagios/objects/rackHost.cfg
註解所有的 service
修改 套用的範本
代碼: [選擇]
define host{
        use             rack-host       ; Inherit default values from a template 這邊要參照/etc/nagios/objects/templates.cfg 內的名稱
        host_name       S_b11_9U        ; The name we're giving to this host 主機名稱(簡稱)(機房位置_機櫃位置_起始U數)
        alias           B11 Rack at 9 ~ 10U; A longer name associated with the host 主機名稱(長)
        address         192.168.1.3     ; IP address of the host 這邊請修改為實際上的IP
        }


複製範本檔案來建立我們想監控的機器(請自行命名 xxx.cfg)
# cp  /etc/nagios/objects/rackHost.cfg   /etc/nagios/racks/S_C13_12U.cfg

 修改
# vi  /etc/nagios/racks/S_C13_12U.cfg

 修改主機名稱對應實際狀況
修改  address 後面的IP, 對應到可以存取的 IP

 address     x.y.z.w

 檢視 Nagios 設定有沒有問題
#nagios  -v   /etc/nagios/nagios.cfg

 這邊可能會有警告, 因為 rack 主機我們只檢查主機不檢查服務

 重新啟動 Nagios
#rcnagios   restart

 ** Nagios Map icon **

 直接使用預設的 icon ( /usr/share/nagios/images/logos 下 )

 修改 templates.cfg
# vi   /etc/nagios/objects/templates.cfg
加入 icon 相關設定, rack-host 比照辦理
代碼: [選擇]
define host{
        name                            linux-server    ; The name of this host template
        use                             generic-host    ; This template inherits other values from the generic-host template
        check_period                    24x7            ; By default, Linux hosts are checked round the clock
        check_interval                  5               ; Actively check the host every 5 minutes
        retry_interval                  1               ; Schedule host check retries at 1 minute intervals
        max_check_attempts              10              ; Check each Linux host 10 times (max)
        check_command                   check-host-alive ; Default command to check Linux hosts
        notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day
                                                        ; Note that the notification_period variable is being overridden from
                                                        ; the value that is inherited from the generic-host template!
        notification_interval           120             ; Resend notifications every 2 hours
        notification_options            d,u,r           ; Only send notifications for specific host states
        contact_groups                  admins          ; Notifications get sent to the admins by default
        hostgroups                      linux-servergroup ; Host groups that Linux servers should be a member of
        icon_image                      linux40.gif
        icon_image                      linux
        statusmap_image                 linux40.gd2
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

 ** switch **
目前還沒有碰 snmp, switch 也不想弄得太麻煩, 只是想在 map 上顯示階層

 複製原來的範本來修改, 只想知道 switch 有沒有活著
# cp  /etc/nagios/objects/switch.cfg   /etc/nagios/objects/switchSimple.cfg

 # vi   /etc/nagios/objects/switchSimple.cfg
註解所有服務
註解 switches 群組, 準備放 templates.cfg
修改主機設定, 自動加入 switch-group 群組
代碼: [選擇]
#define hostgroup{
#       hostgroup_name  switches                ; The name of the hostgroup
#       alias           Network Switches        ; Long name of the group
#       }

 define host{
        use             generic-switch          ; Inherit default values from a template
        host_name       linksys-srw224p         ; The name we're giving to this switch(機房位置_機櫃位置_起始U數)
        alias           Linksys SRW224P Switch  ; A longer name associated with the switch
        address         192.168.1.253           ; IP address of the switch
        hostgroups      switch-group            ; Host groups this switch is associated with
        }


#vi   /etc/nagios/objects/templates.cfg
加入 switch-group 群組
代碼: [選擇]
# 這一段是新增的區段, 為了switch 群組 而設定---- start-------------------------------------------------------------

 define hostgroup{
       hostgroup_name  switch-group               ; The name of the hostgroup
       alias           Network Switches        ; Long name of the group
       }

 # 這一段是新增的區段, 為了switch 群組 而設定---- end  -------------------------------------------------------------
建立資料夾
# mkdir  /etc/nagios/switches

 # vi   /etc/nagios/nagios.cfg
加入
代碼: [選擇]
cfg_dir=/etc/nagios/switches
 複製範本 到 switch 目錄
# cp  /etc/nagios/objects/switchSimple.cfg   /etc/nagios/switches/S_B11_32U.cfg

 # vi  /etc/nagios/switches/S_B11_32U.cfg
修改 主機名稱, address
代碼: [選擇]
define host{
        use             generic-switch          ; Inherit default values from a template
        host_name       S_B11_32U               ; The name we're giving to this switch(機房位置_機櫃位置_起始U數)
        alias           Sinchu B11 32U - Cisco Catalyst 2960x   ; A longer name associated with the switch
        address         192.168.1.124           ; IP address of the switch
        hostgroups      switch-group            ; Host groups this switch is associated with
        }

 接下來修改 rack 設定檔
在 host  設定 加上 parents 設定父物件
例如
define host{
        use             rack-host       ; Inherit default values from a template 這邊要參照/etc/nagios/objects/templates.cfg 內的名稱
        host_name       S_B11_11U       ; The name we're giving to this host 主機名稱(簡稱)(機房位置_機櫃位置_起始U數)
        alias           Shinchu B11 11U - Cisco UCS C220M4; A longer name associated with the host 主機名稱(長)
        address         192.168.1.111   ; IP address of the host 這邊請修改為實際上的IP
        parents         S_B11_32U
        }

 成果如下


20
原Blog URL
http://sakananote2.blogspot.tw/2015/09/docker-with-opensuse-132_3.html


docker with openSUSE 13.2 小記 - 映像檔管理

 今天持續練習 docker with openSUSE 13.2

 昨天有注意到使用者要加入到 docker 的群組, 如果沒有加入到 docker 群組會發生哪些影響呢?

 首先觀察群組, 目前沒有被加入 docker 群組
> id
uid=1000(max) gid=100(users) groups=100(users)

 嘗試以 max 身份列出 image
> docker   images
Get http:///var/run/docker.sock/v1.19/images/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?

 當然是可以用 sudo 來進行啦.... ( 但是你就會被問 root’s password )

 > sudo  docker  images
root's password:
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               57bca5139a13        12 days ago         134.8 MB
opensuse            latest              d6b241b32a2d        5 weeks ago         93.99 MB

 還沒加入使用者之前觀察一下 docker 群組
> sudo   grep   docker    /etc/group
docker:x:482:

 利用  gpasswd 加入 max 到  docker 群組 ( 下次登入才生效 )
> sudo    gpasswd    -a   max   docker
正在將使用者“max”加入到“docker”群組中

 再次觀察 docker 群組
> sudo   grep   docker    /etc/group
docker:x:482:max

 登出 shell
>exit

 重新登入 shell
> id
uid=1000(max) gid=100(users) groups=100(users),482(docker)

 再次執行 docker images 觀察
> docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               57bca5139a13        12 days ago         134.8 MB
opensuse            latest              d6b241b32a2d        5 weeks ago         93.99 MB

 所以小結就是非 root 使用者要直接使用 docker 指令就要加入 docker 群組 ^^

 映像檔管理

 練習教材裏面,  提到映像檔管理,  但是有些內容沒有進一步解釋, 所以就上去找了一下官方文件

 官方文件 Docker user guide
https://docs.docker.com/userguide/

 首先對之前下的指令進行解釋
> sudo   docker   run   --rm   -i   -t   opensuse   /bin/bash
run 執行 docker
--rm   Automatically remove the container when it exits
-i   Keep STDIN open even if not attached
-t  Allocate a pseudo-TTY

 可以使用 >docker  run  --help 來查詢

 不過正確來說應該要連同 TAG 一起下才是正確的( 如果沒有指定 TAG, 預設為 latest )
> docker   run   -i   -t   --rm   opensuse:latest   /bin/bash

 查詢映像檔

 方式 1 上網搜尋
https://hub.docker.com/
例如 搜尋 opensuse


點進想抓的Repositories
這邊可以看到 docker pull 指令還有 Dockerfile 相關資訊



 方式 2 使用指令
使用 docker  search 來搜尋
> docker  search  opensuse
NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
opensuse                             This project contains the stable releases ...   49        [OK]       
hachque/opensuse                     A base openSUSE 13.1 image, built from Sus...   2                   
druonysus/opensuse-base-minion                                                       2                    [OK]
novacoast/opensuse-apache                                                            2                    [OK]


取得映像檔到本機
使用 指令還有 Web 方式的差異是
在 Web 上面, 我們可以看到 images的 TAG, 但是 指令沒有看到

 練習取得映像檔

 > docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               57bca5139a13        13 days ago         134.8 MB
opensuse            latest              d6b241b32a2d        5 weeks ago         93.99 MB

 使用  docker  pull 來下載 image
> docker  pull  opensuse:13.2
13.2: Pulling from opensuse

 5b8dd08af89b: Already exists
d6b241b32a2d: Already exists
Digest: sha256:b9ebaf54a450bcd400bcafea93b53aa3debcc787df7805a5a7e2d0db3457163f
Status: Downloaded newer image for opensuse:13.2

 利用 docker images 來比對, 比對 IMAGE ID 就會知道 latest 與 13.2 是相同的
> docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               57bca5139a13        13 days ago         134.8 MB
opensuse            latest              d6b241b32a2d        5 weeks ago         93.99 MB
opensuse            13.2                d6b241b32a2d        5 weeks ago         93.99 MB

 接下來的練習配合 docker 官方文件

 建立 docker 映像檔

 方式 1 修改現有的映像檔

 下載 training/sinatra Repository映像檔 ( 可以注意到下載了所有 TAG 的映像檔, 從 training/sinatra )

 > docker   pull   training/sinatra
Pulling repository training/sinatra
f0f4ab557f95: Download complete
511136ea3c5a: Download complete
3e76c0a80540: Download complete
be88c4c27e80: Download complete
bfab314f3b76: Download complete
e809f156dc98: Download complete
ce80548340bb: Download complete
79e6bf39f993: Download complete
Status: Downloaded newer image for training/sinatra:latest

 觀察 images
> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               57bca5139a13        13 days ago         134.8 MB
opensuse            13.2                d6b241b32a2d        5 weeks ago         93.99 MB
opensuse            latest              d6b241b32a2d        5 weeks ago         93.99 MB
training/sinatra    latest              f0f4ab557f95        15 months ago       447 MB


執行之前先列出目前執行的 Container
docker  ps 可以列出 container
-a 是列出所有的 container
如果沒有加上 -a 則是列出目前有執行指令的 container

 > docker  ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 > docker  ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 執行 docker image 到  container ( 這次不加上 --rm, 也就是說 exit 之後不刪除 )

 > docker    run    -i    -t    training/sinatra  /bin/bash
root@6764848c94c4:/#

 輸入 exit 離開 container
root@6764848c94c4:/# exit
exit

 再次觀察 container
> docker  ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 > docker  ps  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
6764848c94c4        training/sinatra    "/bin/bash"         2 minutes ago       Exited (0) 36 seconds ago                       elegant_lalande     

 跟上面比對就會發現, 剛剛登入 shell 的時候 root@後面那串就是 container ID

 再次執行一個新的 container

 > docker  run  -i  -t  training/sinatra  /bin/bash
root@ddc3cdc142f3:/#

 這邊就會發現 container ID 是不一樣, 因為是另外一個

 我們基於這個來修改成我們的映像檔
安裝 json 套件來作出差異
root@ddc3cdc142f3:/# gem  install json
Fetching: json-1.8.3.gem (100%)
Building native extensions.  This could take a while...
Successfully installed json-1.8.3
1 gem installed
Installing ri documentation for json-1.8.3...
Installing RDoc documentation for json-1.8.3...

 離開 container
root@ddc3cdc142f3:/# exit
exit

 這樣這個映像檔就跟之前不一樣了
接下來透過 docker  commit 來建立新的


> docker   commit   -m "Add json"  -a "sakana"   ddc3cdc142f3    testrepo/testimage:vTEST
220501802d62b8aca6ed82aad9ea99c2dc9a12d195638b6bdf47f20aa8e92860

 commit   提交一個新的 image
-m 訊息Commit message
-a  作者 Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
ddc3cdc142f3 是container ID
testrepo/testimage:vTEST 是 Repository名稱/映像檔名稱:TAG

 觀察 images
> docker   images
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
testrepo/testimage   vTEST               220501802d62        5 minutes ago       452.1 MB
ubuntu               12.04               57bca5139a13        13 days ago         134.8 MB
opensuse             13.2                d6b241b32a2d        5 weeks ago         93.99 MB
opensuse             latest              d6b241b32a2d        5 weeks ago         93.99 MB
training/sinatra     latest              f0f4ab557f95        15 months ago       447 MB

 這個時候就會知道, 如果我們日後不上傳到 Docker Hub, 其實 Repository名稱是可以自己取的, 沒有影響, 但是如果要上傳, 就是要註冊 Docker Hub的帳號, 符合上面的規則才可以.

 嘗試使用剛剛建立的映像檔來執行

 > docker  run  -t  -i  testrepo/testimage:vTEST   /bin/bash
root@acfed6e70946:/#

 輸入 exit 離開

 root@acfed6e70946:/# exit
exit


方式 2 使用 Dockerfile 建立映像檔

 我們可以透過 docker  build 配合 Dockerfile 來建立映像檔


首先觀察目前的路徑
> pwd
/home/max

 建立目錄
> mkdir  sakana

 進入該目錄
> cd   sakana/

 建立 Dockerfile
> vi   Dockerfile
# 用於註解
# 後續的流程, 前面都要大寫
# FROM 基於那個 image
FROM ubuntu:14.04
# MAINTAINER 維護作者
MAINTAINER Max Huang < sakana@study-area.org >
# RUN 要執行的指令
RUN apt-get update && apt-get install -y ruby ruby-dev
RUN gem install sinatra

 > docker    build    -t    sakanatest/testimage    /home/max/sakana
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:14.04
14.04: Pulling from ubuntu

 d3a1f33e8a5a: Pull complete
c22013c84729: Pull complete
d74508fb6632: Pull complete
91e54dfb1179: Already exists
ubuntu:14.04: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.

 Digest: sha256:7a846cdca616c384ac1c5e3a91d0ea22c89a5c456f60d4d60734715c4e2df9ae
Status: Downloaded newer image for ubuntu:14.04
 ---> 91e54dfb1179
Step 1 : MAINTAINER Max Huang < sakana@study-area.org >
 ---> Running in b59ea0a80376
 ---> adbe1f761471
Removing intermediate container b59ea0a80376
Step 2 : RUN apt-get update && apt-get install -y ruby ruby-dev
Removing intermediate container 833999aeaa6a
Successfully built dd38d73f4e20

 -t 是 tag 後面為 repository名稱/image名稱
路徑為 Dockerfile 所在目錄, 跟他上層目錄叫啥名字沒有關係....

 > docker  images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sakanatest/testimage   latest              dd38d73f4e20        2 minutes ago       318.7 MB
testrepo/testimage     vTEST               220501802d62        37 minutes ago      452.1 MB
ubuntu                 14.04               91e54dfb1179        13 days ago         188.3 MB
ubuntu                 12.04               57bca5139a13        13 days ago         134.8 MB
opensuse               13.2                d6b241b32a2d        5 weeks ago         93.99 MB
opensuse               latest              d6b241b32a2d        5 weeks ago         93.99 MB
training/sinatra       latest              f0f4ab557f95        15 months ago       447 MB

 可以觀察 image ID

 官方文件有提到其他 Dockerfile 的做法( ADD / EXPOSE / CMD ), 但是後面還會提到就先不說

 設定映像檔 TAG

 可以透過  docker tag 來設定 映像檔的 TAG

 > docker  images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sakanatest/testimage   latest              dd38d73f4e20        2 minutes ago       318.7 MB
testrepo/testimage     vTEST               220501802d62        37 minutes ago      452.1 MB
ubuntu                 14.04               91e54dfb1179        13 days ago         188.3 MB
ubuntu                 12.04               57bca5139a13        13 days ago         134.8 MB
opensuse               13.2                d6b241b32a2d        5 weeks ago         93.99 MB
opensuse               latest              d6b241b32a2d        5 weeks ago         93.99 MB
training/sinatra       latest              f0f4ab557f95        15 months ago       447 MB

 > docker    tag    dd38d73f4e20    sakanatest/testimage:tagTest

 > docker  images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sakanatest/testimage   latest              dd38d73f4e20        8 minutes ago       318.7 MB
sakanatest/testimage   tagTest             dd38d73f4e20        8 minutes ago       318.7 MB
testrepo/testimage     vTEST               220501802d62        43 minutes ago      452.1 MB
ubuntu                 14.04               91e54dfb1179        13 days ago         188.3 MB
ubuntu                 12.04               57bca5139a13        13 days ago         134.8 MB
opensuse               13.2                d6b241b32a2d        5 weeks ago         93.99 MB
opensuse               latest              d6b241b32a2d        5 weeks ago         93.99 MB
training/sinatra       latest              f0f4ab557f95        15 months ago       447 MB


上傳映像檔到 Docker Hub

 由於使用 docker  push 上傳要註冊帳號, 所以就先不做



移除映像檔

 如果要移除映像檔, 必須沒有作用中的 container 才可以移除

 先觀察 container
> docker    ps     -a
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS                         PORTS               NAMES
acfed6e70946        testrepo/testimage:vTEST   "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       furious_pare       
ddc3cdc142f3        training/sinatra           "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       serene_tesla       
6764848c94c4        training/sinatra           "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       elegant_lalande   

 觀察映像檔
這邊可以觀察到 sakanatest/testimage 沒有container使用中
testrepo/testimage 以及 trainging/sinatra 有 container 使用中

 > docker    images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
sakanatest/testimage   latest              dd38d73f4e20        About an hour ago   318.7 MB
sakanatest/testimage   tagTest             dd38d73f4e20        About an hour ago   318.7 MB
testrepo/testimage     vTEST               220501802d62        About an hour ago   452.1 MB
ubuntu                 14.04               91e54dfb1179        13 days ago         188.3 MB
ubuntu                 12.04               57bca5139a13        13 days ago         134.8 MB
opensuse               13.2                d6b241b32a2d        5 weeks ago         93.99 MB
opensuse               latest              d6b241b32a2d        5 weeks ago         93.99 MB
training/sinatra       latest              f0f4ab557f95        15 months ago       447 MB


我們可以使用 docker  rmi 來移除 沒有 container 使用中的 image

 首先針對沒有 container 運作的  sakanatest/testimage 來刪除
> docker   rmi   sakanatest/testimage:tagTest
Untagged: sakanatest/testimage:tagTest
Deleted: dd38d73f4e2021c81c52530e99eb1cb98f87b9031d50c6342e7d47b8302f78a7
Deleted: b987f587ddb48e0006250cc77835530f605c32647d5cbe0432ea8a5fd3769017
Deleted: adbe1f76147105dc554a86f026dab8fa8b2019892bfb5d10cfe9e3df5bafa9b9

 刪除不會有問題, 使用  docker  rmi 刪除所有 sakanatest/testimage 上面 image

 接下來嘗試刪除 有 container 執行的 image
> docker  rmi  testrepo/testimage:vTEST
Error response from daemon: Conflict, cannot delete 220501802d62 because the container acfed6e70946 is using it, use -f to force
Error: failed to remove images: [testrepo/testimage:vTEST]

 果然是要刪除 container 才能刪除  image

 再觀察一次
> docker  ps  -a
CONTAINER ID        IMAGE                      COMMAND             CREATED             STATUS                         PORTS               NAMES
acfed6e70946        testrepo/testimage:vTEST   "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       furious_pare       
ddc3cdc142f3        training/sinatra           "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       serene_tesla       
6764848c94c4        training/sinatra           "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                             elegant_lalande

 移除 container 可以使用  docker  rm 指令來完成

 > docker    rm    acfed6e70946
acfed6e70946

 確認已經刪除
> docker  ps  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
ddc3cdc142f3        training/sinatra    "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                       serene_tesla       
6764848c94c4        training/sinatra    "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                       elegant_lalande 

 刪除 image  testrepo/testimage:vTEST
> docker    rmi    testrepo/testimage:vTEST
Untagged: testrepo/testimage:vTEST
Deleted: 220501802d62b8aca6ed82aad9ea99c2dc9a12d195638b6bdf47f20aa8e92860

 接下來剩下一個 image 要刪除, 可是他有 2 個 container 在執行

 > docker  ps  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
ddc3cdc142f3        training/sinatra    "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                       serene_tesla       
6764848c94c4        training/sinatra    "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                       elegant_lalande   

 所以就把腦筋動到一次刪除所有的 container
docker  ps 指令加上 -q 只會列出 container ID
> docker  ps  -a  -q
ddc3cdc142f3
6764848c94c4

 但是做這件事的時候要三思而後行
> docker  rm  $( docker  ps  -a  -q )
ddc3cdc142f3
6764848c94c4

 > docker  ps  -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 刪除完練習用 image, 本日收工
> docker    rmi   training/sinatra:latest
Untagged: training/sinatra:latest
Deleted: f0f4ab557f954f3e04177663a3af90e88641bcdcce1f02ac900dbd9768ef4945
Deleted: 79e6bf39f99322cc062a79bec4a09de0dd19cb7f5f735b4b6b7832c04b13bb45
Deleted: ce80548340bb03726d391bb8fa4d134f8418c2fff90be9a7323560debdea9bd2
Deleted: e809f156dc985e07105fdc86ec05eb03eb7aac8636dc210e8595d31b55787f4a
Deleted: bfab314f3b766eddf9778f8dce089f44e84ea028f4a44ce68740dce81a844ec8
Deleted: be88c4c27e80023b6aea82f0f2e15fb21c6f4193fe814e5b58010d356dd7846b
Deleted: 3e76c0a80540a0d36493ae7110796fc92f559a191454e3ac19c1d4c650bdd9e0
Deleted: 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158


~ enjoy it

21
Linux 討論版 / docker with openSUSE 13.2 小記
« 於: 2015-09-03 08:59 »
原 Blog URL
http://sakananote2.blogspot.tw/2015/09/docker-with-opensuse-132.html

最近覺得真的要撥一點時間學 docker 了...
OS 採用 openSUSE 13.2, 因為套件庫就內建 docker 了

 OS: openSUSE 13.2


主要練習教材 《Docker —— 從入門到實踐­》正體中文版
https://www.gitbook.com/book/philipzheng/docker_practice/details

 docker 安裝
參考 https://docs.docker.com/installation/SUSE/ 安裝 docker

 使用 zypper 指令安裝 docker
> sudo   zypper   in   docker

 We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

     #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

 root's password: 輸入 root 密碼

 6  新套件將被安裝.
Overall download size: 6.8 MiB. Already cached: 0 B  完成操作後,將增加 33.5 MiB 的使用。
要繼續嗎? [y/n/? shows all options] (y):  輸入y

 啟動 docker
> sudo  systemctl  start   docker

 設定開機啟動 docker
> sudo  systemctl   enable   docker

 Docker 官網有段文字要注意 ( 一般使用者如果要使用 docker, 要被加入到 docker 群組 )
The docker package creates a new group named docker. Users, other than root user, need to be part of this group in order to interact with the Docker daemon. You can add users with:
$ sudo   /usr/sbin/usermod   -a   -G   docker   <username>

 驗證是否成功
> sudo   docker   run   --rm   -i   -t   opensuse    /bin/bash
Unable to find image 'opensuse:latest' locally
latest: Pulling from opensuse
5b8dd08af89b: Pull complete
d6b241b32a2d: Already exists
opensuse:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:d1e63126409bb816d11891776c9315f6432f66102825cde6a0055e2cfddcd3a4
Status: Downloaded newer image for opensuse:latest
目前是在 docker 內的 /bin/bash, 查看系統版本 ( 但是我也是 openSUSE 13.2 啊 ~~ )
bash-4.2# cat   /etc/*release
openSUSE 13.2 (x86_64)
VERSION = 13.2
CODENAME = Harlequin
# /etc/SuSE-release is deprecated and will be removed in the future, use /etc/os-release instead
NAME=openSUSE
VERSION="13.2 (Harlequin)"
VERSION_ID="13.2"
PRETTY_NAME="openSUSE 13.2 (Harlequin) (x86_64)"
ID=opensuse
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:opensuse:13.2"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://opensuse.org/"
ID_LIKE="suse"
輸入 exit 離開
# exit

 既然來了就測試一下別的 OS 吧 ^^
利用 docker pull 下載映像檔
> sudo   docker   pull   ubuntu:12.04
root's password:
12.04: Pulling from ubuntu

 ba2b457ecfb2: Downloading [================>                                  ]  14.6 MB/43.92 MB

 列出本機映像檔
> sudo   docker   images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              12.04               57bca5139a13        12 days ago         134.8 MB
opensuse            latest              d6b241b32a2d        5 weeks ago         93.99 MB


今天先到這邊

 ~ enjoy it

22
想請教大家目前使用 ceph 的效能如何
目前使用的版本是
ceph                                0.80.7-1trusty

目前感覺效能沒有很好
不知道大家的狀況是?

23
詳情請見

http://www.104.com.tw/jobbank/custjob/index.php?r=job&j=3860436d346c3f5639323a633864365f25e3a432648463e2121212121382b2625381j56&jobsource=104_sj&hotjob_chr=

工作內容
1.協助開放街景地圖社群連結與會議舉辦
2.協助開放街景地圖平台開發
3.協助特定開放街景地圖應用APP開發
4.協助專案行政業務
職務類別:
研究助理
工作待遇:
面議
工作性質:
全職
上班地點:
新竹市科學園區研發6路7號  (新竹科學工業園區)地圖
管理責任:
不需負擔管理責任
出差外派:
無需出差外派
上班時段:
日班,8-17
休假制度:
依公司規定
可上班日:
一週內
需求人數:
1 人
工作條件
接受身份:
上班族、應屆畢業生
工作經歷:
不拘
學歷要求:
碩士
科系要求:
資訊工程相關
語文條件:
不拘
擅長工具:
不拘
工作技能:
不拘
其他條件:
1.熟悉開放街圖地圖
2.熟悉自由軟體開發
計畫人員聘期自起聘日起至104年7月31日止

24
Linux 討論版 / 藍芽傳輸器 in openSUSE 13.1
« 於: 2014-02-23 16:41 »
分享個小東西吧, 之前在 PC 上面如果買藍芽傳輸器,
我碰到的都只能接鍵盤或是滑鼠之類的裝置, 不能外接我的藍芽耳機聽音樂.


前幾天在網路上買的藍芽傳輸器 WED-210v4
http://shopping.pchome.com.tw/?mod=item&func=exhibit&IT_NO=DCAD02-A72913446

在 openSUSE 13.1 上面是隨插即用,且可以使用我的 Sony HBH-200 藍芽耳機.

我想主要是支援A2DP藍牙立體聲的關係, 之前購買的藍芽傳輸器都沒有直接寫明支援 A2DP

跟大家分享一下 ^__^ ~

25
Linux 討論版 / youtube-dl with openSUSE 13.1
« 於: 2014-02-23 16:38 »
有時候會有從 Youtube 下載影片的需求

參考 How to save Youtube video on Linux http://xmodulo.com/2013/03/how-to-save-youtube-videos-on-linux.html

 查了 http://software.opensuse.org/package/youtube-dl
發現他在 standard 套件庫內

 # zypper  search  youtube
Retrieving repository 'NCHC-Packman' metadata ............................[done]
Building repository 'NCHC-Packman' cache .................................[done]
Loading repository data...
Reading installed packages...

 S | Name                 | Summary                                  | Type     
--+----------------------+------------------------------------------+-----------
i | grilo-plugin-youtube | Media discovering and browsing framewo-> | package   
  | youtube-dl           | Download Videos from youtube.com         | package   
  | youtube-dl           | Download Videos from youtube.com         | srcpackage


 安裝 youtube-dl

 # zypper   install  youtube-dl
Loading repository data...
Reading installed packages...
Resolving package dependencies...

 The following NEW package is going to be installed:
  youtube-dl

 1 new package to install.
Overall download size: 226.1 KiB. After the operation, additional 899.5 KiB
will be used.
Continue? [y/n/? shows all options] (y):
y

 透過 youtube-dl  -F 來觀察可以下載的格式
> 為 openSUSE 下一般使用者 shell 的提示符號(Like $)

 > youtube-dl  -F  http://www.youtube.com/watch?v=13eLHrDcb1k
[youtube] Setting language
[youtube] 13eLHrDcb1k: Downloading video webpage
[youtube] 13eLHrDcb1k: Downloading video info webpage
[youtube] 13eLHrDcb1k: Extracting video information
Available formats:
22 : mp4 [720x1280]
18 : mp4 [360x640]
43 : webm [360x640]
5 : flv [240x400]
17 : mp4 [144x176]


 指定要下載的格式進行下載 (請注意 -f 是小寫)

 > youtube-dl  -f  22 http://www.youtube.com/watch?v=13eLHrDcb1k
[youtube] Setting language
[youtube] 13eLHrDcb1k: Downloading video webpage
[youtube] 13eLHrDcb1k: Downloading video info webpage
[youtube] 13eLHrDcb1k: Extracting video information
[download] Destination: Your Eyes - 竹内まりや ( 安堂ロイド~A.I. knows LOVE?~ 主題歌 )Yo1ko2 Cover-13eLHrDcb1k.mp4
[download] 100.0% of 15.98MiB at 26.02MiB/s ETA 00:00


 觀察輸出

 > ls
2013ironman                                                                                    下載
AddPackmanRepo.sh                                                                              公共
bin                                                                                            圖片
Dropbox                                                                                        影片
forticlientsslvpn                                                                              文件
forticlientsslvpn_linux_4.0.2010.tar.gz                                                        桌面
javaLearn                                                                                      模板
public_html                                                                                    相關會議資訊.docx

Your Eyes - 竹内まりや ( 安堂ロイド~A.I. knows LOVE?~ 主題歌 )Yo1ko2 Cover-13eLHrDcb1k.mp4  音樂

 在指令的選項部份, man 了一下相關選項,找一下可能的有用選項
--all-formats 下載所有的格式
-a, --batch-file  使用檔案的方式批次下載

 例如

 
代碼: [選擇]
> cat   video.list
http://www.youtube.com/watch?v=13eLHrDcb1k
http://www.youtube.com/watch?v=JFlqULfmg2M



> youtube-dl  -a   video.list
[youtube] Setting language
[youtube] 13eLHrDcb1k: Downloading video webpage
[youtube] 13eLHrDcb1k: Downloading video info webpage
[youtube] 13eLHrDcb1k: Extracting video information
[download] Destination: Your Eyes - 竹内まりや ( 安堂ロイド~A.I. knows LOVE?~ 主題歌 )Yo1ko2 Cover-13eLHrDcb1k.mp4
[download] 100.0% of 15.98MiB at 40.78MiB/s ETA 00:00
[youtube] JFlqULfmg2M: Downloading video webpage
[youtube] JFlqULfmg2M: Downloading video info webpage
[youtube] JFlqULfmg2M: Extracting video information
[download] Destination: Hiroshi Kitadani - Pegasus Fantasy Cover no AF 2006 [DBBR]-JFlqULfmg2M.mp4
[download] 100.0% of 16.46MiB at 30.48MiB/s ETA 00:00


26
MOOC 今年似乎真的很火紅

國立交通大學「八年抗戰---迎向平權學習的未來」研討會
https://kktix.com/events/20131219

轉發交大 白啟光老師的研討會 給大家參考

27
Study Area 酷學園在 Flickr 有相片集以及群組

相片集:
http://www.flickr.com/photos/studyarea/sets

群組:
http://www.flickr.com/groups/2138899@N23/

如果您有 Flickr 的帳號, 也有之前活動的照片, 希望可以加入此群組, 然後將您的照片加到此群組.
^__^

感謝大家


sakana

28
好康報報 / Arduino 基礎課程 2013/2/7 資訊
« 於: 2013-01-28 10:02 »
Dear ALL:

轉 國網中心 Arduino 基礎課程資訊給各位
有興趣的朋友可以參加

https://edu.nchc.org.tw/course/one_course_introduction.asp?lms_auto_course_id=2172&from_course_list_url=course_search


報名費用:   
一般人士   1200 元
學生   800 元
課程介紹:   
Arduino 是一套開放式源碼的軟、硬體開發板,我們可以透過官方網站(arduino.cc)免費完整取得電路板及開發的軟體,透過感測器及控制電路的結合,既使沒修習過電子電路的也能快速上手,建立自己的互動平臺,偵測環境中的溫度、溼度、亮度、按鍵控制…等。
參加對象:   
學員請自備 Arduino UNO 或 Duemilanove 開發板
課程內容安排:   
一、Arduino 開發板介紹。
二、感測器介紹。
三、建立開發環境。
四、數位信號輸入、輸出控制。
五、類比信號輸入、輸出控制。
六、透過 UART 與 PC 交換資料。
七、實作 LED 跑馬燈。
八、實作 燈泡 控制。

29
Dear ALL:

Oracle 可以下載 Java Tutorial eBook
有 epub 與 mobi 格式
http://www.oracle.com/technetwork/java/javase/downloads/java-se-7-tutorial-2012-02-28-1536013.html

大家有推荐的閱讀順序嗎?


30
請參考 & 報名網頁
http://www.openfoundry.org/tw/activities/details/342

議程簡介
Nagios 是一個 open source 的電腦系統與網路服務的監控軟體。它可以監控主機與服務,當異常狀況發生時,可以通知指定的聯絡人、或是以指定的通知方式來聯繫。另外也有眾多的 Plugin 可以使用。

對象:大專院校資訊相關系所的學生,或是對自由軟體有興趣者。( 有 Linux 系統操作經驗佳)
人數:約 28 人。
費用:全程免費。
平台:openSUSE 12.2

頁: [1] 2 3 ... 6