python管理系统web版_Python从零搭建Conf_Web配置管理平台
作者:Eagle
某船舶行業(yè)科技公司,運(yùn)維工程師,51Reboot學(xué)員。通過在51Reboot學(xué)習(xí),由運(yùn)維工程師轉(zhuǎn)至運(yùn)維開發(fā)工程師。完成公司自動化平臺的構(gòu)建,對運(yùn)維開發(fā)有了自己的理解,空閑時(shí)間寫了這么一個(gè)小的項(xiàng)目來和大家分享一下。
環(huán)境
CentOS 6/7 x64
Python:2 .7.6
Etcd: 3.2.18
Confd:0 .16.0
Nginx: 1.12.1
效果演示
一,拓?fù)鋱D:
二、涉及軟件
ETD: 。分布式KV存儲系統(tǒng),一般用于共享配置和服務(wù)注冊與發(fā)現(xiàn)是ETOS存儲格式類似于文件系統(tǒng),以根“/”開始下面一級級目錄,最后一個(gè)是重點(diǎn),一個(gè)關(guān)鍵對應(yīng)一個(gè)值。
ETCD 集群:使用筏協(xié)議保證每個(gè)節(jié)點(diǎn)數(shù)據(jù)一致,由多個(gè)節(jié)點(diǎn)對外提供服務(wù)這里只用單臺。
confd:管理本地應(yīng)用配置文件,使用etcd或consul存儲的數(shù)據(jù)渲染模板,還支持redis,zookeeper等.confd有一個(gè)手表功能,通過HTTP API定期監(jiān)測對應(yīng)的etcd中目錄變化,獲取最新的價(jià)值,然后竟染模板
Nginx: Nginx是一款輕量級的Web服務(wù)器/反向代理服務(wù)器以及電子郵件代理服務(wù)器,并在一個(gè)BSD-like協(xié)議下發(fā)行。來自俄羅斯的程序設(shè)計(jì)師l gor Sysoev所開發(fā),供俄國大型的入口網(wǎng)站及搜索引擎聯(lián)系Rambler使用。其特點(diǎn)是占有內(nèi)存少,并發(fā)能力強(qiáng),事實(shí)上nginx的的并發(fā)能力確實(shí)在同類型的網(wǎng)頁服務(wù)器中表現(xiàn)較好。
三、軟件部署
環(huán)境說明:建議使用 Cento7.X X64
1)安裝 etcd(這里安裝的單機(jī),集群環(huán)境根據(jù)自己的需求選取)#yum install etcd -y
#sed -i's / localhost / 0.0.0.0 / g'/etc/etcd/etcd.conf#配置監(jiān)聽地址
#systemctl start etcd && systemctl enable etcd#啟動服務(wù)設(shè)置開機(jī)動
2)安裝 nginx
#cd / usr / local / src
#wget http://nginx.org/download/nginx-1.12.1.tar.gz
#git clone https://github.com/yaoweibin/nginx_upstream_check_module.git
#tar -zxvf nginx-1.12.1.tar.gz
#cd nginx-1.12.1
#patch -p1 /local/src/nginx_upstream_check_module/check_1.12.1+.patch
#。/ configure --prefix = / usr / local / nginx --add-module = / usr / local / src / nginx_upstream_check_module /
make && make install
#mkdir / usr / local / nginx / conf / vhost /
Nginx的主配置文件修改為這個(gè)樣子,增加包括目錄配置
#vi /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs / error.log;
#error_log logs / error.log通知;
#error_log logs / error.log info;
#pid logs / nginx.pid;
事件{
worker_connections 1024;
}
http {
包括mime.types;
default_type application / octet-stream;
#log_format main'$ remote_addr - $ remote_user [$ time_local]“$ request”'
#'$ status $ body_bytes_sent“$ http_referer”'
#'“$ http_user_agent”“$ http_x_forwarded_for”';
#access_log logs / access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
包括vhost / * .conf;
}
3)安裝 confd
地址下載https://github.com/kelseyhightower/confd/releases
下載完畢丟到系統(tǒng)里面
#cp confd / usr / bin / confd
#哪個(gè)confd
在/ usr / bin中/ confd
4)創(chuàng)建配置文件目錄
#mkdir -p /etc/confd/{conf.d,templates}
conf.d#資源模板,下面文件必須以toml后綴
templates#配置文件模板,下面文件必須以tmpl后綴
5)創(chuàng)建 confd 配置文件
#vi /etc/confd/conf.d/app01.conf.toml
src =“app01.conf.tmpl”#默認(rèn)在/ etc / confd / templates目錄下
dest =“/ usr / local / nginx / conf / vhost / app01.conf”#要更新的配置文件
鍵= [
“/ Shopping”,#監(jiān)測的關(guān)鍵
]
reload_cmd =“/ usr / local / nginx / sbin / nginx -s reload”#最后執(zhí)行的命令
6)創(chuàng)建 confd 模板
#vi /etc/confd/templates/app01.conf.tmpl
upstream {{getv“/ Shopping / nginx / cluster1 / proxy_name”}} {
{{range getvs“/ Shopping / nginx / cluster1 / upstream / *”}}
server {{。}};
{{結(jié)束}}
check interval = 5000 rise = 1 fall = 5 timeout = 4000 type = http;
check_http_send“HEAD / HTTP / 1.0 \ r \ n \ r \ n”;
check_http_expect_alive http_2xx http_3xx;
}
服務(wù)器{
server_name {{range getvs“/ Shopping / nginx / cluster1 / server_name / *”}} {{。}} {{end}};
位置 / {
proxy_pass http:// {{getv“/ Shopping / nginx / cluster1 / proxy_name”}};
proxy_redirect off;
proxy_set_header Host $ host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}
位置/狀態(tài){
檢查狀態(tài);
access_log off;
}
}
7)啟動 confd 并設(shè)置開機(jī)啟動
開機(jī)啟動腳本會隨文檔附帶
拷貝至 /etc/init.d/confd,只需要更改等改為連接地址即可#/ etc / init.d / confd start && chkconfig --add confd && chkconfig confd on
四、配置平臺部署
1)Github克隆平臺代碼安裝平臺依賴
#git clone https://github.com/1032231418/Conf_Web.git
#cd Conf_Web / ospweb /
#virtualenv env#建議創(chuàng)建一個(gè)沙盒環(huán)境跑該平臺
#source env / bin / activate#使用沙盒環(huán)境
#pip install -r requirement.txt#安裝相關(guān)軟件
2)創(chuàng)建數(shù)據(jù)庫并將表刷入數(shù)據(jù)庫#vi opsweb / settings.py#這里數(shù)據(jù)庫信息改為自己的數(shù)據(jù)庫信息DATABASES = {'default':{'ENGINE':'django.db.backends.mysql','NAME':'confd','HOST' :'192.168.8.114','USER':'root','PASSWORD':'123456','PORT':3306,}} ETCD_Server =“192.168.0.221”#這里改為自己etcd的ip地址ETCD_Port = 2379 #python manage.py migrate#提交遷移文件至數(shù)據(jù)庫,將表刷入數(shù)據(jù)庫
3)創(chuàng)建超級管理員賬號#python manage.py createsuperuser
4)運(yùn)行平臺#python manage.py runserver 0:8000
訪問地址就是http:// ip:8000賬號密碼就是上一步創(chuàng)建的超級管理員賬號密碼5)登錄平臺為nginx創(chuàng)建鍵/值
例子:購物平臺為例
項(xiàng)目創(chuàng)建:
1.創(chuàng)建商城項(xiàng)目/購物
2.創(chuàng)建商城項(xiàng)目里面的/ Shopping / nginx nginx服務(wù)
3.創(chuàng)建nginx集群目錄/ Shopping / nginx / cluster1
4.給我們的商城nginx的集群1項(xiàng)目創(chuàng)建配置文件
5.域名和節(jié)點(diǎn)名稱可能是多個(gè),這里我們需要?jiǎng)?chuàng)建目錄/ Shopping / nginx / cluster1 / server_name和/ Shopping / nginx / cluster1 / upstream
etcd里面存儲的值
配置創(chuàng)建:
1.反向代理/ Shopping / nginx / cluster1 / proxy_name
2.綁定一個(gè)域名/ Shopping / nginx / cluster1 / server_name / 1
3.創(chuàng)建一個(gè)集群節(jié)點(diǎn)/ Shopping / nginx / cluster1 / upstream / web1
etcd 里面存儲的值
生成的配置文件
通過主機(jī)文件我們可以查看節(jié)點(diǎn)狀態(tài)(雖然這個(gè)節(jié)點(diǎn)不是最高狀態(tài)但是由此可見,我們可以動態(tài)添加節(jié)點(diǎn))
就分享該項(xiàng)目的作者在2018年7月12日晚21:00-22:00會跟大家詳細(xì)講解該項(xiàng)目并且相互探討共同學(xué)習(xí)進(jìn)步有興趣的朋友可以看一下報(bào)名方式然后報(bào)名免費(fèi)領(lǐng)取視頻并且進(jìn)入直播群和我們的作者互動。
報(bào)名方式
分享時(shí)間: 18年7月12日晚
21:00--22:00
分享方式:網(wǎng)絡(luò)直播
報(bào)名方式:掃碼添加小助手微信,備注“公開課”進(jìn)入直播分享群免費(fèi)獲取視頻
總結(jié)
以上是生活随笔為你收集整理的python管理系统web版_Python从零搭建Conf_Web配置管理平台的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 模型训练测试之三:yolov5 模型训练
- 下一篇: python手动垃圾回收_Python3