08/28/14

【salt】salt学习笔记

1、ZMQ版本小于3.2,升级问题
a、下载zeromq源码包,编译安装,但未成功,原因尚不完全清楚。
b、rpm包安装,升级也未成功,原因也不清楚。
c、通过网络发现可以通过yum的方式升级,于是更新yum的源,yum update更新成功。

2、机器太多,希望通过salt state sls批量更新
a、zmq.sls文件规则编写:

get_source_repo:
  cmd.run:
   - name: wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
   - unless: test -f /etc/yum.repos.d/ownsource.repo

zmq_update:
  pkg.installed:
   - pkgs:
     - zeromq: 3.2.2-13.1
     - libzmq3
     - python26-zmq: 13.1.0-1
   - require:
     - cmd:get_source_repo

salt-minion:
  service.running:
    - enable: True
    - watch:
      - pkg: zmq_update

b、执行:salt ‘*’ state.sls zmq
c、发现部分机器更新失败,报错信息:“The following package(s) were not found, and no possible matches were found in the package db: libzmq3, python26-zmq, zeromq”。
d、在更新失败机器手动升级,提示:“6/i386/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 – “The requested URL  returned error: 404″”。原因:机器是32位机器,源上面没有相应的问题。另寻他发升级。
e、执行失败提示:

[root@chen-123 salt]# salt 'local_18' state.sls zmq
local_18:
----------
          ID: get_source_repo
    Function: cmd.run
        Name: wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
      Result: True
     Comment: unless execution succeeded
     Changes:
----------
          ID: zmq_update
    Function: pkg.installed
      Result: False
     Comment: The following package(s) were not found, and no possible matches were found in the package db: libzmq3, python26-zmq, zeromq
     Changes:
----------
          ID: salt-minion
    Function: service.running
      Result: False
     Comment: One or more requisite failed
     Changes:

Summary
------------
Succeeded: 1
Failed:    2
------------
Total:     3

执行成功提示:

local_19:
----------
          ID: get_source_repo
    Function: cmd.run
        Name: wget -O /etc/yum.repos.d/ownsource.repo http://www.comingchina.com:8080/testing/ownsource/ownsource.repo
      Result: True
     Comment: unless execution succeeded
     Changes:
----------
          ID: zmq_update
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed and are at the desired version.
     Changes:
----------
          ID: salt-minion
    Function: service.running
      Result: True
     Comment: Service salt-minion is already enabled, and is in the desired state
     Changes:

Summary
------------
Succeeded: 3
Failed:    0
------------
Total:     3
08/19/14

【shell】清除nginx缓存目录下指定文件

描述:项目上线,运维一般会将样式、图片等文件缓存。上线初期经常需要更新样式文件,该脚本可以交由开发人员执行,减少运维工作量。

#! /bin/sh
#清除指定目录下,指定文件
#主要为了解决清除nginx缓存目录下的缓存文件
#link: blog.phpdba.com
#date: 2014-08-19
#author: chen-123

#Define Path
CACHE_DIR=/tmp/zaojiao.phpdba.com/
FILE="$*"

if [  "$#" -eq "0" ];then
        echo "Please Input clean File, Example: $0 index.html index.js style.css"
        sleep 2 && exit
fi
echo "The file : $FILE to be clean Cache ,please waiting ....."

for i in `echo $FILE`
do
        find ${CACHE_DIR} -name  $i > /tmp/cache_list.txt
        for j in `cat /tmp/cache_list.txt`
        do
                rm  -rf $j
                echo "$i $j is Deleted Success !"
        done
done

脚本下载链接:https://github.com/chen-123/phper/edit/master/cache_nginx.sh

08/19/14

【shell】批量删除缓存图片

描述:现在项目中有好多项目缓存了图片、样式等文件,动不动就10个G的级别

#/bin/sh
# 脚本用于批量删除指定目录下小文件
# link:blog.phpdba.com
# date: 2014-08-18
# author: chen-123

Base_Folder="/ask_d"
Folder='askques'
Old_Folder='askques_old'
Tmp_Folder='tmp'
Check_Old="yes"



if [ "`pwd`" != "$Base_Folder" ]
then
        echo "请将脚本放在"$Base_Folder"目录下执行"
        exit
fi


if [ -d $Tmp_Folder -a "`ls -A $Tmp_Folder`" != "" ]
then
        echo "请检查目录"$Tmp_Folder"是否为空目录"
fi

if [ -d $Old_Folder ]
then
        echo "目录存在"
        if [ "`ls -A $Old_Folder`" == "" ];then
                echo "$Old_Folder 是空目录,请重新执行一次"
                `rm -rf $Old_Folder`
        else
                Old_Size=`du -s ${Old_Folder}|awk '{print $1}'`

                if [ $Old_Size -ge 102400 ]
                then
                        echo $Old_Folder"目录比较大,请检查"
                        if [ "$Check_Old" != "yes" ]
                        then
                                if [ -d $Tmp_Folder ]
                                then
                                        rsync --delete-before -a -H -v --progress --stats $Base_Folder"/"$Tmp_Folder"/" $Base_Folder"/"$Old_Folder"/"
                                else
                                        echo "请确认"$Tmp_Folder"目录是否存在"
                                fi
                        fi
                else
                        echo "正在删除目录"$Old_Folder" ,请重新执行一次"
                        `rm -rf $Old_Folder`
                fi
        fi
else
        echo "目录不存在,创建目录"$Old_Folder
        `mv $Folder $Old_Folder && mkdir $Folder && chown -R apache:apache $Folder`
        if [ -d $Tmp_Folder ]
        then
                rsync --delete-before -a -H -v --progress --stats $Base_Folder"/"$Tmp_Folder"/" $Base_Folder"/"$Old_Folder"/"
                `rm -rf $Old_Folder`
        else
                echo "请确认"$Tmp_Folder"目录是否存在"
        fi
fi

脚本下载链接:https://github.com/chen-123/phper/edit/master/batch_delete_file.sh

08/17/14

对api.A.com部分地区访问故障的思考

总结:出现此故障及解决故障过程中暴露的问题,根本原因:信息共享机制缺失。

1、api.A.com 域名解析错误,除江苏电信之外,其他地区均出现故障。

a、个人猜测,应该是A.com所有子域名均cname到了lbe.B.net 。

b、dnspod上未配置api子域名或者配置错误。

2、运维对域名可用性跟踪问题

a、运维接收到配置需求之后,未做详细了解(何时用?用在哪里?怎么用?),直接配置。根据主管判断,api域名应该是php接口请求,故不放cdn加速。

b、配置好之后,未跟踪dns修改情况,主观认为域名需求发起方已经处理好。

3、项目问题

a、开发组未主动将项目情况,告知运维,导致发现该故障时,排查过程比较曲折。请开发也反思下,以后如何与运维更好的合作。

b、域名管理权限问题,能否将域名移交运维统一管理?

c、新版本上线之后,发现问题比较迟,为什么呢?请项目组与运维保持沟通,并积极关注和反馈应用情况,特别是新版本,新功能。 方便运维协助解决问题。

4、其他

a、工作中难免会出现问题,所以需要团队间互相协助。将出现问题的概率降低或者将故障周期最小化。

b、以上都是个人看法,不对的地方,请指正。谢谢!

08/6/14

【python】smtplib修改

描述:

1、qmail搭建了一套邮件系统,python通过smtp发送邮件,遇到发送失败。

2、排查发现smtplib.py 中authmethod 优先匹配了AUTH_CRAM_MD5

源代码:

# Authentication methods the server supports:
authlist = self.esmtp_features["auth"].split()

# List of authentication methods we support: from preferred to
# less preferred methods. Except for the purpose of testing the weaker
# ones, we prefer stronger methods like CRAM-MD5:
preferred_auths = [AUTH_CRAM_MD5, AUTH_PLAIN,AUTH_LOGIN,]

# Determine the authentication method we’ll use
authmethod = None
for method in preferred_auths:
if method in authlist:
authmethod = method
break

 

修改之后:

        # Authentication methods the server supports:
        authlist = self.esmtp_features["auth"].split()

        # List of authentication methods we support: from preferred to
        # less preferred methods. Except for the purpose of testing the weaker
        # ones, we prefer stronger methods like CRAM-MD5:
        preferred_auths = [AUTH_LOGIN, AUTH_CRAM_MD5, AUTH_PLAIN]

        # Determine the authentication method we'll use
        authmethod = None
        for method in preferred_auths:
            if method in authlist:
                authmethod = method
                break

 

修改之后邮件正常发送。