快活林资源网 Design By www.csstdc.com
我就废话不多说了,大家还是直接看代码吧~
# !/usr/bin/env python # -*- coding:utf-8 -*- __author__ = '_X.xx_' __date__ = '2018/7/18 16:44' from django.http import JsonResponse class HttpCode(object): ok = 200 paramserror = 400 unantu = 401 methoderror = 405 servererror = 500 def ok(): return result() def result(code=HttpCode.ok, message='', data=None, kwargs=None): json_dict = {'code': code, 'message': message, 'data': data} if kwargs and isinstance(kwargs, dict) and kwargs.keys(): json_dict.update(kwargs) return JsonResponse(json_dict) def params_error(message='', data=None): return result(code=HttpCode.paramserror, message=message, data=data) def unauth(message='', data=None): return result(code=HttpCode.unantu, message=message, data=data) def method_error(message='', data=None): return result(code=HttpCode.methoderror, message=message, data=data) def server_error(message='', data=None): return result(code=HttpCode.servererror, message=message, data=data)
补充知识:python部署galery集群
galery.py文件内容
import pexpect import os import configparser HOSTNAME_DB1='db1' HOSTNAME_DB2='db2' HOSTNAME_DB3='db3' DB1 = '192.168.254.24' DB2 = '192.168.254.27' DB3 = '192.168.254.36' PORT = 22 USERNAME = 'root' PASSWORD = 'root' server3_cnf = 'sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;sed -i "s/wsrep_node_address = %s/wsrep_node_address = %s/g" /etc/my.cnf.d/server.cnf' % (DB1,DB3) server2_cnf = 'sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;sed -i "s/wsrep_node_address = %s/wsrep_node_address = %s/g" /etc/my.cnf.d/server.cnf' % (DB1,DB3) def config_parse(): config = configparser.ConfigParser() config.read("/etc/my.cnf.d/server.cnf", encoding="utf-8") config.set('galera','wsrep_on','ON') config.set('galera','wsrep_provider','/usr/lib64/galera/libgalera_smm.so') config.set('galera','wsrep_cluster_address','"gcomm://%s,%s,%s"' % (DB1, DB2, DB3)) config.set('galera','wsrep_node_name','%s' % HOSTNAME_DB1 ) config.set('galera','wsrep_node_address','%s' % DB1) config.set('galera','binlog_format','row') config.set('galera','default_storage_engine','InnoDB') config.set('galera','innodb_autoinc_lock_mode','2') config.set('galera','wsrep_slave_threads','1') config.set('galera','innodb_flush_log_at_trx_commit','1') config.set('galera','innodb_buffer_pool_size','120M') config.set('galera','wsrep_sst_method','rsync') config.set('galera','wsrep_causal_reads','ON') config.write(open('/etc/my.cnf.d/server.cnf','w')) def cp_server_cnf(): child1 = pexpect.spawn('scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf' % (USERNAME,DB2)) child1.expect('password:') child1.sendline(PASSWORD) child1.interact() child1.close() child2 = pexpect.spawn('scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf' % (USERNAME,DB3)) child2.expect('password:') child2.sendline(PASSWORD) child2.interact() child2.close() def conn_db(ip,cnf): child3 = pexpect.spawn('ssh %s@%s' % (USERNAME, ip)) child3.expect('password:') child3.sendline('root') child3.expect('#') child3.sendline(cnf) child3.expect('#') child3.sendline('systemctl restart mariadb > /dev/null') child3.sendline('exit') child3.interact() child3.close() def init_cmd(): res1 = os.system('service mariadb stop') res2 = os.system('mysqld_safe --wsrep_cluster_address=gcomm://%s,%s,%s >/dev/null &' % (DB1, DB2, DB3)) res3 = os.system('galera_new_cluster &>/dev/null') if res2 == 0: print('galera初始化完成') if res3 == 0: print('galera集群已经启动') else: print('galera集群启动失败') else: print('galera初始化失败!') def main(): config_parse() cp_server_cnf() init_cmd() conn_db(DB2,server2_cnf) conn_db(DB3,server3_cnf) if __name__ == '__main__': main()
以上这篇Django封装交互接口代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com
暂无评论...
更新日志
2024年12月25日
2024年12月25日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]