亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 6359 | 回復(fù): 0
打印 上一主題 下一主題

[Salt] Salt自動化之自動更新Gitfs [復(fù)制鏈接]

論壇徽章:
1
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-03-21 06:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-05-26 11:33 |只看該作者 |倒序?yàn)g覽
Salt支持Gitfs, 可以將State Tree放入Git遠(yuǎn)程倉庫中, 進(jìn)行版本控制, 易于管理. 當(dāng)提交更新至遠(yuǎn)程Git倉庫后, 需要手動在Master執(zhí)行如下操作:
  1. salt-run fileserver.update
復(fù)制代碼

或者等待一段時間,由Master的maintenance進(jìn)程進(jìn)行更新(默認(rèn)更新間隔為60s, 可以通過master配置文件 loop_interval 選項(xiàng)進(jìn)行調(diào)整). 那么有沒有一種方案, 能夠?qū)崿F(xiàn)Push代碼至Git倉庫后, 自動觸發(fā)Gitfs的更新哪?

常見的Git倉庫管理系統(tǒng), 如Gitlab, Github, Bitbucket都支持Webhook功能, 即當(dāng)Push代碼至倉庫時, 能夠自動觸發(fā)外部Webhook調(diào)用, 而Salt API提供Webhook功能, 可以通過Webhook觸發(fā)Event, Reactor系統(tǒng)又能基于Event進(jìn)行Salt自動化管理, 看看可以就此入手, 實(shí)現(xiàn)Gitfs自動更新方案.
環(huán)境說明

CentOS 6.5 With EPEL
salt-master及salt-api版本2015.5.0
Master端已安裝python-pygit2
Master端已安裝Nginx(用于salt-api安全防護(hù))
本次采用Github作為遠(yuǎn)程倉庫Demo
本次采用臨時域名salt-api-demo.pengyao.org進(jìn)行測試, 請根據(jù)自己真實(shí)環(huán)境進(jìn)行調(diào)整
開工

以下操作, 如非說明, 均在Master端進(jìn)行
配置Salt API
  1. /etc/salt/master.d/api.conf
復(fù)制代碼
  1. rest_cherrypy:
  2.   port: 8000
  3.   host: 127.0.0.1
  4.   debug: True
  5.   disable_ssl: True
  6.   webhook_url: /hook
  7.   webhook_disable_auth: True
復(fù)制代碼

由于第三方Webhook部分并不支持認(rèn)證功能, 所以關(guān)閉了webhook認(rèn)證(webhook_disable_auth參數(shù))

重啟Salt API服務(wù), 以使配置生效
  1. service salt-api restart
復(fù)制代碼

由于關(guān)閉了Webhook認(rèn)證, 意味著公網(wǎng)所有人都可以觸發(fā)本W(wǎng)ebhook, 所以Master端安裝了Nginx對Webhook接口增加Basic Auth認(rèn)證功能

  1. /etc/nginx/conf.d/salt-api-demo.pengyao.org.conf
復(fù)制代碼
  1. upstream salt-api-demo {
  2.   server 127.0.0.1:8000;
  3. }

  4. server {
  5.   listen 80;
  6.   server_name salt-api-demo.pengyao.org;

  7.   location / {
  8.     proxy_pass  http://salt-api-demo;
  9.   }
  10.   location /hook {
  11.     proxy_pass  http://salt-api-demo;
  12.     auth_basic  "salt api demo";
  13.     auth_basic_user_file  /opt/htpasswd;
  14.   }
  15. }
復(fù)制代碼

重啟Nginx服務(wù), 以使配置生效
  1. service nginx restart
復(fù)制代碼

創(chuàng)建Basic Auth用戶文件:
  1. echo "demo:$(echo -n demo_pass |openssl passwd -stdin)"  > /opt/htpasswd
復(fù)制代碼

Master下載eventlisten.py, 監(jiān)聽Event
  1. wget https://raw.githubusercontent.com/saltstack/salt/develop/tests/eventlisten.py
  2. python eventlisten.py
復(fù)制代碼

開啟新窗口, 手動觸發(fā)webhook, 進(jìn)行測試
  1. curl http://demo:demo_pass@salt-api-demo.pengyao.org/hook/test -XPOST -d "demo=True"
復(fù)制代碼

運(yùn)行eventlisten.py的控制臺有如下輸出:
  1. Event fired at Tue May 26 00:33:04 2015
  2. *************************
  3. Tag: salt/netapi/hook/test
  4. Data:
  5. {'_stamp': '2015-05-25T16:33:04.425532',
  6. 'body': '',
  7. 'headers': {'Accept': '*/*',
  8.              'Authorization': 'Basic ZGVtbzpkZW1vX3Bhc3M=',
  9.              'Connection': 'close',
  10.              'Content-Length': '9',
  11.              'Content-Type': 'application/x-www-form-urlencoded',
  12.              'Host': 'salt-api-demo',
  13.              'Remote-Addr': '127.0.0.1',
  14.              'User-Agent': 'curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2'},
  15. 'post': {'demo': 'True'}}
復(fù)制代碼

webhook測試達(dá)到預(yù)期

建立遠(yuǎn)程倉庫

登陸Github建立遠(yuǎn)程倉庫, 本次Demo倉庫地址:
https://github.com/pengyao/salt-gitfs-demo.git
配置Gitfs
  1. /etc/salt/master.d/gitfs.conf
復(fù)制代碼
  1. # Gitfs backend
  2. fileserver_backend:
  3.   - git

  4. # Gitfs provider
  5. gitfs_provider: pygit2

  6. # Gitfs repositories
  7. gitfs_remotes:
  8.   - https://github.com/pengyao/salt-gitfs-demo.git
復(fù)制代碼

重啟Salt Master服務(wù), 以使配置生效
  1. service salt-master restart
復(fù)制代碼

重啟完畢后, 獲取gitfs中的文件列表(啟動時, 會自動觸發(fā)拉取最新的遠(yuǎn)程倉庫代碼)
  1. salt-run fileserver.file_list
復(fù)制代碼

輸出如下:
  1. - README
復(fù)制代碼

配置Reactor
  1. /etc/salt/master.d/reactor.conf
復(fù)制代碼
  1. reactor:
  2.   - 'salt/netapi/hook/gitfs/*':
  3.     - /srv/reactor/gitfs.sls
復(fù)制代碼
  1. /srv/reactor/gitfs.sls
復(fù)制代碼
  1. {% if 'gitfs/update' in tag %}
  2. gitfs_update:
  3.   runner.fileserver.update
  4. {% endif %}
復(fù)制代碼

重啟Salt Master服務(wù), 以使配置生效
  1. service salt-master restart
復(fù)制代碼

重啟完畢后, 測試webhook:
  1. curl http://demo:demo_pass@salt-api-demo.pengyao.org/hook/gitfs/update -XPOST -d "demo=True"
復(fù)制代碼

運(yùn)行eventlisten.py的窗口, 有如下輸出:
  1. Event fired at Tue May 26 00:49:11 2015
  2. *************************
  3. Tag: salt/netapi/hook/gitfs/update
  4. Data:
  5. {'_stamp': '2015-05-25T16:49:11.694576',
  6. 'body': '',
  7. 'headers': {'Accept': '*/*',
  8.              'Authorization': 'Basic ZGVtbzpkZW1vX3Bhc3M=',
  9.              'Connection': 'close',
  10.              'Content-Length': '9',
  11.              'Content-Type': 'application/x-www-form-urlencoded',
  12.              'Host': 'salt-api-demo',
  13.              'Remote-Addr': '127.0.0.1',
  14.              'User-Agent': 'curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2'},
  15. 'post': {'demo': 'True'}}
  16. Event fired at Tue May 26 00:49:11 2015
  17. *************************
  18. Tag: salt/event/new_client
  19. Data:
  20. {'_stamp': '2015-05-25T16:49:11.737823'}
  21. Event fired at Tue May 26 00:49:11 2015
  22. *************************
  23. Tag: salt/run/20150526004911736899/new
  24. Data:
  25. {'_stamp': '2015-05-25T16:49:11.742807',
  26. 'fun': 'runner.fileserver.update',
  27. 'jid': '20150526004911736899',
  28. 'user': 'Reactor'}
  29. Event fired at Tue May 26 00:49:14 2015
  30. *************************
  31. Tag: salt/run/20150526004911736899/ret
  32. Data:
  33. {'_stamp': '2015-05-25T16:49:14.168910',
  34. 'fun': 'runner.fileserver.update',
  35. 'jid': '20150526004911736899',
  36. 'return': True,
  37. 'success': True,
  38. 'user': 'Reactor'}
復(fù)制代碼

可以看到, 本次測試, 產(chǎn)生了4條event:

webhook產(chǎn)生, 對應(yīng)Tag為: salt/netapi/hook/gitfs/update
由于配置的有對應(yīng)的Reactor, 所以會自動創(chuàng)建Reactor線程, 產(chǎn)生第二條Event
產(chǎn)生的Reactor線程在獲取對應(yīng)的sls發(fā)現(xiàn)需要運(yùn)行runner.fileserver.update任務(wù), 所以自動創(chuàng)建該任務(wù), 對應(yīng)的Tag為: salt/run/$jid/new
runner任務(wù)結(jié)果返回, 對應(yīng)的Tag為: salt/run/$jid/ret
測試達(dá)到預(yù)期

配置GitHub Webhook

進(jìn)入項(xiàng)目配置頁面, 選擇"Webhooks & Services"左側(cè)導(dǎo)航條, 選擇 "Add Webhook", 分別輸入如下內(nèi)容:

Payload URL: http://demo:demo_pass@salt-api-demo.pengyao.org/hook/gitfs/update
輸入完畢后, 選擇 Add Webhook進(jìn)行保存

自動更新Gitfs測試

本地clone本項(xiàng)目, 進(jìn)行如下操作:
  1. git clone git@github.com:pengyao/salt-gitfs-demo.git
  2. cd salt-gitfs-demo
  3. echo "I am a test" > test
  4. git add -A
  5. git commit -m "add test"
  6. git push -u origin master
復(fù)制代碼

git push后, 在運(yùn)行eventlisten.py窗口, 有如下輸出:
  1. Event fired at Tue May 26 01:04:15 2015
  2. *************************
  3. Tag: salt/netapi/hook/gitfs/update
  4. Data:
  5. {'_stamp': '2015-05-25T17:04:15.495458',
  6. 'body': '{"ref":"refs/heads/master","before":"efe61d0816e4f34c7c0117945ef2383a4183ac26","after":"e2264a6386bf5c6b8ec6daee0ddca3155b4e3ccc","created":false,"deleted":false,"forced":false,"base_ref":null,"compare":"https://github.com/pengyao/salt-gitfs-demo/compare/efe61d0816e4...e2264a6386bf","commits"
  7. ......此處省略若干字......
  8. Event fired at Tue May 26 01:04:15 2015
  9. *************************
  10. Tag: salt/event/new_client
  11. Data:
  12. {'_stamp': '2015-05-25T17:04:15.523955'}
  13. Event fired at Tue May 26 01:04:15 2015
  14. *************************
  15. Tag: salt/run/20150526010415522645/new
  16. Data:
  17. {'_stamp': '2015-05-25T17:04:15.529005',
  18. 'fun': 'runner.fileserver.update',
  19. 'jid': '20150526010415522645',
  20. 'user': 'Reactor'}
  21. Event fired at Tue May 26 01:04:19 2015
  22. *************************
  23. Tag: salt/run/20150526010415522645/ret
  24. Data:
  25. {'_stamp': '2015-05-25T17:04:19.393239',
  26. 'fun': 'runner.fileserver.update',
  27. 'jid': '20150526010415522645',
  28. 'return': True,
  29. 'success': True,
  30. 'user': 'Reactor'}
復(fù)制代碼

檢查gitfs倉庫文件列表:
  1. salt-run fileserver.file_list
復(fù)制代碼

輸出如下:
  1. - README
  2. - test
復(fù)制代碼

達(dá)到預(yù)期

結(jié)束語

Reactor系統(tǒng)的加入, Salt插上智能化的翅膀, 輕松甩開競爭對手幾條街. 簡單易用的Salt REST API接口, 更易于和第三方系統(tǒng)整合, 使Salt輕松成為運(yùn)維系統(tǒng)自動化引擎.

人生苦短, 我用Salt!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP