lamp环境加glusterfs存储集群自动化监控自动修复python脚本

#!/usr/bin/python
#coding:utf-8
import os
import sys
import re
import paramiko
import commands
import time
import datetime

def apache_connect_perform(ip,command):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip,username=‘gluster_zabbix‘,password=‘gluster‘)
stdin,stdout,stdeer = client.exec_command(command)
global result
result = stdout.read()

print stdout.read()

print stdeer.read()

client.close()

#apache_connect_perform()

def apache_info_write(info):
with open(‘/opt/scripts/apache-stop.log‘,‘a‘) as f:
f.write(str(info) + ‘\n‘)

if name == ‘main‘:
command_apache_status = "sudo su -c ‘/etc/init.d/apache2 status|grep running|wc -l‘ -"
command_apache_restart = "sudo su -c ‘service apache2 restart‘ -"
command_nginx_reload = "setsid script -c ‘sudo nginx -s reload‘ /dev/null"
command_apache_mount_check = "df -h|grep ‘/app‘|wc -l"
command_apache_mount = "sudo su -c ‘mount -a‘ -"
command_apache_umount = "sudo su -c ‘umount /app‘ -"
apache_list = [‘10.133.72.116‘,‘10.133.72.118‘]
nginx_list = [‘10.133.72.110‘,‘10.133.72.111‘]
for ip in apache_list:
apache_connect_perform(ip,command_apache_status)

print result,ip

    if int(result) != 1:
        info_apache_stop = "%s, %s apache is not running"%(datetime.datetime.now(),ip)
        apache_info_write(info_apache_stop)
        try:
            apache_connect_perform(ip,command_apache_restart)
        except Exception as a:
            apache_info_write(a)

print result

        time.sleep(3)
        apache_connect_perform(ip,command_apache_status)
        if int(result) != 1:
            info_apache_stop_again = "%s ,%s apache restart fail"%(datetime.datetime.now(),ip)
            apache_info_write(info_apache_stop_again)
            for ip_nginx in nginx_list:
                command_nginx_zhushi = "grep %s /etc/nginx/conf.d/panda.saicmotor.com.conf|grep ‘#‘|wc -l"%ip
                apache_connect_perform(ip_nginx,command_nginx_zhushi)
                if int(result) == 0:
                    new_dst = "‘s/server %s/#&/‘"%ip
                    dst = ["sed","-i",new_dst,"/etc/nginx/conf.d/panda.saicmotor.com.conf"]
                    command_nginx_apache_stop = " ".join(dst)

                    new_command = ["sudo su -c",‘"‘,command_nginx_apache_stop,‘"‘,"-"]
                    new_command_split = " ".join(new_command)
                    apache_connect_perform(ip_nginx,new_command_split)
                    time.sleep(2)
                    apache_connect_perform(ip_nginx,command_nginx_reload)
                else:
                    pass

        else:
            info_apache_restart_sucess = "%s,%s apache now is rerunning now"%(datetime.datetime.now(),ip)
            apache_info_write(info_apache_restart_sucess)
    else:

print datetime.datetime.now(), "%s apache is running"%ip

        apache_connect_perform(ip,command_apache_mount_check)
        if int(result) == 1:
            for ip_nginx_zhushi in nginx_list:

print datetime.datetime.now(),"%s apache mount is already now"%ip

                command_nginx_zhushi = "grep %s /etc/nginx/conf.d/panda.saicmotor.com.conf|grep ‘#‘|wc -l"%ip
                            apache_connect_perform(ip_nginx_zhushi,command_nginx_zhushi)
                            if int(result) == 2:
                    new_dst = "‘/%s/s/#//g‘"%ip
                                        dst = ["sed","-i",new_dst,"/etc/nginx/conf.d/panda.saicmotor.com.conf"]
                                    command_nginx_apache_stop = " ".join(dst)

                                        new_command = ["sudo su -c",‘"‘,command_nginx_apache_stop,‘"‘,"-"]
                                        new_command_split = " ".join(new_command)
                                        apache_connect_perform(ip_nginx_zhushi,new_command_split)
                                        time.sleep(2)
                                        apache_connect_perform(ip_nginx_zhushi,command_nginx_reload)

        else:

print "not mount"

            info_app_mount = "%s ,%s apache is not mount now"%(datetime.datetime.now(),ip)
            apache_info_write(info_app_mount)
            try:
                apache_connect_perform(ip,command_apache_umount)
                time.sleep(4)
                apache_connect_perform(ip,command_apache_mount)
            except Exception as b:
                apache_info_write(b)
            time.sleep(2)
            apache_connect_perform(ip,command_apache_mount_check)
            if int(result) == 1:
                info_remount = "%s,%s apache is remounting now"%(datetime.datetime.now(),ip)
                apache_info_write(info_remount)
            else:
                info_mount_fail = "%s ,%s apache is remount fail"%(datetime.datetime.now(),ip)
                apache_info_write(info_mount_fail)
                for ip_nginx1 in nginx_list:
                    command_nginx_zhushi = "grep %s /etc/nginx/conf.d/panda.saicmotor.com.conf|grep ‘#‘|wc -l"%ip
                                        apache_connect_perform(ip_nginx1,command_nginx_zhushi)
                                        if int(result) == 0:
                        new_dst = "‘s/server %s/#&/‘"%ip
                        dst = ["sed","-i",new_dst,"/etc/nginx/conf.d/panda.saicmotor.com.conf"]
                        command_nginx_apache_stop = " ".join(dst)

                        new_command = ["sudo su -c",‘"‘,command_nginx_apache_stop,‘"‘,"-"]
                        new_command_split = " ".join(new_command)
                        apache_connect_perform(ip_nginx1,new_command_split)

                        time.sleep(2)
                        apache_connect_perform(ip_nginx1,command_nginx_reload)
                    else:
                        pass

原文地址:http://blog.51cto.com/12189425/2165952

时间: 2024-08-29 12:20:51

lamp环境加glusterfs存储集群自动化监控自动修复python脚本的相关文章

脚本自动部署构架集群和监控状态

脚本自动部署构架集群和监控状态 shell脚本编写自动部署.初始配置.并启动nginx反向代理服务 1 #!/bin/bash 2 systemctl disable firewalld 3 systemctl stop firewalld 4 setenforce 0 5 #### 6 yum install epel-release -y 7 yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 8 yum

GlusterFS分布式存储集群部署记录-相关补充

接着上一篇Centos7下GlusterFS分布式存储集群环境部署记录文档,继续做一些补充记录,希望能加深对GlusterFS存储操作的理解和熟悉度. ========================清理glusterfs存储环境========================= 由上面可知,该glusterfs存储集群有四个节点: [[email protected] ~]# cat /etc/hosts ....... 192.168.10.239 GlusterFS-master 192.

基于redhat7.3 ceph对象存储集群搭建+owncloud S3接口整合生产实践

一.环境准备 安装redhat7.3虚拟机四台 在四台装好的虚拟机上分别加一块100G的硬盘.如图所示: 3.在每个节点上配置主机名 4.集群配置信息如下 admin-node node1 node2 node3 192.168.42.110 192.168.42.111 192.168.42.112 192.168.42.113 deploy.osd*1 mon*1.osd*1. rgw*1.mds*1 mon*1.osd*1 mon*1.osd*1 5.各节点配置yum源 #需要在每个主机上

Linux网络服务--LAMP+Nginx+Squid搭建web集群

一.         项目名称         LAMP+Nginx+Squid搭建web集群环境 二.         项目拓扑 三.         项目描述 3.1 项目环境 某部队为了满足信息化政治工作建设需要,用以丰富官兵日常生活内容,活化教育形式,更好的建设部队人文环境,准备架设部队内部的网站服务器,并申请使用军内公网IP:1.1.1.1 基于以上情况为该部提出以下解决方案.   3.2 实施方案 3.2.1  服务器操作系统与软件版本选择 操作系统选择RedHat企业版5.10:

ZooKeeper环境搭建(单机/集群)(转)

前提: 配置文件主要是在$ZOOKEEPER_HOME/conf/zoo.cfg,刚解压时为zoo_sample.cfg,重命名zoo.cfg即可. 配置文件常用项参考:http://www.cnblogs.com/EasonJim/p/7483880.html 环境搭建: 一.ZooKeeper的搭建方式 ZooKeeper安装方式有三种,单机模式和集群模式以及伪集群模式. 单机模式:ZooKeeper只运行在一台服务器上,适合测试环境: 伪集群模式:就是在一台物理机上运行多个ZooKeepe

谈谈KV存储集群的设计要点

版权声明:本文由廖念波原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/150 来源:腾云阁 https://www.qcloud.com/community Key-value存储系统,是非常普遍的需求,几乎每个在线的互联网后台服务都需要KV存储,我们团队在KV存储方面,经历过几个时期,我自己深感要做好不容易. 这里扯远一点,展开说一下: 第一个时期,很早期的时候,我们的数据存储在mysql表里,按照用户账号简单的分库分

ceph部署二(存储集群安装)

完成预检之后,你就可以开始部署 Ceph 存储集群了.二.创建集群2.1.创建ceph集群mkdir my-clustercd my-clusterceph-deploy new ceph1 ceph2 ceph3在当前目录下用 ls 和 cat 检查 ceph-deploy 的输出,应该有一个 Ceph 配置文件.一个 monitor 密钥环和一个日志文件.注意:如果你有多个网卡,可以把 public network 和cluster network 写入 Ceph 配置文件的 [global

Centos6.5下Ceph存储集群的搭建

简单介绍 Ceph的部署模式下主要包含以下几个类型的节点 ? Ceph OSDs: A Ceph OSD 进程主要用来存储数据,处理数据的replication,恢复,填充,调整资源组合以及通过检查其他OSD进程的心跳信息提供一些监控信息给Ceph Monitors . 当Ceph Storage Cluster 要准备2份数据备份时,要求至少有2个Ceph OSD进程的状态是active+clean状态 (Ceph 默认会提供两份数据备份). ? Monitors: Ceph Monitor

window环境搭建zookeeper,kafka集群

为了演示集群的效果,这里准备一台虚拟机(window 7),在虚拟机中搭建了单IP多节点的zookeeper集群(多IP节点的也是同理的),并且在本机(win 7)和虚拟机中都安装了kafka. 前期准备说明: 1.三台zookeeper服务器,本机安装一个作为server1,虚拟机安装两个(单IP) 2.三台kafka服务器,本机安装一个作为server1,虚拟机安装两个. 备注:当然你可以直接在虚拟机上安装三个服务器分别为server1.server2.server3 . 虚拟机和本机网络环