├── ops-scripts
├── zabbix
│ ├── zabbix_report_email
│ │ ├── requirements.txt
│ │ ├── default.docx
│ │ ├── README.md
│ │ ├── config.ini
│ │ └── report.py
│ └── zabbix_report_excel.py
├── plogstash
│ ├── README.md
│ └── plogstash.py
├── mkpasswd
│ └── mpass.sh
├── ip.txt
├── kuanpanshell
│ ├── run.sh
│ ├── OAuth.sh
│ └── kuaipan_uploader.sh
├── ipget.py
├── iozone_benchmark_fileio.sh
├── pstack.sh
├── devstack-start.sh
├── pptpd-centos6.sh
├── performance_tuning
│ ├── set_rps.sh
│ └── show-busy-java-threads.sh
├── nagios_install.sh
├── systeminit.sh
├── lua-ngx-log.md
├── migratetoconfluence.py
└── lnmp_install.sh
├── zabbix-templates
├── Template TCP
│ ├── README.txt
│ └── Template TCP Status.xml
├── Template UDP
│ ├── README.txt
│ └── Template UDP Status.xml
├── Template for Redis
│ ├── README.txt
│ └── redismonitor.sh
├── Template Percona MySQL
│ ├── README.txt
│ ├── scripts
│ │ └── get_mysql_stats_wrapper.sh
│ └── templates
│ │ └── userparameter_percona_mysql.conf
├── Template Linux Multi CPU Cores.xml
└── Template Generic Linux OS.xml
├── .gitmodules
├── README.md
├── 开源工具一览表.md
└── config
└── smokeping_config
/ops-scripts/zabbix/zabbix_report_email/requirements.txt:
--------------------------------------------------------------------------------
1 | ConfigParser
2 | python-docx
3 | email
4 |
--------------------------------------------------------------------------------
/zabbix-templates/Template TCP/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekwolf/sa-scripts/HEAD/zabbix-templates/Template TCP/README.txt
--------------------------------------------------------------------------------
/zabbix-templates/Template UDP/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekwolf/sa-scripts/HEAD/zabbix-templates/Template UDP/README.txt
--------------------------------------------------------------------------------
/zabbix-templates/Template for Redis/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekwolf/sa-scripts/HEAD/zabbix-templates/Template for Redis/README.txt
--------------------------------------------------------------------------------
/ops-scripts/zabbix/zabbix_report_email/default.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekwolf/sa-scripts/HEAD/ops-scripts/zabbix/zabbix_report_email/default.docx
--------------------------------------------------------------------------------
/zabbix-templates/Template Percona MySQL/README.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekwolf/sa-scripts/HEAD/zabbix-templates/Template Percona MySQL/README.txt
--------------------------------------------------------------------------------
/zabbix-templates/Template for Redis/redismonitor.sh:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geekwolf/sa-scripts/HEAD/zabbix-templates/Template for Redis/redismonitor.sh
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ops-scripts/zabbix/zabbix-weixin-picture"]
2 | path = ops-scripts/zabbix/zabbix-weixin-picture
3 | url = https://github.com/bluetom520/zabbix-weixin-picture.git
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | sa-scripts
2 | ==========
3 |
4 | scripts for linux
5 |
6 | @……@ Enjoy yourself
7 | 博客:http://www.simlinux.com
8 | By Geekwolf
9 |
10 | 
11 |
--------------------------------------------------------------------------------
/ops-scripts/plogstash/README.md:
--------------------------------------------------------------------------------
1 | #### 用途
2 |
3 | - 基于Redis List日志消息,归档日志文件
4 | - 解决Logstash(新版本单线程可解决)归档乱序问题
5 | - 架构: Filebeat->Redis->Plogstash->Files
6 | #### 用法:
7 | ```
8 | python3 plogstash.py
9 | Usage: plogstash.py [start|stop|restart|status]
10 | ```
11 |
--------------------------------------------------------------------------------
/ops-scripts/mkpasswd/mpass.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #pssh.txt:Host IP
3 | #Autor:Geekwolf
4 | while read line
5 | do
6 | a=`mkpasswd -l 16 -c 2 -C 2 -s 1 -v`
7 | echo -e "$line \t $a">>nowpassw.txt
8 | pssh -H $line -P -p 1 "echo $a|passwd --stdin root"
9 | echo $line
10 | done < pssh.txt
11 |
--------------------------------------------------------------------------------
/ops-scripts/zabbix/zabbix_report_email/README.md:
--------------------------------------------------------------------------------
1 | #### 版本
2 | ```
3 | Python2.7
4 | ```
5 | #### 安装依赖
6 | ```
7 | pip install -r requirements.txt
8 | ```
9 | #### 使用说明
10 | 1. 邮件图文告警
11 | 在Zabbix配置邮件发送告警脚本
12 | 2. 报表
13 | 在config.ini中graph配置info(要出报表的主机及对应的graphid)
14 | ```
15 | python report.py report
16 | ```
17 |
--------------------------------------------------------------------------------
/ops-scripts/zabbix/zabbix_report_email/config.ini:
--------------------------------------------------------------------------------
1 | [monitor]
2 | zbx_url = http://zbx.simlinux.com/
3 | graph_url = chart2.php
4 | item_graph_url = chart.php
5 | username = geekwolf
6 | password = geekwolf
7 | temp_dir = tmp
8 | log_file = zbx.log
9 |
10 | [graph]
11 | #显示执行时前一天的数据,报表使用
12 | period = 86400
13 | width = 580
14 | height = 600
15 | info = [{"name":"HOST1","graphids":[1304,1306,1301,1302]},{"name":"HOST2","graphids":[1296,1298,1293,1294]},{"name":"HOST3","graphids":[1247,1263,1251,1267]}]
16 |
17 | [ftp]
18 | host = 1.1.1.1
19 | port = 21
20 | username = ftpuser
21 | password = ftpuser
22 |
23 | [email]
24 | smtpserver = email.simlinux.com
25 | username = geekwolf@simlinux.com
26 | password = test
27 | port = 25
28 |
29 |
--------------------------------------------------------------------------------
/ops-scripts/ip.txt:
--------------------------------------------------------------------------------
1 | 101.226.102.97
2 | 101.226.33.200
3 | 101.226.33.205
4 | 101.226.33.208
5 | 101.226.33.219
6 | 101.226.33.223
7 | 101.226.33.226
8 | 101.226.33.228
9 | 101.226.33.237
10 | 101.226.33.238
11 | 101.226.65.108
12 | 101.226.66.172
13 | 101.226.66.175
14 | 101.226.66.179
15 | 101.226.66.181
16 | 101.226.66.21
17 | 101.226.89.116
18 | 101.226.89.117
19 | 101.226.89.120
20 | 101.226.89.123
21 | 112.64.235.247
22 | 112.64.235.252
23 | 112.64.235.89
24 | 112.64.235.90
25 | 112.65.193.15
26 | 180.153.163.187
27 | 180.153.201.15
28 | 180.153.201.212
29 | 180.153.201.215
30 | 180.153.201.216
31 | 180.153.201.66
32 | 180.153.205.254
33 | 180.153.206.13
34 | 180.153.206.18
35 | 180.153.206.21
36 | 180.153.206.22
37 | 180.153.206.23
38 | 180.153.206.25
39 | 180.153.206.27
40 | 180.153.206.29
41 | 180.153.206.31
42 | 180.153.206.36
43 | 180.153.206.38
44 | 180.153.214.176
45 | 180.153.214.190
46 | 180.153.214.191
47 | 222.73.76.253
48 |
--------------------------------------------------------------------------------
/ops-scripts/kuanpanshell/run.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | f=`date +%Y%m%d`
3 | mysqldump --opt --lock-tables=false -h127.0.0.1 -u"root" -p"root" initcom_einit09com > /home/initcom/backup-script/tmp/e_init09_com.sql
4 | mysqldump --opt --lock-tables=false -h127.0.0.1 -u"root" -p"root" initcom_wrdp1 > /home/initcom/backup-script/tmp/initcom_wrdp1.sql
5 | mysqldump --opt --lock-tables=false -h127.0.0.1 -u"root" -p"root" initcom_brainy > /home/initcom/backup-script/tmp/initcom_brainy.sql
6 | cd /home/initcom/backup-script/tmp/
7 | tar -czvf /home/initcom/backup-script/tmp/database_backup_$f.tar.gz /home/initcom/backup-script/tmp/*.sql
8 | echo 'Upload dropbox';
9 | filelist=`ls /home/initcom/backup-script/tmp/*.gz`
10 | for filename in $filelist
11 | do
12 | sleep 1s
13 | bash /home/initcom/backup-script/dropbox_uploader.sh upload $filename /backup/database_backup_$f.tar.gz
14 | done
15 | rm /home/initcom/backup-script/tmp/* -rf
16 | echo 'ok';
17 |
--------------------------------------------------------------------------------
/ops-scripts/ipget.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # coding=utf8
3 | # Author:Geekwolf
4 | # Blog:http://www.simlinux.com
5 | # Des:Get ip's owner
6 | # 可使用nali软件:https://qqwry.googlecode.com/files/nali-0.2.tar.gz
7 |
8 | import sys, urllib, simplejson
9 |
10 | #ip.txt格式每行一个ip
11 | file = open("ip.txt")
12 | for ip in file.readlines():
13 | ipstr=ip.split()[0]
14 | url='http://ip.taobao.com/service/getIpInfo.php?ip=%s' % ipstr
15 | f= urllib.urlopen(url).read()
16 | s= simplejson.loads(f)
17 | print ipstr+" \t "+s['data']['country']+s['data']['area']+s['data']['region']+s['data']['city']+s['data']['isp']
18 |
19 | file.close()
20 |
21 |
22 | #接收IP输入 python ipget.py 8.8.8.8
23 | #ip=sys.argv[1]
24 | #url='http://ip.taobao.com/service/getIpInfo.php?ip=%s' % ip
25 | #f= urllib.urlopen(url).read()
26 | #s= simplejson.loads(f)
27 | #print ip+" \t "+s['data']['country']+s['data']['area']+s['data']['region']+s['data']['city']+s['data']['isp']
28 |
29 |
--------------------------------------------------------------------------------
/ops-scripts/iozone_benchmark_fileio.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | ##
3 | ## 执行IOZONE 基准测试
4 | ##
5 |
6 |
7 | PATH=$PATH:/usr/local/bin
8 | export PATH
9 |
10 | #set -u
11 | #set -x
12 | #set -e
13 |
14 | # {{{ 各种参数
15 | WORKDIR=/data/iozone
16 | cd ${WORKDIR}
17 |
18 | exec 3>&1 4>&2 1>> iozone_benchmark_fileio-`date +'%Y%m%d%H%M%S'`.log 2>&1
19 |
20 | SLEEP_SEC=120
21 | #文件块大小:4 ~ 64k
22 | FILEIO_BLK_SIZE="4k 8k 16k"
23 | #每个文件大小:1 ~ 16G
24 | FILEIO_TOTAL_SIZE="1024M 2048M 4096M"
25 | #并发请求书:1 ~ 16
26 | NUM_THREADS="1 2 4 8 "
27 | #测试设备名,6SAS_RAID10意为6块SAS盘组成RAID 1+0,2SSD_RAID1意为2块SSD盘组成RAID 1
28 | #DEVICE="6SAS_RAID10"
29 | DEVICE="2SAS_RAID1"
30 |
31 | # }}}
32 |
33 | # {{{ SLEEP
34 | SLEEP()
35 | {
36 | sleep $SLEEP_SEC
37 | }
38 | # }}}
39 |
40 | # {{{ MUTEX
41 | FILEIO()
42 | {
43 | for FILEIO_SIZE in ${FILEIO_TOTAL_SIZE}
44 | do
45 | for FILEIO_BLK in ${FILEIO_BLK_SIZE}
46 | do
47 | for THREADS in ${NUM_THREADS}
48 | do
49 | iozone -R -E -s ${FILEIO_SIZE} -l ${THREADS} -r ${FILEIO_BLK} >> iozone_{${DEVICE}}_R_E_s_{${FILEIO_SIZE}}_l_{${THREADS}}_r_{${FILEIO_BLK}}_{`date +'%Y%m%d%H%M%S'`}.log
50 | done
51 | done
52 | done
53 | }
54 | # }}}
55 |
56 | #while [ 1 ]
57 | #do
58 |
59 | FILEIO
60 | SLEEP
61 |
62 |
63 | #done
64 |
--------------------------------------------------------------------------------
/ops-scripts/pstack.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if test $# -ne 1; then
4 | echo "Usage: `basename $0 .sh` " 1>&2
5 | exit 1
6 | fi
7 |
8 | if test ! -r /proc/$1; then
9 | echo "Process $1 not found." 1>&2
10 | exit 1
11 | fi
12 |
13 | # GDB doesn't allow "thread apply all bt" when the process isn't
14 | # threaded; need to peek at the process to determine if that or the
15 | # simpler "bt" should be used.
16 |
17 | backtrace="bt"
18 | if test -d /proc/$1/task ; then
19 | # Newer kernel; has a task/ directory.
20 | if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
21 | backtrace="thread apply all bt"
22 | fi
23 | elif test -f /proc/$1/maps ; then
24 | # Older kernel; go by it loading libpthread.
25 | if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
26 | backtrace="thread apply all bt"
27 | fi
28 | fi
29 |
30 | GDB=${GDB:-/usr/bin/gdb}
31 |
32 | if $GDB -nx --quiet --batch --readnever > /dev/null 2>&1; then
33 | readnever=--readnever
34 | else
35 | readnever=
36 | fi
37 |
38 | # Run GDB, strip out unwanted noise.
39 | $GDB --quiet $readnever -nx /proc/$1/exe $1 <&1 |
40 | $backtrace
41 | EOF
42 | /bin/sed -n \
43 | -e 's/^(gdb) //' \
44 | -e '/^#/p' \
45 | -e '/^Thread/p'
--------------------------------------------------------------------------------
/zabbix-templates/Template Percona MySQL/scripts/get_mysql_stats_wrapper.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # The wrapper for Cacti PHP script.
3 | # It runs the script every 5 min. and parses the cache file on each following run.
4 | # Version: 1.1.6
5 | #
6 | # This program is part of Percona Monitoring Plugins
7 | # License: GPL License (see COPYING)
8 | # Copyright: 2016 Percona
9 | # Authors: Roman Vynar
10 |
11 | ITEM=$1
12 | HOST=localhost
13 | DIR=`dirname $0`
14 | CMD="/usr/bin/php -q $DIR/ss_get_mysql_stats.php --host $HOST --items gg"
15 | CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt"
16 |
17 | USER='dba_monitor'
18 | PASS='xxxx'
19 |
20 | if [ "$ITEM" = "running-slave" ]; then
21 | # Check for running slave
22 | RES=`HOME=~zabbix mysql -h localhost -u $USER -p$PASS -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
23 | if [ "$RES" = " Yes, Yes," ]; then
24 | echo 1
25 | else
26 | echo 0
27 | fi
28 | exit
29 | elif [ -e $CACHEFILE ]; then
30 | # Check and run the script
31 | TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt`
32 | TIMENOW=`date +%s`
33 | if [ `expr $TIMENOW - $TIMEFLM` -gt 300 ]; then
34 | rm -f $CACHEFILE
35 | $CMD 2>&1 > /dev/null
36 | fi
37 | else
38 | $CMD 2>&1 > /dev/null
39 | fi
40 |
41 | # Parse cache file
42 | if [ -e $CACHEFILE ]; then
43 | cat $CACHEFILE | sed 's/ /\n/g; s/-1/0/g'| grep $ITEM | awk -F: '{print $2}'
44 | else
45 | echo "ERROR: run the command manually to investigate the problem: $CMD"
46 | fi
47 |
--------------------------------------------------------------------------------
/ops-scripts/devstack-start.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | Author:Geekwolf
3 | Blog:http://www.simlinux.com
4 |
5 | rm -rf /var/log/nova/*.log
6 | mkdir /var/log/nova/
7 | service mysqld start
8 | service rabbitmq-server start
9 |
10 | /usr/bin/glance-registry --config-file=/etc/glance/glance-registry.conf > /var/log/nova/glance-registry.log 2>&1 &
11 |
12 | /usr/bin/glance-api --config-file=/etc/glance/glance-api.conf > /var/log/nova/glance-api.log 2>&1 &
13 | echo "Waiting for g-api to start..."
14 | if ! timeout 60 sh -c "while ! wget --no-proxy -q -O- http://127.0.0.1:9292;
15 | do sleep 1; done"; then
16 | echo "g-api did not start"
17 | exit 1
18 | fi
19 | echo "Done."
20 |
21 | /usr/bin/keystone-all --config-file /etc/keystone/keystone.conf --log-config /etc/keystone/logging.conf -d --debug > /var/log/nova/keystone-all.log 2>&1 &
22 | echo "Waiting for keystone to start..."
23 | if ! timeout 60 sh -c "while ! wget --no-proxy -q -O- http://127.0.0.1:5000;
24 | do sleep 1; done"; then
25 | echo "keystone did not start"
26 | exit 1
27 | fi
28 | echo "Done."
29 |
30 | /usr/bin/cinder-api --config-file /etc/cinder/cinder.conf > /var/log/nova/cinder-api.log 2>&1 &
31 |
32 | /usr/bin/cinder-volume --config-file /etc/cinder/cinder.conf > /var/log/nova/cinder-volume.log 2>&1 &
33 |
34 | /usr/bin/cinder-scheduler --config-file /etc/cinder/cinder.conf > /var/log/nova/cinder-scheduler.log 2>&1 &
35 |
36 | /usr/bin/nova-api > /var/log/nova/nova-api.log 2>&1 &
37 | echo "Waiting for nova-api to start..."
38 | if ! timeout 60 sh -c "while ! wget --no-proxy -q -O- http://127.0.0.1:8774;
39 | do sleep 1; done"; then
40 | echo "nova-api did not start"
41 | exit 1
42 | fi
43 | echo "Done."
44 |
45 | /usr/bin/nova-scheduler > /var/log/nova/nova-scheduler.log 2>&1 &
46 |
47 | /usr/bin/nova-cert > /var/log/nova/nova-cert.log 2>&1 &
48 |
49 | /usr/bin/nova-objectstore > /var/log/nova/nova-objectstore.log 2>&1 &
50 |
51 | /usr/bin/nova-network > /var/log/nova/nova-network.log 2>&1 &
52 |
53 | /usr/bin/nova-compute > /var/log/nova/nova-compute.log 2>&1 &
54 |
55 | /opt/stack/noVNC/utils/nova-novncproxy --config-file /etc/nova/nova.conf --web . > /var/log/nova/nova-novncproxy.log 2>&1 &
56 |
57 | /usr/bin/nova-xvpvncproxy --config-file /etc/nova/nova.conf > /var/log/nova/nova-xvpvncproxy.log 2>&1 &
58 |
59 | /usr/bin/nova-consoleauth > /var/log/nova/nova-consoleauth.log 2>&1 &
60 |
61 | service httpd restart
62 |
--------------------------------------------------------------------------------
/ops-scripts/pptpd-centos6.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | function installVPN(){
4 | echo "begin to install VPN services";
5 | #check wether vps suppot ppp and tun
6 |
7 | yum remove -y pptpd ppp
8 | iptables --flush POSTROUTING --table nat
9 | iptables --flush FORWARD
10 | rm -rf /etc/pptpd.conf
11 | rm -rf /etc/ppp
12 |
13 | arch=`uname -m`
14 |
15 | wget http://www.hi-vps.com/downloads/dkms-2.0.17.5-1.noarch.rpm
16 | wget http://wty.name/linux/sources/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
17 | wget http://www.hi-vps.com/downloads/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
18 | wget http://www.hi-vps.com/downloads/pptpd-1.3.4-2.el6.$arch.rpm
19 | wget http://www.hi-vps.com/downloads/ppp-2.4.5-17.0.rhel6.$arch.rpm
20 |
21 |
22 | yum -y install make libpcap iptables gcc-c++ logrotate tar cpio perl pam tcp_wrappers
23 | rpm -ivh dkms-2.0.17.5-1.noarch.rpm
24 | rpm -ivh kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
25 | rpm -qa kernel_ppp_mppe
26 | rpm -Uvh ppp-2.4.5-17.0.rhel6.$arch.rpm
27 | rpm -ivh pptpd-1.3.4-2.el6.$arch.rpm
28 |
29 | mknod /dev/ppp c 108 0
30 | echo 1 > /proc/sys/net/ipv4/ip_forward
31 | echo "mknod /dev/ppp c 108 0" >> /etc/rc.local
32 | echo "echo 1 > /proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
33 | echo "localip 172.16.36.1" >> /etc/pptpd.conf
34 | echo "remoteip 172.16.36.2-254" >> /etc/pptpd.conf
35 | echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
36 | echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd
37 |
38 | pass=`openssl rand 6 -base64`
39 | if [ "$1" != "" ]
40 | then pass=$1
41 | fi
42 |
43 | echo "vpn pptpd ${pass} *" >> /etc/ppp/chap-secrets
44 |
45 | iptables -t nat -A POSTROUTING -s 172.16.36.0/24 -j SNAT --to-source `ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}'`
46 | iptables -A FORWARD -p tcp --syn -s 172.16.36.0/24 -j TCPMSS --set-mss 1356
47 | service iptables save
48 |
49 | chkconfig iptables on
50 | chkconfig pptpd on
51 |
52 | service iptables start
53 | service pptpd start
54 |
55 | echo "VPN service is installed, your VPN username is vpn, VPN password is ${pass}"
56 |
57 | }
58 |
59 | function repaireVPN(){
60 | echo "begin to repaire VPN";
61 | mknod /dev/ppp c 108 0
62 | service iptables restart
63 | service pptpd start
64 | }
65 |
66 | function addVPNuser(){
67 | echo "input user name:"
68 | read username
69 | echo "input password:"
70 | read userpassword
71 | echo "${username} pptpd ${userpassword} *" >> /etc/ppp/chap-secrets
72 | service iptables restart
73 | service pptpd start
74 | }
75 |
76 | echo "which do you want to?input the number."
77 | echo "1. install VPN service"
78 | echo "2. repaire VPN service"
79 | echo "3. add VPN user"
80 | read num
81 |
82 | case "$num" in
83 | [1] ) (installVPN);;
84 | [2] ) (repaireVPN);;
85 | [3] ) (addVPNuser);;
86 | *) echo "nothing,exit";;
87 | esac
88 |
--------------------------------------------------------------------------------
/ops-scripts/performance_tuning/set_rps.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | ### BEGIN INIT INFO
4 | # Provides: set_rps
5 | # Required-Start: $remote_fs $network $time $syslog
6 | # Required-Stop: $remote_fs $network $syslog
7 | # Default-Start: 2 3 4 5
8 | # Default-Stop: 0 1 6
9 | # Short-Description: Set rps
10 | # Description: Script for open rps
11 | ### END INIT INFO
12 | #
13 |
14 | RETCODE=0
15 |
16 | # kernel version must be >= 2.6.37
17 | kernel_ver=`uname -r`
18 | case "$kernel_ver" in
19 | 2.6.*)
20 | kernel_ver=`uname -r|sed -n 's/2.6.\([0-9]\+\).*/\1/p'`
21 | [ -z $kernel_ver ] && echo "$0:Kernel version is not 2.6.x, no need to run this script." && exit 0
22 | [ $kernel_ver -lt 37 ] && echo "$0:Kernel version is lower than 2.6.37, no need to run this script." && exit 9
23 | ;;
24 | 3.*|4.*)
25 | :
26 | ;;
27 | *)
28 | echo "Kernel version unsupport."
29 | exit $RETCODE
30 | ;;
31 | esac
32 |
33 | # get cpu count
34 | cpu_count=`head -n1 /proc/interrupts|awk '{print NF}'`
35 |
36 | # get interface name
37 | interfaces=`route -n | awk 'NR>2 && !a[$NF]++{print $NF}' | grep '^eth[0-9.]\+\|bond[0-9.]\+$'`
38 |
39 | set_rps(){
40 | interface="$@"
41 |
42 | #convert cpu_bits into hex format: 10 -> 16
43 | rps_cpus=`printf "%x" $((2**$cpu_count-1))`
44 | rps_flow_cnt=4096
45 | rps_sock_flow_entries=0
46 | for int in $interface
47 | do
48 | for rxdir in /sys/class/net/"$int"/queues/rx-*
49 | do
50 | echo $rps_cpus >$rxdir/rps_cpus
51 | echo $rps_flow_cnt >$rxdir/rps_flow_cnt
52 | rps_sock_flow_entries=$(($rps_sock_flow_entries+$rps_flow_cnt))
53 | done
54 | done
55 | echo $rps_sock_flow_entries >/proc/sys/net/core/rps_sock_flow_entries
56 | }
57 |
58 | clr_rps(){
59 | interface="$@"
60 | for int in $interface
61 | do
62 | for rxdir in /sys/class/net/"$int"/queues/rx-*
63 | do
64 | echo 0 >$rxdir/rps_cpus
65 | echo 0 >$rxdir/rps_flow_cnt
66 | done
67 | done
68 | echo 0 >/proc/sys/net/core/rps_sock_flow_entries
69 | }
70 |
71 | dsp_rps(){
72 | interface="$@"
73 | for int in $interface
74 | do
75 | for rxdir in /sys/class/net/"$int"/queues/rx-*
76 | do
77 | awk '{print FILENAME,$0}' $rxdir/rps_cpus
78 | awk '{print FILENAME,$0}' $rxdir/rps_flow_cnt
79 | done
80 | done
81 | awk '{print FILENAME,$0}' /proc/sys/net/core/rps_sock_flow_entries
82 | }
83 |
84 | case $1 in
85 | start)
86 | set_rps $interfaces
87 | ;;
88 | stop)
89 | clr_rps $interfaces
90 | ;;
91 | status)
92 | dsp_rps $interfaces
93 | ;;
94 | *)
95 | echo "Usage: $0 [start|stop|status]"
96 | ;;
97 | esac
98 |
--------------------------------------------------------------------------------
/ops-scripts/nagios_install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #Welcome to NAGIOS for CentOS6.x Installation!
3 | #This Installation Released Geekwolf
4 | #Author:Geekwolf
5 | #Date:2013-06-14
6 | #Blog:www.linuxhonker.com
7 |
8 | function Nagios_Install(){
9 | yum -y install gcc gcc-c++ glibc glibc-common gd gd-devel httpd-tools
10 | useradd nagios
11 | groupadd nagcmd
12 | usermod -G nagcmd nagios
13 | #将web用户加入nagcmd组
14 | usermod -G nagcmd nobody
15 | mkdir /usr/src/nagios
16 | cd /usr/src/nagios
17 | wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz
18 | wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz
19 | wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz?r=http%3A%2F%2Fexchange.nagios.org%2Fdirectory%2FAddons%2FMonitoring-Agents%2FNRPE--2D-Nagios-Remote-Plugin-Executor%2Fdetails&ts=1371189057&use_mirror=nchc
20 | tar zxvf nagios-3.5.0.tar.gz
21 | cd nagios
22 | ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
23 | make all
24 | make install
25 | make install-init
26 | make install-config
27 | make install-commandmode
28 | make install-webconf
29 | cd ../
30 | tar zxvf nagios-plugins-1.4.16.tar.gz
31 | cd nagios-plugins-1.4.16
32 | ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
33 | make && make install
34 | cd ../
35 | tar zxvf nrpe-2.14.tar.gz
36 | cd nrpe-2.14
37 | ./configure
38 | make all
39 | make install-plugin
40 | make install-daemon
41 | make install-daemon-config
42 |
43 | htpasswd -bc /usr/local/nagios/etc/htpasswd nagiosadmin nagiosadmin
44 | echo "alias nagioscheck='/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'" >>/etc/bashrc
45 | source /etc/bashrc
46 |
47 | chkconfig nagios on
48 | service nagios start
49 |
50 | cat >>/usr/local/nginx/conf/nginx.conf <
3 | WeiXin: Geekwolf
4 | ##### 欢迎补充~
5 |
6 |
7 | **Bootstrapping:** [云霁X86装机工具](http://github.com/idcos/osinstall)、Kickstart、Cobbler、rpmbuild/xen、kvm、lxc、Openstack、 Cloudstack、Opennebula、Eucalyplus、RHEV
8 | **配置类工具:** Capistrano、Chef、puppet、func、salstack、Ansible、rundeck、CFengine、Rudder
9 | **web管理平台:** [Redis云管理平台-CacheCloud](https://github.com/sohutv/cachecloud)
10 | **自动化构建和测试:** Ant、Maven、Selenium、PyUnit、QUnit、JMeter、Gradle、PHPUnit
11 | **监控类工具:** Cacti、Nagios(Icinga)、Zabbix([模板大全](https://monitoringartist.github.io/zabbix-searcher/))、基于时间监控前端Grafana、Mtop、MRTG(网络流量监控图形工具)、[Monit](https://mmonit.com/) 、Diamond+Graphite+Grafana、[netdata](https://my-netdata.io/)
12 | **微服务平台:** OpenShift、Cloud Foundry、Kubernetes、Mesosphere
13 | **性能监控工具:** dstat(多类型资源统计)、atop(htop/top)、nmon(类Unix系统性能监控)、slabtop(内核slab缓存信息)、sar(性能监控和瓶颈检查)、sysdig(系统进程高级视图)、tcpdump(网络抓包)、iftop(类似top的网络连接工具)、iperf(网络性能工具)、smem)(高级内存报表工具)、collectl(性能监控工具)、[TCP优化监控工具tcpdive](https://github.com/fastos/tcpdive)
14 | **响应时间统计工具:** [tcprstat](https://github.com/Lowercases/tcprstat)
15 | **免费APM工具:** [mmtrix(见过的最全面的分析工具)](http://www.mmtrix.com/evaluate/result)、[alibench](http://alibench.com/)、[JAVA性能监控pinpoint](https://github.com/naver/pinpoint)、[cat](https://github.com/dianping/cat)、[skywalking](http://skywalking.org/)、[UAVStack](https://uavorg.github.io/main/)、[Google Opencensus](http://opencensus.io/)、[OpenZipkin](https://zipkin.io/)
16 | **进程监控:** [mmonit](http://mmonit.com/monit/documentation/monit.html)、Supervisor、[frigga](https://github.com/xiaomi-sa/frigga)、 [StrongLoop Process Manager](http://strong-pm.io/compare/)
17 | **日志系统:** Logstash、Scribe、Graylog、ELKStack
18 | **绘图工具:** RRDtool、Gnuplot
19 | **流量监控:** iptraf、nload、ifstat、iftop、ntop、mtr、vnstat
20 | **数据库可视化:** zeppelin、metabase、Heka、redash、superset
21 | **流控系统:** Panabit、[在线数据包分析工具Pcap Analyzer](http://le4f.net/post/post/pcap-online-analyzer)
22 | **安全检查:** chrootkit、rkhunter
23 | **PaaS:** Cloudify、Cloudfoundry、Openshift、[Deis](http://www.deis.io/) (Docker、CoreOS、[Atomic](https://access.redhat.com/articles/rhel-atomic-getting-started)、[ubuntu core/Snappy](http://www.ubuntu.com/cloud/tools/snappy)、[RancherOS](http://rancher.com))、[DomeOS](http://domeos.org)、[Rainbond](http://www.rainbond.com/)
24 | **Troubleshooting:**[Sysdig](http://www.sysdig.org/) 、Systemtap、Perf
25 | **服务发现:** [SmartStack](http://nerds.airbnb.com)、etcd
26 | **持续集成:** [Go](http://www.go.cd)、Jenkins、Gitlab、[facebook代码审查工具phabricator](http://phabricator.org/)、[spinnaker](http://spinnaker.io/)、[PHP代码持续集成工具PHPCI](https://www.phptesting.org)
27 | **APP CD:** [fastlane](https://fastlane.tools/#tools)、[xcode_shell](https://github.com/webfrogs/xcode_shell.git)、[xctool](https://github.com/facebook/xctool.git)
28 | **磁盘压测:** fio、iozone、IOMeter(win)
29 | **Memcache** [Mcrouter(scaling memcached)](https://github.com/facebook/mcrouter)
30 | **Redis** [Dynomite](https://github.com/Netflix/dynomite)、Twemproxy、codis/SSDB/Aerospike、Redis Cluster
31 | **MySQL 监控:** mytop、orzdba、Percona-toolkit、Maatkit、[Percona-PMM(包含Grafana)](https://www.percona.com/software/database-tools/percona-monitoring-and-management)、[innotop](http://www.percona.com/blog/2013/10/14/innotop-real-time-advanced-investigation-tool-mysql/)、[myawr](https://github.com/noodba/myawr)、[SQL级监控mysqlpcap](https://github.com/hoterran/tcpcollect)、[拓扑可视化工具](https://github.com/outbrain/orchestrator)
32 | **MySQL基准测试:** mysqlsla、sql-bench、Super Smack、Percona's TPCC-MYSQL Tool、sysbench
33 | **MySQL Proxy:** [SOHU-DBProxy](https://github.com/SOHUDBA/SOHU-DBProxy)、[Mycat](http://www.mycat.org.cn/)、[Altas](https://github.com/Qihoo360/Atlas)、[cobar](https://github.com/alibaba/cobar)、[58同城Oceanus](https://github.com/58code/Oceanus)、[kingshard](https://github.com/flike/kingshard)
34 | **MySQL逻辑备份工具**: mysqldump、mysqlhotcopy、mydumper、MySQLDumper 、mk-parallel-dump/mk-parallel-restore
35 | **MySQL物理备份工具**: Xtrabackup、LVM Snapshot
36 | **MongoDB压测:** [iibench&sysbench](https://github.com/tmcallaghan)
37 | **数据库管理:** [数据库迁移工具flyway](https://flywaydb.org/)、表结构对比工具sqllog
38 | **大数据管理套件: ** [Ambari](http://incubator.apache.org/ambari/)、[Cloudera Manger(CDH)](https://www.cloudera.com)
39 | #### DevOps Tool
40 | **开源运维系统:** [autoops](https://github.com/hequan2017/autoops)、[OpsManage](https://github.com/welliamcao/OpsManage)、[opman-django](https://github.com/hgz6536/opman-django)
41 | **CMDB:** [CMDB(hequan)](https://github.com/pengzihe/cmdb)、[CMDB(voilet)](https://github.com/voilet/cmdb)、[roncoo-cmdb](https://github.com/roncoo/roncoo-cmdb)
42 | **故障管理&监控二次开发:** [fms](https://github.com/geekwolf/fms)
43 |
--------------------------------------------------------------------------------
/ops-scripts/performance_tuning/show-busy-java-threads.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # @Function
3 | # Find out the highest cpu consumed threads of java, and print the stack of these threads.
4 | #
5 | # @Usage
6 | # $ ./show-busy-java-threads.sh
7 | #
8 | # @author Jerry Lee
9 |
10 | readonly PROG=`basename $0`
11 | readonly -a COMMAND_LINE=("$0" "$@")
12 |
13 | usage() {
14 | local out
15 | [ -n "$1" -a "$1" != 0 ] && out=/dev/stderr || out=/dev/stdout
16 |
17 | > $out cat < /dev/null; then
91 | [ -z "$JAVA_HOME" ] && {
92 | redEcho "Error: jstack not found on PATH!" 1>&2
93 | exit 1
94 | }
95 | ! [ -f "$JAVA_HOME/bin/jstack" ] && {
96 | redEcho "Error: jstack not found on PATH and \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) file does NOT exists!" 1>&2
97 | exit 1
98 | }
99 | ! [ -x "$JAVA_HOME/bin/jstack" ] && {
100 | redEcho "Error: jstack not found on PATH and \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) is NOT executalbe!" 1>&2
101 | exit 1
102 | }
103 | export PATH="$JAVA_HOME/bin:$PATH"
104 | fi
105 |
106 | readonly uuid=`date +%s`_${RANDOM}_$$
107 |
108 | cleanupWhenExit() {
109 | rm /tmp/${uuid}_* &> /dev/null
110 | }
111 | trap "cleanupWhenExit" EXIT
112 |
113 | printStackOfThreads() {
114 | local line
115 | local counter=1
116 | while IFS=" " read -a line ; do
117 | local pid=${line[0]}
118 | local threadId=${line[1]}
119 | local threadId0x="0x`printf %x ${threadId}`"
120 | local user=${line[2]}
121 | local pcpu=${line[4]}
122 |
123 | local jstackFile=/tmp/${uuid}_${pid}
124 | [ ! -f "${jstackFile}" ] && {
125 | {
126 | if [ "${user}" == "${USER}" ]; then
127 | jstack ${force} ${pid} > ${jstackFile}
128 | elif [ $UID == 0 ]; then
129 | sudo -u "${user}" jstack ${force} ${pid} > ${jstackFile}
130 | else
131 | redEcho "[$((counter++))] Fail to jstack Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
132 | redEcho "User of java process($user) is not current user($USER), need sudo to run again:"
133 | yellowEcho " sudo ${COMMAND_LINE[@]}"
134 | echo
135 | continue
136 | fi
137 | } || {
138 | redEcho "[$((counter++))] Fail to jstack Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user})."
139 | echo
140 | rm ${jstackFile}
141 | continue
142 | }
143 | }
144 |
145 | blueEcho "[$((counter++))] Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user}):"
146 | sed "/nid=${threadId0x} /,/^$/p" -n ${jstackFile}
147 | done
148 | }
149 |
150 |
151 | ps -Leo pid,lwp,user,comm,pcpu --no-headers | {
152 | [ -z "${pid}" ] &&
153 | awk '$4=="java"{print $0}' ||
154 | awk -v "pid=${pid}" '$1==pid,$4=="java"{print $0}'
155 | } | sort -k5 -r -n | head --lines "${count}" | printStackOfThreads
156 |
--------------------------------------------------------------------------------
/ops-scripts/systeminit.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | <<<<<<< HEAD
3 | #blog:www.linuxhonker.com
4 | =======
5 | #Modify by Geekwolf
6 | #Blog:http://www.linuxhonker.com
7 | #CentOS6.4 x64 system initalization script
8 | #Release:1.0
9 | #适合测试环境:最小化安装Centos6.4 X64
10 | cat << EOF
11 | +---------------------------------------+
12 | | CentOS6.4 x64 system initalization |
13 | | start optimizing....... |
14 | +---------------------------------------
15 | EOF
16 | #修改默认yum源,更改为163或者sohu
17 | rm -rf /etc/yum.repo.d/*
18 | wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo
19 | #增加EPEL源(很多常用的软件,是专门针对RHEL的一个补充)
20 | rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
21 | rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
22 | #增加RPMForge源,是CentOS推荐的源
23 | rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
24 | rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
25 | rm -rf /etc/yum.repo.d/mirrors*
26 | rm -rf /etc/yum.repo.d/epel-testing.repo
27 | #安装yum -y install priorities,用于配置调用yum源时的优先级,此处设置CentOS-Base.repo源优先级最高
28 | #(priority=[1],1为最高,99为最低)
29 | sed -i 's#^gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#& \npriority=1#g' /etc/yum.repos.d/CentOS-Base.repo
30 | sed -i 's#^gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6#& \npriority=2#g' /etc/yum.repos.d/epel.repo
31 | sed -i 's#^gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag#& \npriority=3#g' /etc/yum.repos.d/rpmforge.repo
32 | /usr/bin/yum makecache
33 |
34 | cat << EOF
35 | +---------------------------------------+
36 | | SNMP Monitor & sysstat |
37 | | install....... |
38 | +---------------------------------------
39 | EOF
40 | #安装net-snmp,sysstat
41 | yum -y install net-snmp sysstat vim >/dev/null 2>&1
42 | echo "alias vi='vim'">>/etc/bashrc
43 | echo "\033[40;33mSNMP&Sysstat has been installed!\n \033[0m"
44 |
45 | sed -i -e s#'com2sec notConfigUser default public'#'com2sec notConfigUser 192.168.1.73 public'#g /etc/snmp/snmpd.conf
46 | echo 'pass .1.3.6.1.3.1 /usr/bin/perl /usr/local/bin/iostat.pl'>/etc/snmp/snmpd.conf
47 | /sbin/service snmpd restart
48 | echo -e "\033[40;33mSNMP Start Sucessfully!\n \033[0m"
49 |
50 | #sync time
51 | yum -y install ntp at
52 | echo "0 0 * * * root /usr/sbin/ntpdate ntp.fudan.edu.cn;hwclock -w">>/etc/crontab
53 | /usr/sbin/ntpdate ntp.fudan.edu.cn;hwclock -w
54 | #设置默认字符集语言字体等
55 | cat >/etc/sysconfig/i18n <> /etc/security/limits.conf <> /etc/sysctl.conf << EOF
72 | net.ipv4.tcp_syncookies = 1
73 | net.ipv4.tcp_syn_retries = 1
74 | net.ipv4.tcp_tw_recycle = 1
75 | net.ipv4.tcp_tw_reuse = 1
76 | net.ipv4.tcp_fin_timeout = 1
77 | net.ipv4.tcp_keepalive_time = 1200
78 | net.ipv4.ip_local_port_range = 1024 65535
79 | EOF
80 | /sbin/sysctl -p
81 |
82 | #禁止ipv6
83 | sysctl -w net.ipv6.conf.all.disable_ipv6=1 >/dev/null 2>&1
84 |
85 | #ssh默认端口更改
86 | sed -i 's#\#Port 22#Port 22222#' /etc/ssh/sshd_config
87 | sed -i 's#\#Banner none#Banner /etc/ssh/banner#' /etc/ssh/sshd_config
88 | echo "Welcome to the TWOS! Proceed with caution!">/etc/ssh/banner
89 | /sbin/service sshd restart
90 | echo -e "\033[40;33mSSH Port has been changed to 22222!!\n \033[0m"
91 |
92 | #tcpwrapper配置
93 | cat >> /etc/hosts.allow <>/etc/hosts.deny
97 | sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config
98 |
99 | #关闭ipv6tables并配置iptables
100 | echo "alias net-pf-10 off">>/etc/modprobe.conf
101 | echo "alias ipv6 off" >>/etc/modprobe.conf
102 | /sbin/chkconfig ip6tables off
103 | echo "\033[40;33mDisable Ipv6 set OK!!\n \033[0m"
104 |
105 | IPTABLES=/sbin/iptables
106 | ICMP_IP=222.111.111.111/32
107 | SSH_IP=222.111.111.111/32
108 |
109 | $IPTABLES -F
110 | $IPTABLES -X
111 | $IPTABLES -Z
112 | $IPTABLES -P INPUT DROP
113 | $IPTABLES -P FORWARD DROP
114 | $IPTABLES -P OUTPUT ACCEPT
115 | $IPTABLES -A INPUT -m state --stat RELATED,ESTABLISHED -j ACCEPT
116 | #124.172.207.192/27为IDC监控机IP
117 | $IPTABLES -A INPUT -i lo -j ACCEPT
118 |
119 | $IPTABLES -A INPUT -s $ICMP_IP -p icmp -j ACCEPT
120 | $IPTABLES -A INPUT -s $SSH_IP -p tcp -m tcp --dport 22222 -j ACCEPT
121 | #$IPTABLES -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
122 | echo -e "\033[40;33mTcpwrapper&Iptables&Selinux set OK!!\n \033[0m"
123 |
124 | #删除不必要的账户
125 | NO_USERS='adm lp news uucp operator sync ftp gopher games postfix'
126 | for i in $NO_USERS
127 | do
128 | userdel $i
129 | done
130 |
131 | #关闭不比要的服务
132 | NO_SERVICES='cups ip6tables netfs nslock postfix'
133 | for j in $NO_SERVICES
134 | do
135 | chkconfig --level 012345 $j off
136 | done
137 | #设置历史命令条数
138 | echo "HISTSIZE=200">>/etc/profile
139 | >>>>>>> b1887acdae07f76fc9be3f19c8496d142f4b0318
140 |
--------------------------------------------------------------------------------
/ops-scripts/lua-ngx-log.md:
--------------------------------------------------------------------------------
1 | #### 1. install softs
2 |
3 | ```
4 | wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
5 | wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
6 | wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1.tar.gz
7 | wget https://openresty.org/download/openresty-1.15.8.1.tar.gz
8 | ```
9 | #### 2. install openrestry luajit2 lib
10 | ```
11 | ./configure --prefix=/user/local/openresty-1.15.8.1
12 | make
13 | make install
14 | ln -s /usr/local/openresty-1.15.8.1/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
15 | export LUAJIT_LIB=/usr/local/openresty-1.15.8.1/luajit/lib/
16 | export LUAJIT_INC=/usr/local/openresty-1.15.8.1/luajit/include/luajit-2.1/
17 |
18 | ```
19 | #### 3. install tengine
20 |
21 | ```
22 | ./configure --prefix=/usr/local/tengine/ --with-http_gzip_static_module --add-module=/data/data/softs/lua-nginx-module-0.10.15/ --add-module=/data/data/softs/ngx_devel_kit-0.3.1/
23 | make
24 | make install
25 | ```
26 |
27 | #### 4. Nginx Configure: log_by_lua_file
28 | ```
29 | log_by_lua_file /usr/local/tengine/conf/lua/ngx_log.lua;
30 | ```
31 |
32 | ### 5. ngx_log.lua
33 | ```
34 |
35 |
36 | -- local file_name
37 |
38 | -- if ngx.var.file_type == 'audit' then
39 | -- file_name = '/usr/local/apps/nginx/logs/audit.log'
40 | -- elseif ngx.var.file_type == 'mapi'then
41 | -- file_name = '/usr/local/apps/nginx/logs/access.log'
42 | -- end
43 |
44 |
45 | local file_audit = '/usr/local/apps/nginx/logs/audit.log'
46 | local file_mapi = '/usr/local/apps/nginx/logs/access.log'
47 |
48 |
49 | function write_content(file_name, content)
50 | local f = assert(io.open(file_name,'a'))
51 | f:write(content)
52 | f:close()
53 | end
54 |
55 | function urlDecode(s)
56 | if(nil ~= s)
57 | then
58 | s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
59 | return s
60 | end
61 | end
62 |
63 | function handle_body(s)
64 | s = urlDecode(s)
65 | if(nil ~= s)
66 | then
67 | return string.gsub(s,'payMethodInfo=(.-)&','payMethodInfo=***&')
68 | end
69 | end
70 |
71 |
72 | local remote_addr = ngx.var.remote_addr
73 | local http_x_forwarded_for = ngx.var.http_x_forwarded_for
74 | local time_local = ngx.var.time_local
75 | local server_name = ngx.var.server_name
76 | local request_method = ngx.var.request_method
77 | local scheme = ngx.var.scheme
78 | local host = ngx.var.host
79 | local request_uri = ngx.var.request_uri
80 | local status = ngx.var.status
81 | local referer = ngx.var.referer
82 | local body = handle_body(ngx.var.request_body)
83 | local http_user_agent = ngx.var.http_user_agent
84 | local upstream_status = ngx.var.upstream_status
85 | local request_time = ngx.var.request_time
86 | local upstream_response_time = ngx.var.upstream_response_time
87 | local http_host = ngx.var.http_host
88 | local scheme_http_host_request_uri = ngx.var.scheme..'://'..http_host..request_uri
89 | local body_bytes_sent = ngx.var.body_bytes_sent
90 | local http_referer = ngx.var.http_referer
91 | local upstream_addr = ngx.var.upstream_addr
92 |
93 |
94 |
95 | -- if ngx.var.file_type == 'audit' then
96 | -- local extend = string.format('srcip=%s&x_srcip=%s&time="%s"&server=%s&server_ip=%s&method=%s&link="%s://%s%s&status=%s&referer="%s"&post="%s"&user_agent="%s"',remote_addr,http_x_forwarded_for,time_local,server_name,server_addr,request_method,scheme,host,request_uri,status,referer,body,http_user_agent)
97 | -- if(ngx.req.get_method() == 'POST')
98 | -- then
99 | -- write_content(file_audit, extend..'\n')
100 | -- end
101 | -- elseif ngx.var.file_type == 'mapi' then
102 | -- local extend = string.format('{"upstream_status":%s,"request_time":%s,"upstream_response_time":%s,"remote_addr":%s,"time_local":%s,"scheme_http_host_request_uri":%s,"status":%s,"body_bytes_sent":%s,"http_referer":%s,"request_body":%s,"http_user_agent":%s,"http_x_forwarded_for":%s,"upstream_addr":%s}',upstream_status,request_time,upstream_response_time,remote_addr,time_local,scheme_http_host_request_uri,status,body_bytes_sent,http_referer,request_body,http_user_agent,http_x_forwarded_for,upstream_addr)
103 | -- write_content(file_mapi, extend..'\n')
104 | -- end
105 |
106 | local extend_audit = string.format('srcip=%s&x_srcip=%s&time="%s"&server=%s&server_ip=%s&method=%s&link="%s://%s%s&status=%s&referer="%s"&post="%s"&user_agent="%s"',remote_addr,http_x_forwarded_for,time_local,server_name,server_addr,request_method,scheme,host,request_uri,status,referer,body,http_user_agent)
107 | local extend_mapi = string.format('{"upstream_status":%s,"request_time":%s,"upstream_response_time":%s,"remote_addr":%s,"time_local":%s,"scheme_http_host_request_uri":%s,"status":%s,"body_bytes_sent":%s,"http_referer":%s,"request_body":%s,"http_user_agent":%s,"http_x_forwarded_for":%s,"upstream_addr":%s}',upstream_status,request_time,upstream_response_time,remote_addr,time_local,scheme_http_host_request_uri,status,body_bytes_sent,http_referer,request_body,http_user_agent,http_x_forwarded_for,upstream_addr)
108 |
109 | if(ngx.req.get_method() == 'POST')
110 | then
111 | write_content(file_audit, extend_audit..'\n')
112 | end
113 | write_content(file_mapi, extend_mapi..'\n')
114 |
115 | ```
116 | #### 6.Lua加载顺序
117 | 
118 |
--------------------------------------------------------------------------------
/ops-scripts/zabbix/zabbix_report_excel.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #Author: Geekwolf
3 | # -*- coding: utf-8 -*-
4 |
5 | from pyzabbix import ZabbixAPI
6 | import xlsxwriter
7 | import time
8 | import sys
9 |
10 |
11 | zabbix_url = 'https://zbx.simlinux.com'
12 | zabbix_user = 'geekwolf'
13 | zabbix_passwd = 'geekwolf'
14 | groups_name = ["hostgroup_name"]
15 | items_key = {"custom.tcp.conn.stat[established]": "TCP", "custom.udp.conn.stat[inuse]": "UDP",
16 | "system.cpu.util[,idle]": "CPU", "system.cpu.load[all,avg5]": "LOAD", "proc.num[]": "PROC"}
17 | zapi = ZabbixAPI(zabbix_url)
18 | zapi.session.auth = (zabbix_user, zabbix_passwd)
19 | zapi.session.verify = False
20 | zapi.login(zabbix_user, zabbix_passwd)
21 |
22 |
23 | def get_data(start, end):
24 | group_id = zapi.hostgroup.get(output="groupid", filter={"name": groups_name})[0]['groupid']
25 | # hosts_ip = json.dumps(zapi.host.get(output=["hostid", "host"], selectGroups="extend", filter={"groupids": "33"}))
26 | hosts_ip = zapi.host.get(output=["hostid", "host"], groupids=group_id)
27 |
28 | his_data = []
29 | for host in hosts_ip:
30 | data = {}
31 | dict1 = []
32 |
33 | for key, value in items_key.items():
34 | item_id = zapi.item.get(output=["itemids", "value_type", "key_"], hostids=host['hostid'],
35 | filter={"key_": key})
36 | # print key +'--------' + value
37 | history = zapi.history.get(history=item_id[0]['value_type'],
38 | itemids=item_id[0]['itemid'], time_from=start, time_till=end)
39 | _tmp = []
40 | for h in history:
41 | _tmp.append(float(h['value']))
42 | if _tmp:
43 | imax = max(_tmp)
44 | imin = min(_tmp)
45 | iavg = float(sum(_tmp) / len(_tmp))
46 | # print item_id[0]['key_'] + "max:%.1f,min:%.1f,iavg:%.2f" % (imax, imin, iavg)
47 |
48 | if value == 'TCP' or value == 'UDP' or value == 'PROC':
49 | dict1.extend([int(imax), int(iavg), int(imin)])
50 | elif value == 'CPU':
51 | dict1.extend([format(float(100 - imin), '0.2f') + "%", format(float(100 - iavg), '0.2f') + "%",
52 | format(float(100 - imax), '0.2f') + "%"])
53 | else:
54 | dict1.extend([format(imax, '0.2f'), format(iavg, '0.2f'), format(imin, '0.2f')])
55 | else:
56 | imax = 'None'
57 | imin = 'None'
58 | iavg = 'None'
59 | # print "max:%s,min:%s,avg:%s" % (imax, imin, iavg)
60 |
61 | dict1.extend([imax, iavg, imin])
62 |
63 | data[host['host']] = dict1
64 | his_data.append(data)
65 | return his_data
66 |
67 |
68 | def dump_excel(data):
69 | # Create a workbook and add a worksheet.
70 | workbook = xlsxwriter.Workbook('zabbix_report.xlsx')
71 | worksheet = workbook.add_worksheet(u'服务器状态')
72 |
73 | # Add a title content format to use to highlight cells.
74 | title = workbook.add_format({'bold': True, 'align': 'center', 'border': 1, 'font_name': 'Microsoft YaHei'})
75 | content = workbook.add_format({'align': 'left', 'border': 1})
76 |
77 | # Write some data headers.
78 | row2 = [u'UDP(单位/个)', u'CPU(单位/百分比)', u'TCP(单位/个)', u'LOAD(5分钟)', u'系统进程数(单位/个)']
79 | row2_col2 = [u'服务项/监控项', u'服务器地址']
80 | row3 = [u'', u'', u'最大值', u'平均值', u'最小值', u'最大值', u'平均值', u'最小值', u'最大值', u'平均值', u'最小值', u'最大值', u'平均值', u'最小值',
81 | u'最大值', u'平均值', u'最小值']
82 | worksheet.merge_range('A1:Q1', u'服务器状态(最近7天数据统计)', title)
83 |
84 | c = 0
85 | for item in row2_col2:
86 | worksheet.merge_range(1, c, 2, c, item, title)
87 | c += 1
88 | # Set the column 1-2 width size
89 | worksheet.set_column(0, 1, 25)
90 |
91 | c = 0
92 | for item in row2:
93 | worksheet.merge_range(1, c + 2, 1, c + 4, item, title)
94 | c += 3
95 |
96 | c = 0
97 | for item in row3:
98 | worksheet.write(2, c, item, content)
99 | c += 1
100 |
101 | row_number = 2
102 |
103 | for p in data:
104 | row_number += 1
105 | for key, value in p.items():
106 | col_number = 1
107 | worksheet.write(row_number, col_number - 1, key, content)
108 | worksheet.write(row_number, col_number, key, content)
109 |
110 | print row_number, col_number - 1
111 | for v in value:
112 | col_number += 1
113 | worksheet.write(row_number, col_number, v, content)
114 |
115 | workbook.close()
116 |
117 |
118 | if __name__ == '__main__':
119 | start_time = time.time()
120 | if len(sys.argv) < 2:
121 | print "Please Input the start time and end time to report like 2016-10-18 10:11:30" + "\n" + '"2016-10-18 10:11:30" "2016-10-18 11:11:30"'
122 | sys.exit()
123 | else:
124 | his_data = get_data(time.mktime(time.strptime(sys.argv[1], '%Y-%m-%d %H:%M:%S'))
125 | , time.mktime(time.strptime(sys.argv[2], '%Y-%m-%d %H:%M:%S')))
126 | dump_excel(his_data)
127 | end_time = time.time()
128 | times = end_time - start_time
129 | print '%s min,%s sec' % (int(times / 60), int(times % 60))
130 |
--------------------------------------------------------------------------------
/zabbix-templates/Template Linux Multi CPU Cores.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2017-01-16T08:54:38Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Template for Multiple CPU Cores
13 | Template for Multiple CPU Cores
14 |
15 |
16 |
17 | Templates
18 |
19 |
20 |
21 |
22 | CPU
23 |
24 |
25 |
26 |
27 |
28 | CPU Multiple Discovery
29 | 0
30 |
31 |
32 | system.cpu.discovery
33 | 10
34 | 0
35 |
36 |
37 |
38 | 0
39 | 0
40 |
41 | 0
42 |
43 |
44 |
45 |
46 | 0
47 |
48 |
49 |
50 |
51 |
52 |
53 | 0
54 |
55 |
56 |
57 | 30
58 |
59 |
60 |
61 | CPU Core-{#CPU.NUMBER}
62 | 0
63 |
64 | 0
65 |
66 | system.cpu.util[{#CPU.NUMBER},user,avg1]
67 | 30
68 | 90
69 | 365
70 | 0
71 | 0
72 |
73 | %
74 | 0
75 |
76 |
77 | 0
78 | 0
79 |
80 | 0
81 |
82 | 1
83 |
84 |
85 |
86 | 0
87 | 0
88 |
89 |
90 |
91 |
92 |
93 |
94 | 0
95 |
96 |
97 | CPU
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | {Template for Multiple CPU Cores:system.cpu.util[{#CPU.NUMBER},user,avg1].min(3m)}>80
107 | {HOST.HOST} CPU Core-{#CPU.NUMBER}核利用率超80%
108 |
109 | 0
110 | 0
111 |
112 | 1
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/ops-scripts/migratetoconfluence.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Author: Geekwolf
3 | # @Date: 2018-05-24 17:58:16
4 | # @Last Modified by: Geekwolf
5 | # @Last Modified time: 2018-05-25 19:50:37
6 |
7 | import pymysql
8 | import collections
9 | import requests
10 | import json
11 | import markdown
12 |
13 |
14 | class DBHelper(object):
15 | """docstring for DBHelper"""
16 |
17 | def __init__(self):
18 | self.host = '192.168.1.1'
19 | self.user = 'wiki'
20 | self.password = 'password'
21 | self.database = 'db'
22 | self.conn = None
23 | self.cur = None
24 |
25 | def ConnDB(self):
26 | try:
27 | self.conn = pymysql.connect(self.host, self.user, self.password, self.database, charset='utf8')
28 | except Exception as e:
29 | print(str(e))
30 | return False
31 | self.cur = self.conn.cursor()
32 | return True
33 |
34 | def Close(self):
35 | if self.conn and self.cur:
36 | self.cur.close()
37 | self.conn.close()
38 | return True
39 |
40 | def Execute(self, sql, params=None):
41 | self.ConnDB()
42 | try:
43 | if self.conn and self.cur:
44 | self.cur.execute(sql, params)
45 | self.conn.commit()
46 | except Exception as e:
47 | print(str(e))
48 | self.Close()
49 | return False
50 | return True
51 |
52 | def Select(self, sql, params=None):
53 | self.Execute(sql, params)
54 | return self.cur.fetchall()
55 |
56 |
57 | class SyncWiki(object):
58 | """docstring for SyncWiki"""
59 |
60 | def __init__(self, ):
61 |
62 | # The Space:autotest Key Name
63 | self.space = 'ops'
64 | self.url = 'http://confluence'
65 | self.username = 'geekwolf'
66 | self.password = 'geekwolf'
67 | self.session = self.GetSession()
68 | # self.home_page = '{} Home'.format(self.space)
69 | self.home_page='ops'
70 | self.headers = {'Content-Type': 'application/json'}
71 | self.dbhelper = DBHelper()
72 |
73 | def GetSession(self):
74 | session = requests.session()
75 | data = {'os_username': self.username, 'os_password': self.password, 'login': 'Log in'}
76 | res = session.post(self.url, data)
77 | return session
78 |
79 | def MarkdownToHtml(self, content):
80 | # convert_url = "{}/rest/api/contentbody/convert/storage".format(self.url)
81 | # print(convert_url)
82 | # data = {"value": content, "representation": "wiki"}
83 | # ret = self.session.post(convert_url, json.dumps(data), headers=self.headers)
84 |
85 | ret = markdown.markdown(content, extensions=['fenced_code', 'codehilite', 'extra', 'abbr', 'attr_list', 'def_list', 'footnotes',
86 | 'tables', 'smart_strong', 'admonition', 'codehilite', 'headerid', 'meta', 'nl2br', 'sane_lists', 'smarty', 'toc', 'wikilinks'])
87 | return ret
88 |
89 | def GetPageId(self, title):
90 | '''
91 | 通过分类名称获取在Confluence中的id
92 | '''
93 | content_url = '{}/rest/api/content?spaceKey={}&title={}'.format(self.url, self.space, title)
94 | data = self.session.get(content_url).json()
95 | id = data['results'][0]['id']
96 | return id
97 |
98 | def CreatePageMethod(self, id, title, value=None):
99 |
100 | page_url = '{}/rest/api/content'.format(self.url)
101 | data = {"type": "page", "ancestors": [{"id": id}], "title": title, "space": {
102 | "key": self.space}, "body": {"storage": {"value": value, "representation": "storage"}}}
103 | self.session.post(page_url, json.dumps(data), headers=self.headers)
104 |
105 | def CreateTypePage(self):
106 | '''
107 | 创建分类页面(二级分类)
108 | '''
109 | group_page_url = '{}/rest/api/content'.format(self.url)
110 | group_info = self.GetGroupInfo()
111 |
112 | try:
113 | for k, v in group_info.items():
114 | self.CreatePageMethod(self.GetPageId(self.home_page), k)
115 | for i in v:
116 | self.CreatePageMethod(self.GetPageId(k), i)
117 | ret = True
118 | except Exception as e:
119 | print(str(e))
120 | ret = False
121 | return ret
122 |
123 | def CreatePage(self):
124 | '''
125 | 根据标题和内容创建对应子类的页面
126 | '''
127 | content = self.GetWiki()
128 | for i in content:
129 | try:
130 | id = self.GetPageId(i[0])
131 | title = i[1]
132 | value = self.MarkdownToHtml(i[2])
133 | self.CreatePageMethod(id, title, value=value)
134 | print('{}------{}已经创建'.format(i[0], i[1]))
135 | except Exception as e:
136 | print('{}------{}创建失败:{}'.format(i[0], i[1], str(e)))
137 |
138 | def GetGroupInfo(self):
139 |
140 | sql = 'select * from wiki_group;'
141 | result = self.dbhelper.Select(sql)
142 | _group_info = collections.defaultdict(list)
143 | _group_dict = dict([(r[0], r[1]) for r in result])
144 |
145 | for r in result:
146 | if r[3] is None:
147 | _group_info[r[1]] = []
148 | else:
149 | _group_info[_group_dict[r[3]]].append(r[1])
150 | return _group_info
151 |
152 | def GetWiki(self):
153 |
154 | sql = 'SELECT g.name,w.title,w.content from wiki_wiki as w LEFT JOIN wiki_group as g ON w.group_id = g.id'
155 | result = self.dbhelper.Select(sql)
156 | return result
157 |
158 |
159 | if __name__ == '__main__':
160 |
161 | ins = SyncWiki()
162 | if ins.CreateTypePage():
163 | ins.CreatePage()
164 |
165 |
--------------------------------------------------------------------------------
/zabbix-templates/Template UDP/Template UDP Status.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2017-01-16T08:45:37Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Custom UDP Connect Stat
13 | Custom UDP Connect Stat
14 |
15 |
16 |
17 | Templates
18 |
19 |
20 |
21 |
22 | Custom UDP Connect Stat
23 |
24 |
25 |
26 | -
27 | custom_udp_connect_stat_inuse
28 | 0
29 |
30 | 0
31 |
32 | custom.udp.conn.stat[inuse]
33 | 120
34 | 90
35 | 365
36 | 0
37 | 3
38 |
39 |
40 | 0
41 |
42 |
43 | 0
44 | 0
45 |
46 | 0
47 |
48 | 1
49 |
50 |
51 |
52 | 0
53 | 0
54 |
55 |
56 |
57 |
58 |
59 |
60 | 0
61 |
62 |
63 | Custom UDP Connect Stat
64 |
65 |
66 |
67 |
68 |
69 | -
70 | custom_udp_connect_stat_mem
71 | 0
72 |
73 | 0
74 |
75 | custom.udp.conn.stat[mem]
76 | 120
77 | 90
78 | 365
79 | 0
80 | 3
81 |
82 |
83 | 0
84 |
85 |
86 | 0
87 | 0
88 |
89 | 0
90 |
91 | 1
92 |
93 |
94 |
95 | 0
96 | 0
97 |
98 |
99 |
100 |
101 |
102 |
103 | 0
104 |
105 |
106 | Custom UDP Connect Stat
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 | Custom udp connect
122 | 900
123 | 200
124 | 0.0000
125 | 100.0000
126 | 1
127 | 1
128 | 0
129 | 1
130 | 0
131 | 0.0000
132 | 0.0000
133 | 0
134 | 0
135 | 0
136 | 0
137 |
138 |
139 | 0
140 | 0
141 | 00C800
142 | 0
143 | 2
144 | 0
145 | -
146 | Custom UDP Connect Stat
147 | custom.udp.conn.stat[inuse]
148 |
149 |
150 |
151 | 1
152 | 0
153 | C80000
154 | 0
155 | 2
156 | 0
157 | -
158 | Custom UDP Connect Stat
159 | custom.udp.conn.stat[mem]
160 |
161 |
162 |
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/ops-scripts/kuanpanshell/OAuth.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright (c) 2010, Yu-Jie Lin
3 | # All rights reserved. https://github.com/livibetter/bash-oauth
4 | #
5 | # Redistribution and use in source and binary forms, with or without
6 | # modification, are permitted provided that the following conditions are met:
7 | #
8 | # * Redistributions of source code must retain the above copyright notice,
9 | # this list of conditions and the following disclaimer.
10 | #
11 | # * Redistributions in binary form must reproduce the above copyright notice,
12 | # this list of conditions and the following disclaimer in the documentation
13 | # and/or other materials provided with the distribution.
14 | #
15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 | # POSSIBILITY OF SUCH DAMAGE.
26 |
27 | OAuth_debug () {
28 | # Print out all parameters, each in own line
29 | [[ "$OAUTH_DEBUG" == "" ]] && return
30 | local t=$(date +%FT%T.%N)
31 | while (( $# > 0 )); do
32 | echo "[OAuth][DEBUG][$t] $1"
33 | shift 1
34 | done
35 | }
36 |
37 | OAuth_nonce () {
38 | # Return a nonce
39 | md5sum <<< "$RANDOM-$(date +%s.%N)" | cut -d' ' -f 1
40 | }
41 |
42 | OAuth_timestamp () {
43 | # Return timestamp
44 | echo "$(date +%s)"
45 | }
46 |
47 | OAuth_PE () {
48 | # Encode $1 using Percent-encoding as defined in
49 | # http://tools.ietf.org/html/rfc5849#section-3.6
50 | # Any character other than [a-zA-Z0-9-._~] is converted into format %XX
51 | [ -n "$1" ] \
52 | && echo -n "$1" | perl -p -e 's/([^A-Za-z0-9-._~])/sprintf("%%%02X", ord($1))/seg'
53 | }
54 |
55 | OAuth_PE_file () {
56 | # Encode a file $1 using Percent-encoding as defined in
57 | # http://tools.ietf.org/html/rfc5849#section-3.6
58 | # $1 a filename, not the content of file
59 | perl -p -e 's/([^A-Za-z0-9-._~])/sprintf("%%%02X", ord($1))/seg' < "$1"
60 | }
61 |
62 | OAuth_params_string () {
63 | # Sort the paramters and join them into one-line string
64 | while (( $# > 0 )); do
65 | echo $1
66 | shift 1
67 | done | sort | tr '\n' '&' | sed 's/&$//'
68 | }
69 |
70 | OAuth_base_string () {
71 | # $1 method: "GET", "POST", etc
72 | # $2 url
73 | # $3-$N params
74 | local method=$1
75 | local url=$2
76 | shift 2
77 |
78 | local params_string=$(OAuth_params_string $@)
79 |
80 | echo "$method&$(OAuth_PE "$url")&$(OAuth_PE "$params_string")"
81 | }
82 |
83 | OAuth_param () {
84 | # Return a percent encoded key-value pair
85 | # $1 key
86 | # $2 value
87 | echo "$(OAuth_PE "$1")=$(OAuth_PE "$2")"
88 | }
89 |
90 | OAuth_param_quote () {
91 | # Return a percent encoded key-value pair, value is quoted
92 | # $1 key
93 | # $2 value
94 | echo "$(OAuth_PE "$1")=\"$(OAuth_PE "$2")\""
95 | }
96 |
97 | OAuth_param_file () {
98 | # Return a percent encoded key-value pair, the value is an encoded file content
99 | # $1 key
100 | # $2 filename
101 | echo "$(OAuth_PE "$1")=$(OAuth_PE_file "$2")"
102 | }
103 |
104 | OAuth_param_raw_value () {
105 | # Return a percent encoded key-value pair, only key will be encoded by this function
106 | # $1 key
107 | # $2 value
108 | echo "$(OAuth_PE "$1")=$2"
109 | }
110 |
111 | OAuth_HMAC_SHA1 () {
112 | # Hash the text $1 with key $2
113 | local text="$1"
114 | local key="$2"
115 | echo -n "$text" | openssl dgst -sha1 -binary -hmac "$key" | base64
116 | }
117 |
118 | _OAuth_signature () {
119 | # Return the signature, note it's necessary to pass to OAuth_PE before add to header
120 | # $1 signature_method
121 | # $2 base_string
122 | # $3 consumer_secret
123 | # $4 token_secret
124 | local signature_method="OAuth_${1//-/_}"
125 | local base_string=$2
126 | local c_secret=$3
127 | local t_secret=$4
128 | $signature_method "$base_string" "$c_secret&$t_secret"
129 | }
130 |
131 | OAuth_signature () {
132 | # Return the signature, note it's necessary to pass to OAuth_PE before add to header
133 | # $1 base_string
134 | _OAuth_signature "$oauth_signature_method" "$1" "$oauth_consumer_secret" "$oauth_token_secret"
135 | }
136 |
137 | _OAuth_authorization_header_params_string () {
138 | while (( $# > 0 )); do
139 | echo -n "$(cut -d\= -f 1 <<< "$1")=\"$(cut -d\= -f 2 <<< "$1")\""
140 | shift 1
141 | # Use break to prevent error code being returned
142 | (( $# > 0 )) && echo -n ', ' || break
143 | done
144 | }
145 |
146 | _OAuth_authorization_header () {
147 | # Return header string
148 | # $1 header key
149 | # $2 OAuth realm, can be empty string
150 | # $3 OAuth consumer key
151 | # $4 OAuth consumer secret
152 | # $5 OAuth token
153 | # $6 OAuth token secret
154 | # $7 OAuth signature method
155 | # $8 OAuth version
156 | # $9 nonce
157 | # $10 timestamp
158 | # $11 method
159 | # $12 url
160 | # $13-$N params
161 | echo -n "$1: OAuth "
162 | [[ "$2" != "" ]] && echo -n "realm=\"$2\", "
163 | local oauth_consumer_key="$3"
164 | local oauth_consumer_secret="$4"
165 | local oauth_token="$5"
166 | local oauth_token_secret="$6"
167 | local oauth_signature_method="$7"
168 | local oauth_version="$8"
169 | local oauth_nonce="$9"
170 | [[ "$oauth_nonce" == "" ]] && oauth_nonce="$(OAuth_nonce)"
171 | local oauth_timestamp="${10}"
172 | [[ "$oauth_timestamp" == "" ]] && oauth_timestamp="$(OAuth_timestamp)"
173 | local method="${11}"
174 | local url="${12}"
175 | shift 12
176 | local params=(
177 | $(OAuth_param 'oauth_consumer_key' "$oauth_consumer_key")
178 | $(OAuth_param 'oauth_signature_method' "$oauth_signature_method")
179 | $(OAuth_param 'oauth_version' "$oauth_version")
180 | $(OAuth_param 'oauth_nonce' "$oauth_nonce")
181 | $(OAuth_param 'oauth_timestamp' "$oauth_timestamp")
182 | )
183 | [[ "$oauth_token" != "" ]] && params[${#params[@]}]=$(OAuth_param 'oauth_token' "$oauth_token")
184 | local sign_params=${params[@]}
185 | while (( $# > 0 )); do
186 | sign_params[${#sign_params[@]}]="$1"
187 | shift 1
188 | done
189 | local base_string=$(OAuth_base_string "$method" "$url" ${sign_params[@]})
190 | local signature=$(_OAuth_signature "$oauth_signature_method" "$base_string" "$oauth_consumer_secret" "$oauth_token_secret")
191 | params[${#params[@]}]=$(OAuth_param 'oauth_signature' "$signature")
192 | _OAuth_authorization_header_params_string ${params[@]}
193 | }
194 |
195 | OAuth_authorization_header () {
196 | # Return header string
197 | # $1 header key
198 | # $2 OAuth realm, can be empty string
199 | # $3 OAuth nonce
200 | # $4 OAuth timestamp
201 | # $5 method
202 | # $6 url
203 | # $7-$N params
204 | local header_key="$1"
205 | local realm="$2"
206 | local oauth_nonce="$3"
207 | local oauth_timestamp="$4"
208 | local method="$5"
209 | local url="$6"
210 | shift 6
211 | local params=()
212 | while (( $# > 0 )); do
213 | params[${#params[@]}]="$1"
214 | shift 1
215 | done
216 | _OAuth_authorization_header "$header_key" "$realm" "$oauth_consumer_key" "$oauth_consumer_secret" "$oauth_token" "$oauth_token_secret" "$oauth_signature_method" "$oauth_version" "$oauth_nonce" "$oauth_timestamp" "$method" "$url" ${params[@]}
217 | }
218 |
--------------------------------------------------------------------------------
/zabbix-templates/Template Generic Linux OS.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2017-01-16T08:53:06Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Linux Generic Templates
13 | Linux Generic Templates
14 |
15 |
16 |
17 | Templates
18 |
19 |
20 |
21 |
22 | CPU Cores
23 |
24 |
25 |
26 |
27 |
28 | CPU Multiple Discovery
29 | 0
30 |
31 |
32 | system.cpu.discovery
33 | 3600
34 | 0
35 |
36 |
37 |
38 | 0
39 | 0
40 |
41 | 0
42 |
43 |
44 |
45 |
46 | 0
47 |
48 |
49 |
50 |
51 |
52 |
53 | 0
54 |
55 |
56 |
57 | 30
58 |
59 |
60 |
61 | CPU Core-{#CPU.NUMBER}
62 | 0
63 |
64 | 0
65 |
66 | system.cpu.util[{#CPU.NUMBER},user,avg5]
67 | 30
68 | 90
69 | 365
70 | 0
71 | 0
72 |
73 | %
74 | 0
75 |
76 |
77 | 0
78 | 0
79 |
80 | 0
81 |
82 | 1
83 |
84 |
85 |
86 | 0
87 | 0
88 |
89 |
90 |
91 |
92 |
93 |
94 | 0
95 |
96 |
97 | CPU Cores
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | { Linux Generic Templates:system.cpu.util[{#CPU.NUMBER},user,avg5].avg(5m)}>80
107 | {HOST.HOST} CPU Core-{#CPU.NUMBER}核利用率超80%
108 |
109 | 0
110 | 1
111 |
112 | 0
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 | {$MAX_CPU_LOAD}
122 | 18
123 |
124 |
125 |
126 |
127 | Custom TCP Connect Stat
128 |
129 |
130 | Custom UDP Connect Stat
131 |
132 |
133 | Template ICMP Ping
134 |
135 |
136 | Template OS Linux
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 | { Linux Generic Templates:system.cpu.load[all,avg5].last()}>{$MAX_CPU_LOAD}
145 | Processor load is too high on {HOST.NAME}
146 |
147 | 0
148 | 1
149 |
150 | 0
151 |
152 |
153 |
154 |
155 |
156 | Processes Number
157 | 900
158 | 200
159 | 0.0000
160 | 100.0000
161 | 1
162 | 1
163 | 0
164 | 1
165 | 0
166 | 0.0000
167 | 0.0000
168 | 0
169 | 0
170 | 0
171 | 0
172 |
173 |
174 | 0
175 | 0
176 | 00C800
177 | 0
178 | 2
179 | 0
180 | -
181 | Linux Generic Templates
182 | proc.num[]
183 |
184 |
185 |
186 | 1
187 | 0
188 | C80000
189 | 0
190 | 2
191 | 0
192 | -
193 | Linux Generic Templates
194 | proc.num[,,run]
195 |
196 |
197 |
198 |
199 |
200 |
201 |
--------------------------------------------------------------------------------
/ops-scripts/plogstash/plogstash.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # @Author: Geekwolf
3 | # @Date: 2018-01-29 14:23:04
4 | # @Last Modified by: Geekwolf
5 | # @Last Modified time: 2018-01-31 10:55:01
6 |
7 | #!/usr/bin/env python3
8 | # daemon.py
9 |
10 | import os
11 | import sys
12 | import time
13 | import redis
14 | import json
15 | import re
16 | import atexit
17 | import signal
18 | # import collections
19 |
20 |
21 | class Base(object):
22 |
23 | def __init__(self, *args, **kwargs):
24 |
25 | self.pidfile = '/var/run/plogstash.pid'
26 | self.service_name = 'Plogstash'
27 | self.path = '/var/log/plogstash'
28 | os.makedirs(self.path, exist_ok=True)
29 | self.logfile = '%s/%s.log' % (self.path, self.service_name)
30 |
31 | self.redis_host = '127.0.0.1'
32 | self.redis_password = 'geekwolf'
33 | self.redis_port = 5044
34 | self.redis_db = 0
35 | self.redis_key = 'filebeat'
36 | self.batch_size = 5000
37 | self.expires = 5 # second
38 | self.archive_time = 1 # how long time to archive
39 | self.base_dir = '/data/logs'
40 | # self._tmp = '/tmp/.%s' % self.service_name
41 |
42 |
43 | class Daemon(Base):
44 |
45 | def __init__(self, *args, **kwargs):
46 | super(Daemon, self).__init__(*args, **kwargs)
47 |
48 | def daemonize(self):
49 |
50 | # First fork (detaches from parent)
51 | try:
52 | if os.fork() > 0:
53 | raise SystemExit(0) # Parent exit
54 | except OSError as e:
55 | raise RuntimeError('fork #1 failed.')
56 |
57 | os.chdir('/')
58 | # set this will 777
59 | # os.umask(0)
60 | os.setsid()
61 | # Second fork (relinquish session leadership)
62 | try:
63 | if os.fork() > 0:
64 | raise SystemExit(0)
65 | except OSError as e:
66 | raise RuntimeError('fork #2 failed.')
67 |
68 | # Flush I/O buffers
69 | sys.stdout.flush()
70 | sys.stderr.flush()
71 |
72 | # Replace file descriptors for stdin, stdout, and stderr
73 | with open(self.logfile, 'ab', 0) as f:
74 | os.dup2(f.fileno(), sys.stdout.fileno())
75 | with open(self.logfile, 'ab', 0) as f:
76 | os.dup2(f.fileno(), sys.stderr.fileno())
77 | with open(self.logfile, 'rb', 0) as f:
78 | os.dup2(f.fileno(), sys.stdin.fileno())
79 |
80 | # Write the PID file
81 | print(os.getpid())
82 | with open(self.pidfile, 'w') as f:
83 | print(os.getpid(), file=f)
84 |
85 | # Arrange to have the PID file removed on exit/signal
86 | atexit.register(lambda: os.remove(self.pidfile))
87 |
88 | # Signal handler for termination (required)
89 | def sigterm_handler(signo, frame):
90 | raise SystemExit(1)
91 |
92 | signal.signal(signal.SIGTERM, sigterm_handler)
93 |
94 | def get_now_date(self):
95 |
96 | return time.strftime('%Y-%m-%d', time.localtime(time.time()))
97 |
98 | def get_now_timestamp(self):
99 |
100 | return time.time()
101 |
102 | def get_now_time(self):
103 | return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
104 |
105 | def logging(self, msg):
106 |
107 | with open(self.logfile) as f:
108 | print('%s %s' % (self.get_now_time(), msg))
109 |
110 | def append_log(self):
111 | pass
112 |
113 | def start(self):
114 |
115 | if os.path.exists(self.pidfile):
116 | raise RuntimeError('Already running')
117 | else:
118 | try:
119 | self.daemonize()
120 | self.append_log()
121 | self.status()
122 | except RuntimeError as e:
123 | print(e, file=sys.stderr)
124 | raise SystemExit(1)
125 |
126 | def stop(self):
127 |
128 | # f = os.open(self.pipe_path, os.O_RDONLY | os.O_NONBLOCK)
129 | # ret = os.read(f, 1024).decode('utf-8')
130 | # print(ret.split('\n'))
131 | # os.close(f)
132 |
133 | if os.path.exists(self.pidfile):
134 | # with open(self._tmp) as f:
135 | # _data = f.read()
136 | # if _data is not None and len(eval(_data)) > 0:
137 | # for k, v in eval(_data).items():
138 | # v = v['fd'].rstrip('\n')
139 | # v.close()
140 | with open(self.pidfile) as f:
141 | os.kill(int(f.read()), signal.SIGTERM)
142 | print('Plogstash is stopped')
143 | else:
144 | print('Not running', file=sys.stderr)
145 | raise SystemExit(1)
146 |
147 | def restart(self):
148 |
149 | self.stop()
150 | self.start()
151 |
152 | def status(self):
153 |
154 | try:
155 | with open(self.pidfile, 'r') as f:
156 | pid = int(f.read().strip())
157 | except:
158 | pid = None
159 |
160 | if pid:
161 | print('%s is running as pid:%s' % (self.service_name, pid))
162 | else:
163 | print('%s is not running' % self.service_name)
164 |
165 |
166 | class Worker(Daemon):
167 |
168 | def __init__(self, *args, **kwargs):
169 | super(Worker, self).__init__(self, *args, **kwargs)
170 |
171 | def _redis(self):
172 |
173 | pool = redis.ConnectionPool(host=self.redis_host, password=self.redis_password, port=self.redis_port, db=self.redis_db, socket_timeout=10000)
174 | rc = redis.StrictRedis(connection_pool=pool)
175 | return rc
176 |
177 | def get_redis_data(self):
178 |
179 | _data = self._redis().lrange(self.redis_key, 0, self.batch_size - 1)
180 | # 删除数据(可考虑处理完再删除)
181 | return _data
182 |
183 | def del_redis_data(self):
184 |
185 | _data = self._redis().ltrim(self.redis_key, self.batch_size, -1)
186 |
187 | def append_log(self):
188 |
189 | file_meta = {}
190 | # file_handler = collections.defaultdict(dict)
191 | # try:
192 | # os.mkfifo(self.pipe_path)
193 | # except Exception as e:
194 | # print(str(e))
195 |
196 | # pipe_ins = os.open(self.pipe_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)
197 | while True:
198 | time.sleep(self.archive_time)
199 | _data = self.get_redis_data()
200 | if _data:
201 | for _d in _data:
202 | try:
203 | _d = json.loads(_d.decode('utf-8'))
204 | _path = '%s/%s/%s/%s' % (self.base_dir, _d['fields']['env'], self.get_now_date(), _d['fields']['ip_address'])
205 | os.makedirs(_path + '/logs', exist_ok=True)
206 | file_name = _d['source'].split('/')[-1]
207 | # _path = '%s/%s/%s/%s' % (self.base_dir, _d['fields']['env'],self.get_now_date(), _d['fields']['ip_address'])
208 |
209 | if re.match('nohup', file_name):
210 | file_path = '%s/%s' % (_path, file_name)
211 | else:
212 | file_path = '%s/logs/%s' % (_path, file_name)
213 |
214 | with open(file_path, 'a') as f:
215 | f.write(_d['message'] + '\n')
216 | # if 'fd' not in file_handler[file_path]:
217 | # f = open(file_path, 'a', buffering=1024000)
218 | # file_handler[file_path]['fd'] = str(f)
219 | # file_handler[file_path]['time'] = self.get_now_timestamp()
220 | except Exception as e:
221 | self.logging(str(e))
222 | self.del_redis_data()
223 | # with open(self._tmp, 'w') as f:
224 | # f.write(json.dumps(file_handler))
225 |
226 | if __name__ == '__main__':
227 |
228 | if len(sys.argv) != 2:
229 | print('Usage: {} [start|stop|restart|status]'.format(sys.argv[0]), file=sys.stderr)
230 | raise SystemExit(1)
231 |
232 | daemon = Worker()
233 | if sys.argv[1] == 'start':
234 | daemon.start()
235 | elif sys.argv[1] == 'stop':
236 | daemon.stop()
237 | elif sys.argv[1] == 'restart':
238 | print("Restart ...")
239 | daemon.restart()
240 | elif sys.argv[1] == 'status':
241 | daemon.status()
242 | else:
243 | print('Unknown command {!r}'.format(sys.argv[1]), file=sys.stderr)
244 | raise SystemExit(1)
245 |
--------------------------------------------------------------------------------
/ops-scripts/zabbix/zabbix_report_email/report.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | # @Author: Geekwolf
4 | # @Date: 2018-05-07 13:26:12
5 | # @Last Modified by: Geekwolf
6 | # @Last Modified time: 2018-07-11 14:11:00
7 |
8 | import ConfigParser
9 | import cookielib
10 | import urllib2
11 | import urllib
12 | import ast
13 | import datetime,time
14 | from docx import Document
15 | from docx.shared import Pt, RGBColor
16 | from docx.enum.text import WD_ALIGN_PARAGRAPH
17 | from docx.oxml.ns import qn
18 | from docx.enum.style import WD_STYLE_TYPE
19 | from docx.shared import Inches
20 | from io import BytesIO
21 | import collections
22 | from ftplib import FTP
23 | import os
24 | import mimetypes
25 | import sys
26 | import smtplib
27 | from email.header import Header
28 | from email.mime.text import MIMEText
29 | from email.mime.image import MIMEImage
30 | from email.mime.multipart import MIMEMultipart
31 | from email.utils import parseaddr, formataddr
32 |
33 | config = ConfigParser.RawConfigParser()
34 | config.read(os.path.join(os.path.dirname(os.path.abspath(__file__)),'./config.ini'))
35 |
36 | class ZabbixGraph(object):
37 |
38 | def __init__(self):
39 |
40 | self.url = config.get('monitor', 'zbx_url')
41 | self.username = config.get('monitor', 'username')
42 | self.password = config.get('monitor', 'password')
43 | self.graph_url = self.url + config.get('monitor', 'graph_url')
44 | self.item_graph_url = self.url + config.get('monitor', 'item_graph_url')
45 | self.width = config.get('graph', 'width')
46 | self.height = config.get('graph', 'height')
47 | self.period = config.get('graph', 'period')
48 | self.temp_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),config.get('monitor', 'temp_dir'))
49 | self.log_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),config.get('monitor','log_file'))
50 | if not os.path.exists(self.temp_dir):
51 | os.makedirs(self.temp_dir)
52 | self.urlOpener = self.GetSession()
53 |
54 | def GetSession(self):
55 |
56 | cookiejar = cookielib.CookieJar()
57 | urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
58 | values = {"name": self.username, 'password': self.password, 'autologin': 1, "enter": 'Sign in'}
59 | data = urllib.urlencode(values)
60 | request = urllib2.Request(self.url, data)
61 | try:
62 | urlOpener.open(request, timeout=10)
63 | self.urlOpener = urlOpener
64 | except urllib2.HTTPError, e:
65 | print e
66 | return urlOpener
67 |
68 | def Log(self,rec):
69 | t = time.strftime('%Y-%m-%d %H:%M:%S')
70 | with open(self.log_file,'a') as f:
71 | f.write('{} {}'.format(str(t),str(rec)))
72 |
73 |
74 | def GetRequest(self,values,url,id):
75 |
76 | _data = urllib.urlencode(values)
77 | request = urllib2.Request(url, _data)
78 | url = self.urlOpener.open(request)
79 | ext = mimetypes.guess_extension(url.headers['content-type'])
80 | imagename = '{}/{}{}'.format(self.temp_dir, str(id), ext)
81 | with open(imagename, 'wb') as f:
82 | f.write(url.read())
83 | return imagename
84 |
85 | def GetItemGraph(self,id):
86 |
87 | values = {'itemids': id, 'width': self.width, 'height': self.height, 'period': self.period}
88 | imagename = self.GetRequest(values,self.item_graph_url,id)
89 | return imagename
90 |
91 | def GetGraph(self):
92 |
93 | info = ast.literal_eval(config.get('graph', 'info'))
94 | data = collections.defaultdict(list)
95 | for i in info:
96 | values = {}
97 | for j in i['graphids']:
98 | values = {'graphid': j, 'width': self.width, 'height': self.height, 'period': self.period}
99 | imagename = self.GetRequest(values,self.graph_url,j)
100 | # image = BytesIO()
101 | # image.write(url.read())
102 | data[i['name']].append(imagename)
103 | # imagename = "%s/%s.png" % (self.temp_dir, str(j) + i['name'])
104 | # f = open(imagename, 'wb')
105 | # f.write(image)
106 | self.WriteDoc(data)
107 |
108 | def GetStyles(self):
109 |
110 | # doc = Document()
111 | # 在脚本打包成二进制时,需要指定default.docx路径,否则会报错
112 | doc = Document(docx=os.path.join(os.getcwd(), 'default.docx'))
113 | style_head = doc.styles.add_style('style_head', WD_STYLE_TYPE.PARAGRAPH)
114 | style_head.font.size = Pt(25)
115 | style_head.font.name = u'微软雅黑'
116 | style_head.font.bold = True
117 | style_head._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
118 | style_head.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
119 |
120 | style_title = doc.styles.add_style('style_title', WD_STYLE_TYPE.PARAGRAPH)
121 | style_title.font.size = Pt(15)
122 | style_title.font.name = u'微软雅黑'
123 | style_title.font.bold = True
124 | style_title._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
125 |
126 | sub_title = doc.styles.add_style('sub_title', WD_STYLE_TYPE.PARAGRAPH)
127 | sub_title.font.size = Pt(10)
128 | sub_title.font.name = u'微软雅黑'
129 | sub_title.font.bold = True
130 | sub_title._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
131 |
132 | return doc, style_head, style_title, sub_title
133 |
134 | @staticmethod
135 | def GetYesterdayTime():
136 |
137 | _time = datetime.date.today() - datetime.timedelta(days=1)
138 | return str(_time)
139 |
140 | def WriteDoc(self, data):
141 |
142 | doc, style_head, style_title, sub_title = self.GetStyles()
143 | _dict = {0: '一', 1: '二', 2: '三'}
144 | _time = ZabbixGraph.GetYesterdayTime()
145 | head = doc.add_paragraph(u'zbx监控报表', style='style_head')
146 | sub_head = doc.add_paragraph(_time)
147 | sub_head.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER
148 | for d in enumerate(data):
149 | title = '{}、{}'.format(_dict[d[0]], d[1])
150 | doc.add_paragraph(title.decode('utf8'), style='style_title')
151 | for idx, val in enumerate(data[d[1]]):
152 | #sub_title = u'内存' if idx%2 == 1 else u'CPU'
153 | if idx >=2:
154 | sub_title = u'内存'
155 | else:
156 | sub_title = u'CPU'
157 | if idx%2 != 1:
158 | doc.add_paragraph(sub_title, style='sub_title')
159 | doc.add_picture(val, width=Inches(6.5), height=Inches(3))
160 | file = 'report-{}.docx'.format(('').join(_time.split('-')))
161 | doc.save(file)
162 | #如果将报表上传ftp,可以去掉注释
163 | #self.FtpUpload(file)
164 |
165 | def DelTemp(self):
166 |
167 | os.system('rm -rf report-* {}'.format(self.temp_dir))
168 |
169 | def FtpUpload(self, file):
170 |
171 | host = config.get('ftp', 'host')
172 | port = config.get('ftp', 'port')
173 | username = config.get('ftp', 'username')
174 | password = config.get('ftp', 'password')
175 | ftp = FTP(host=host)
176 | ftp.login(user=username, passwd=password)
177 | ftp.storbinary('STOR ' + file, open(file, 'rb'))
178 | ftp.quit()
179 | self.DelTemp()
180 |
181 | class AlarmInfo(ZabbixGraph):
182 |
183 | def format(content):
184 |
185 | name, addr = parseaddr(content)
186 | return formataddr((Header(name, 'utf-8').encode(), addr))
187 |
188 | def Email(self):
189 |
190 | smtpserver = config.get('email', 'smtpserver')
191 | username = config.get('email','username')
192 | password = config.get('email','password')
193 | port = config.get('email','password')
194 | try:
195 | smtp = smtplib.SMTP()
196 | smtp.connect(smtpserver)
197 | smtp.login(username,password)
198 | return smtp
199 | except Exception as e:
200 | self.Log(str(e))
201 |
202 | def SendEmail(self,_info):
203 |
204 | itemid = _info[2].split('|')[0]
205 | imagename = self.GetItemGraph(itemid)
206 | fro = config.get('email','username')
207 | _content = ('
').join(_info[3].split('\n'))
208 | content = '{}
'.format(_content)
209 | msg = MIMEMultipart()
210 | #msg['From'] = '监控告警<{}>'.format(fro).decode('utf-8')
211 | msg['From'] = "%s<%s>" % (Header("监控告警","utf-8"),fro)
212 | msg['Subject'] = Header((': ').join(_info[2].split('|')[-2:]),'utf-8')
213 | msg['To'] = _info[1]
214 | msg.attach(MIMEText(content,'html','utf-8'))
215 | with open(imagename,'rb') as f:
216 | img = MIMEImage(f.read())
217 | img.add_header('Content-ID', '')
218 | msg.attach(img)
219 | try:
220 | email = self.Email()
221 | email.sendmail(fro,_info[1],msg.as_string())
222 | email.quit()
223 | except Exception as e:
224 | self.Log(str(e))
225 |
226 | def main(self,_info):
227 | try:
228 | if len(_info) == 4:
229 | rec = '{}\t{}\n{}\n'.format(_info[1],_info[2],_info[3])
230 | self.Log(rec)
231 | self.SendEmail(_info)
232 | elif len(_info) == 2 and _info[1] == 'report':
233 | self.GetGraph()
234 | except Exception as e:
235 | self.Log(str(e))
236 |
237 |
238 | if __name__ == '__main__':
239 |
240 | ins = AlarmInfo()
241 | ins.main(sys.argv)
242 |
--------------------------------------------------------------------------------
/zabbix-templates/Template TCP/Template TCP Status.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2017-01-16T08:45:33Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Custom TCP Connect Stat
13 | Custom TCP Connect Stat
14 |
15 |
16 |
17 | Templates
18 |
19 |
20 |
21 |
22 | Custom TCP Connect Stat
23 |
24 |
25 |
26 | -
27 | CLOSE_WAIT
28 | 0
29 |
30 | 0
31 |
32 | custom.tcp.conn.stat[close-wait]
33 | 30
34 | 90
35 | 365
36 | 0
37 | 3
38 |
39 |
40 | 0
41 |
42 |
43 | 0
44 | 0
45 |
46 | 0
47 |
48 | 1
49 |
50 |
51 |
52 | 0
53 | 0
54 |
55 |
56 |
57 |
58 |
59 |
60 | 0
61 |
62 |
63 | Custom TCP Connect Stat
64 |
65 |
66 |
67 |
68 |
69 | -
70 | ESTABLISHED
71 | 0
72 |
73 | 0
74 |
75 | custom.tcp.conn.stat[established]
76 | 10
77 | 90
78 | 365
79 | 0
80 | 3
81 |
82 |
83 | 0
84 |
85 |
86 | 0
87 | 0
88 |
89 | 0
90 |
91 | 1
92 |
93 |
94 |
95 | 0
96 | 0
97 |
98 |
99 |
100 |
101 |
102 |
103 | 0
104 |
105 |
106 | Custom TCP Connect Stat
107 |
108 |
109 |
110 |
111 |
112 | -
113 | TIME_WAIT
114 | 0
115 |
116 | 0
117 |
118 | custom.tcp.conn.stat[time-wait]
119 | 120
120 | 90
121 | 365
122 | 0
123 | 3
124 |
125 |
126 | 0
127 |
128 |
129 | 0
130 | 0
131 |
132 | 0
133 |
134 | 1
135 |
136 |
137 |
138 | 0
139 | 0
140 |
141 |
142 |
143 |
144 |
145 |
146 | 0
147 |
148 |
149 | Custom TCP Connect Stat
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 | {Custom TCP Connect Stat:custom.tcp.conn.stat[established].avg(5m)}>{$TCP_TIME_ESTABLISHED}
165 | TCP ESTABLISHED on {HOST.NAME}
166 |
167 | 0
168 | 1
169 |
170 | 0
171 |
172 |
173 |
174 | {Custom TCP Connect Stat:custom.tcp.conn.stat[time-wait].avg(5m)}>{$TCP_TIME_WAIT}
175 | TCP TimeWait on {HOST.NAME}
176 |
177 | 0
178 | 1
179 |
180 | 0
181 |
182 |
183 |
184 |
185 |
186 | Custom tcp connect
187 | 900
188 | 200
189 | 0.0000
190 | 100.0000
191 | 1
192 | 1
193 | 0
194 | 1
195 | 0
196 | 0.0000
197 | 0.0000
198 | 0
199 | 0
200 | 0
201 | 0
202 |
203 |
204 | 0
205 | 0
206 | 00C800
207 | 0
208 | 2
209 | 0
210 | -
211 | Custom TCP Connect Stat
212 | custom.tcp.conn.stat[established]
213 |
214 |
215 |
216 | 1
217 | 0
218 | C80000
219 | 0
220 | 2
221 | 0
222 | -
223 | Custom TCP Connect Stat
224 | custom.tcp.conn.stat[time-wait]
225 |
226 |
227 |
228 | 2
229 | 0
230 | 0000C8
231 | 0
232 | 2
233 | 0
234 | -
235 | Custom TCP Connect Stat
236 | custom.tcp.conn.stat[close-wait]
237 |
238 |
239 |
240 |
241 |
242 |
243 |
--------------------------------------------------------------------------------
/config/smokeping_config:
--------------------------------------------------------------------------------
1 | *** General ***
2 |
3 | owner = nobody
4 | contact = g@163.com
5 | mailhost = localhost
6 | sendmail = /usr/lib/sendmail
7 | # NOTE: do not put the Image Cache below cgi-bin
8 | # since all files under cgi-bin will be executed ... this is not
9 | # good for images.
10 | imgcache = /usr/local/smokeping-2.6.8/htdocs/cache
11 | imgurl = cache
12 | datadir = /usr/local/smokeping-2.6.8/var
13 | piddir = /usr/local/smokeping-2.6.8/var
14 | cgiurl = http://smokeping.linuxhonker.com/smokeping.cgi
15 | smokemail = /usr/local/smokeping-2.6.8/etc/smokemail
16 |
17 | tmail = /usr/local/smokeping-2.6.8/etc/tmail
18 | # specify this to get syslog logging
19 | #syslogfacility = local0
20 | # each probe is now run in its own process
21 | # disable this to revert to the old behaviour
22 | # concurrentprobes = no
23 | *** Alerts ***
24 | to = g@163.com
25 | from = monitor@163.com
26 |
27 | +someloss
28 | type = loss
29 | # in percent
30 | pattern = >0%,*20*,>0%,*20*,>0%
31 | comment = loss 1 package in 20 continuous 3 times.
32 |
33 | +manyloss
34 | type = loss
35 | # in percent
36 | pattern = >10%,*50*,>10%,*50*,>15%
37 | comment = loss 5 packages in 50 continuous 3 times.
38 |
39 | *** Database ***
40 |
41 | step = 60
42 | pings = 50
43 |
44 |
45 | # consfn mrhb steps total
46 |
47 | AVERAGE 0.5 1 1008
48 | AVERAGE 0.5 12 4320
49 | MIN 0.5 12 4320
50 | MAX 0.5 12 4320
51 | AVERAGE 0.5 144 720
52 | MAX 0.5 144 720
53 | MIN 0.5 144 720
54 |
55 | *** Presentation ***
56 |
57 | charset = UTF-8
58 | template = /usr/local/smokeping-2.6.8/etc/basepage.html
59 |
60 | + charts
61 |
62 | menu = Charts
63 | title = The most interesting destinations
64 |
65 | ++ stddev
66 | sorter = StdDev(entries=>4)
67 | title = Top Standard Deviation
68 | menu = Std Deviation
69 | format = Standard Deviation %f
70 |
71 | ++ max
72 | sorter = Max(entries=>5)
73 | title = Top Max Roundtrip Time
74 | menu = by Max
75 | format = Max Roundtrip Time %f seconds
76 |
77 | ++ loss
78 | sorter = Loss(entries=>5)
79 | title = Top Packet Loss
80 | menu = Loss
81 | format = Packets Lost %f
82 |
83 | ++ median
84 | sorter = Median(entries=>5)
85 | title = Top Median Roundtrip Time
86 | menu = by Median
87 | format = Median RTT %f seconds
88 |
89 | + overview
90 |
91 | width = 600
92 | height = 50
93 | range = 10h
94 |
95 | + detail
96 |
97 | width = 600
98 | height = 200
99 | unison_tolerance = 2
100 |
101 | "Last 3 Hours" 3h
102 | "Last 30 Hours" 30h
103 | "Last 10 Days" 10d
104 | "Last 400 Days" 400d
105 |
106 | #+ hierarchies
107 | #++ owner
108 | #title = Host Owner
109 | #++ location
110 | #title = Location
111 |
112 | *** Probes ***
113 |
114 | + FPing
115 |
116 | binary = /usr/sbin/fping
117 |
118 | *** Slaves ***
119 | secrets=/usr/local/smokeping-2.6.8/etc/smokeping_secrets
120 |
121 | *** Targets ***
122 |
123 | probe = FPing
124 |
125 | menu = Top
126 | title = Network Latency Grapher
127 | remark = Welcome to the SmokePing website of xxx Company. \
128 | Here you will learn all about the latency of our network.
129 |
130 | menuextra = *
131 |
132 | ##### Host Monitored From Slave Configure #####
133 |
134 | #+ Slaves
135 | #menu = Slaves
136 | #title = All of the Monitor From the Slaves
137 |
138 | #++ baowu1
139 | #menu = baowu1
140 | #title = 北京帝联-122.11.61.154 from dfgs1
141 | #alerts = someloss
142 | #slaves = dfgs1
143 | #host = 122.11.61.154
144 |
145 | #++ baowu2
146 | #menu = baowu2
147 | #title = 北京帝联-122.11.61.155 from dfgs1
148 | #alerts = someloss
149 | #slaves = dfgs1
150 | #host = 122.11.61.155
151 |
152 | #++ bwbanhao
153 | #menu = bwbanhao
154 | #title = 厦门电信-218.85.133.197 from dfgs1
155 | #alerts = someloss
156 | #slaves = dfgs1
157 | #host = 218.85.133.197
158 |
159 | ##### Single Host Monitor #####
160 |
161 | + CNC
162 | title = 中国网通
163 | menu = CNC
164 |
165 | ++ beijing
166 | menu = beijing
167 | title = 北京-202.108.100.166
168 | #alerts = someloss
169 | host = 202.108.100.166
170 |
171 | ++ tianjin
172 | menu = tianjin
173 | title = 天津-218.69.33.1
174 | #alerts = someloss
175 | host = 218.69.33.1
176 |
177 | ++ shanghai
178 | menu = shanghai
179 | title = 上海-220.248.112.1
180 | #alerts = someloss
181 | host = 220.248.112.1
182 |
183 | ++ hebei
184 | menu = hebei
185 | title = 河北-221.192.1.1
186 | #alerts = someloss
187 | host = 221.192.1.1
188 |
189 | ++ shanxi
190 | menu = shanxi
191 | title = 山西-218.26.176.1
192 | #alerts = someloss
193 | host = 218.26.176.1
194 |
195 | ++ neimeng
196 | menu = neimeng
197 | title = 内蒙-60.31.195.1
198 | #alerts = someloss
199 | host = 60.31.195.1
200 |
201 | ++ liaoning
202 | menu = liaoning
203 | title = 辽宁-218.25.255.1
204 | #alerts = someloss
205 | host = 218.25.255.1
206 |
207 | ++ jilin
208 | menu = jinlin
209 | title = 吉林-221.8.96.1
210 | #alerts = someloss
211 | host = 221.8.96.1
212 |
213 | ++ heilongjian
214 | menu = heilongjiang
215 | title = 黑龙江-218.7.249.154
216 | #alerts = someloss
217 | host = 218.7.249.154
218 |
219 | ++ shandong
220 | menu = shandong
221 | title = 山东-218.59.169.109
222 | #alerts = someloss
223 | host = 218.59.169.109
224 |
225 | ++ heinan
226 | menu = heinan
227 | title = 河南-202.111.148.1
228 | #alerts = someloss
229 | host = 202.111.148.1
230 |
231 | ++ jiangsu
232 | menu = jiangsu
233 | title = 江苏-58.240.48.43
234 | #alerts = someloss
235 | host = 58.240.48.43
236 |
237 | ++ zhejiang
238 | menu = zhejiang
239 | title = 浙江-60.12.193.1
240 | #alerts = someloss
241 | host = 60.12.193.1
242 |
243 | ++ yunan
244 | menu = yunan
245 | title = 云南-221.3.131.1
246 | #alerts = someloss
247 | host = 221.3.131.1
248 |
249 | ++ sichuan
250 | menu = sichuan
251 | title = 四川-221.10.239.1
252 | #alerts = someloss
253 | host = 221.10.239.1
254 |
255 | ++ shengxi
256 | menu = shengxi
257 | title = 陕西-2221.11.1.1
258 | #alerts = someloss
259 | host = 221.11.1.1
260 |
261 | ++ guangxi
262 | menu = guangxi
263 | title = 广西-221.7.129.163
264 | #alerts = someloss
265 | host = 221.7.129.163
266 |
267 | ++ fujian
268 | menu = fujian
269 | title = 福建-58.22.97.1
270 | #alerts = someloss
271 | host = 58.22.97.1
272 |
273 | ++ chongqing
274 | menu = chongqing
275 | title = 重庆-221.5.196.1
276 | #alerts = someloss
277 | host = 221.5.196.1
278 |
279 | ++ changchun
280 | menu = changchun
281 | title = 长春-221.8.18.8
282 | #alerts = someloss
283 | host = 221.8.18.8
284 |
285 | ++ dalian
286 | menu = dalian
287 | title = 大连-202.96.69.38
288 | #alerts = someloss
289 | host = 202.96.69.38
290 |
291 | ++ qingdao
292 | menu = qingdao
293 | title = 青岛-60.209.5.254
294 | #alerts = someloss
295 | host = 60.209.5.254
296 |
297 |
298 | ++ hubei
299 | menu = hubei
300 | title = 湖北-210.52.149.2
301 | #alerts = someloss
302 | host = 210.52.149.2
303 |
304 |
305 | +CTC
306 | title = 中国电信Ping
307 | menu = CTC
308 |
309 | ++ shanghai1
310 | menu = shanghai1
311 | title = 上海-61.152.188.1
312 | #alerts = someloss
313 | host = 61.152.188.1
314 |
315 | ++ shanghai2
316 | menu = shanghai2
317 | title = 上海2-61.129.51.254
318 | #alerts = someloss
319 | host = 61.129.51.254
320 |
321 | ++ guangzhou
322 | menu = guangzhou
323 | title = 广州-61.145.125.229
324 | #alerts = someloss
325 | host = 61.145.125.229
326 |
327 | ++ shenzhen
328 | menu = shenzhen
329 | title = 深圳-218.18.104.1
330 | #alerts = someloss
331 | host = 218.18.104.1
332 |
333 | ++ shangtou
334 | menu = shangtou
335 | title = 汕头-218.16.239.129
336 | #alerts = someloss
337 | host = 218.16.239.129
338 |
339 | ++ zhejianghangzhou
340 | menu = zhejiang
341 | title = 浙江-218.75.107.60
342 | #alerts = someloss
343 | host = 218.75.107.60
344 |
345 | ++ hunan
346 | menu = hunan
347 | title = 湖南-202.103.96.200
348 | #alerts = someloss
349 | host = 202.103.96.200
350 |
351 | ++ sichuan
352 | menu = sichuan
353 | title = 四川-221.236.17.1
354 | #alerts = someloss
355 | host = 221.236.17.1
356 |
357 | ++ chongjing
358 | menu = chongjing
359 | title = 重庆-222.176.2.214
360 | #alerts = someloss
361 | host = 222.176.2.214
362 |
363 | ++ liangning
364 | menu = liangning
365 | title = 辽宁-219.148.197.6
366 | #alerts = someloss
367 | host = 219.148.197.6
368 |
369 | ++ shangdong
370 | menu = shangdong
371 | title = 山东-219.148.197.6
372 | #alerts = someloss
373 | host = 219.148.197.6
374 |
375 | ++ hebei
376 | menu = hebei
377 | title = 河北-222.222.202.202
378 | #alerts = someloss
379 | host = 222.222.202.202
380 |
381 | ++ hubei
382 | menu = hubei
383 | title = 湖北-58.53.192.150
384 | #alerts = someloss
385 | host = 58.53.192.150
386 |
387 | ++ hainan
388 | menu = hainan
389 | title = 海南-218.77.178.229
390 | #alerts = someloss
391 | host = 218.77.178.229
392 |
393 | ++ guizhou
394 | menu = guizhou
395 | title = 贵州-219.141.62.111
396 | #alerts = someloss
397 | host = 219.141.62.111
398 |
399 | ++ shengxi
400 | menu = shengxi
401 | title = 陕西-218.30.85.83
402 | #alerts = someloss
403 | host = 218.30.85.83
404 |
405 | ++ xian
406 | menu = xian
407 | title = 西安-218.30.64.121
408 | #alerts = someloss
409 | host = 218.30.64.121
410 |
411 | ++ gansu
412 | menu = gansu
413 | title = 甘萧-60.164.225.1
414 | #alerts = someloss
415 | host = 60.164.225.1
416 |
417 |
418 | ++ ningxia
419 | menu = ningxia
420 | title = 宁夏-202.100.96.68
421 | #alerts = someloss
422 | host = 202.100.96.68
423 |
424 | ++ tianjin
425 | menu = tianjin
426 | title = 天津-221.238.193.1
427 | #alerts = someloss
428 | host = 221.238.193.1
429 |
430 | ++ fujian
431 | menu = fujian
432 | title = 福建-202.109.204.150
433 | #alerts = someloss
434 | host = 202.109.204.150
435 |
436 | ++ jiangxi
437 | menu = jiangxi
438 | title = 江西-220.175.8.1
439 | #alerts = someloss
440 | host = 220.175.8.1
441 |
442 |
443 | ++ neimeng
444 | menu = neimeng
445 | title = 内蒙古-219.148.162.4
446 | #alerts = someloss
447 | host = 219.148.162.4
448 |
449 | + Edu
450 | title = 教育网ping
451 | menu = EDU
452 |
453 | ++ bj-hangkong
454 | menu = bj-hangkong
455 | title = 北京航空-202.112.128.1
456 | #alerts = someloss
457 | host = 202.112.128.1
458 |
459 | ++jinghua
460 | menu = jinghua
461 | title = 清华-166.111.8.28
462 | #alerts = someloss
463 | host = 166.111.8.28
464 |
465 | ++ shanghai-jiaodong
466 | menu = shanghai-jiaotong
467 | title = 上海交通-202.112.26.34
468 | #alerts = someloss
469 | host = 202.112.26.34
470 |
471 | ++ guangzhou-huanan
472 | menu = guangzhou-huanan
473 | title = 广州华南-202.116.160.33
474 | #alerts = someloss
475 | host = 202.116.160.33
476 |
--------------------------------------------------------------------------------
/ops-scripts/kuanpanshell/kuaipan_uploader.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #load oauth source
4 | source OAuth.sh
5 |
6 | #Set to 1 to enable DEBUG mode
7 | DEBUG=0
8 |
9 | #Set to 1 to enable VERBOSE mode
10 | VERBOSE=1
11 |
12 | #Default configuration file
13 | CONFIG_FILE=~/.kuaipan_uploader
14 |
15 | #Don't edit these...
16 | API_REQUEST_TOKEN_URL="https://openapi.kuaipan.cn/open/requestToken"
17 | API_USER_AUTH_URL="https://www.kuaipan.cn/api.php?ac=open&op=authorise"
18 | API_ACCESS_TOKEN_URL="https://openapi.kuaipan.cn/open/accessToken"
19 | API_LOCATE_URL="http://api-content.dfs.kuaipan.cn/1/fileops/upload_locate"
20 | API_UPLOAD_URL="1/fileops/upload_file"
21 | APP_CREATE_URL="http://www.kuaipan.cn/developers/create.htm"
22 | RESPONSE_FILE="/tmp/du_resp_$RANDOM"
23 | BIN_DEPS="curl sed"
24 | VERSION="0.1"
25 |
26 | OAUTH_VERSION="1.0"
27 | SIGNATURE_METHOD="HMAC-SHA1"
28 | KUAIPAN_PATH="backup/"
29 |
30 | umask 077
31 |
32 | if [ $DEBUG -ne 0 ]; then
33 | set -x
34 | RESPONSE_FILE="/tmp/du_resp_debug"
35 | fi
36 |
37 |
38 | #Remove temporary files
39 | function remove_temp_files
40 | {
41 | if [ $DEBUG -eq 0 ]; then
42 | rm -fr $RESPONSE_FILE
43 | fi
44 | }
45 |
46 | #Replace spaces
47 | function urlencode
48 | {
49 | str=$1
50 | echo ${str// /%20}
51 | }
52 |
53 | #USAGE
54 | function usage() {
55 | echo -e "快盘上传shell脚本 v$VERSION"
56 | echo -e "1号蟋蟀 - come.a.mail@gmail.com\n"
57 | echo -e "使用: $0 命令 [参数]..."
58 | echo -e "\n命令:"
59 | echo -e "\t upload [源文件]"
60 | echo -en "\n"
61 | remove_temp_files
62 | exit 1
63 | }
64 |
65 | #CHECK DEPENDENCIES
66 | for i in $BIN_DEPS; do
67 | which $i > /dev/null
68 | if [ $? -ne 0 ]; then
69 | echo -e "错误: 文件未找到: $i"
70 | remove_temp_files
71 | exit 1
72 | fi
73 | done
74 |
75 | #CHECKING FOR AUTH FILE
76 | if [ -f $CONFIG_FILE ]; then
77 |
78 | #Loading data...
79 | CONSUMER_KEY=$(sed -n -e 's/CONSUMER_KEY:\([a-z A-Z 0-9]*\)/\1/p' $CONFIG_FILE)
80 | CONSUMER_SECRET=$(sed -n -e 's/CONSUMER_SECRET:\([a-z A-Z 0-9]*\)/\1/p' $CONFIG_FILE)
81 | OAUTH_ACCESS_TOKEN=$(sed -n -e 's/OAUTH_ACCESS_TOKEN:\([a-z A-Z 0-9]*\)/\1/p' $CONFIG_FILE)
82 | OAUTH_ACCESS_TOKEN_SECRET=$(sed -n -e 's/OAUTH_ACCESS_TOKEN_SECRET:\([a-z A-Z 0-9]*\)/\1/p' $CONFIG_FILE)
83 |
84 | #NEW SETUP...
85 | else
86 |
87 | echo -ne "\n这是你第一次运行此脚本\n"
88 | echo -ne "如果你尚未创建任何快盘应用,请先创建一个,快盘系统会给你的应用分配和\n"
89 | echo -ne "创建快盘应用的时候,请设置 <访问权限> 为 '整个快盘' \n\n"
90 | echo -ne "当你成功创建完应用以后,请输入以下信息: \n\n"
91 | #Getting the app key and secret from the user
92 | while (true); do
93 |
94 | echo -n " # consumer_key: "
95 | read CONSUMER_KEY
96 |
97 | echo -n " # consumer_secret: "
98 | read CONSUMER_SECRET
99 |
100 | echo -ne " > consumer_key 是 $CONSUMER_KEY, consumer_secret 是 $CONSUMER_SECRET, 正确? [y/n]"
101 | read answer
102 | if [ "$answer" == "y" ]; then
103 | break;
104 | fi
105 |
106 | done
107 |
108 | #TOKEN REQUESTS
109 | echo -ne "\n > 获取授权第一步: request token... "
110 | OAUTH_TIMESTAMP="$(OAuth_timestamp)"
111 | OAUTH_NONCE="$(OAuth_nonce)"
112 | params=(
113 | $(OAuth_param 'oauth_consumer_key' "$CONSUMER_KEY")
114 | $(OAuth_param 'oauth_signature_method' "$SIGNATURE_METHOD")
115 | $(OAuth_param 'oauth_version' "$OAUTH_VERSION")
116 | $(OAuth_param 'oauth_nonce' "$OAUTH_NONCE")
117 | $(OAuth_param 'oauth_timestamp' "$OAUTH_TIMESTAMP")
118 | )
119 |
120 | BASE_STRING=$(OAuth_base_string 'GET' "$API_REQUEST_TOKEN_URL" ${params[@]})
121 |
122 | SIGNATURE=$(_OAuth_signature "$SIGNATURE_METHOD" "$BASE_STRING" "$CONSUMER_SECRET" "")
123 |
124 | curl -k -s --show-error -i -o $RESPONSE_FILE "$API_REQUEST_TOKEN_URL?oauth_version=$OAUTH_VERSION&oauth_consumer_key=$CONSUMER_KEY&oauth_signature_method=$SIGNATURE_METHOD&oauth_signature=$SIGNATURE&oauth_timestamp=$OAUTH_TIMESTAMP&oauth_nonce=$OAUTH_NONCE"
125 | OAUTH_TOKEN_SECRET=$(sed -n -e 's/{"oauth_token_secret": "\([a-z A-Z 0-9]*\).*/\1/p' "$RESPONSE_FILE")
126 | OAUTH_TOKEN=$(sed -n -e 's/.*oauth_token": "\([a-zA-Z0-9]*\)", ".*}/\1/p' "$RESPONSE_FILE")
127 |
128 |
129 | if [ "$OAUTH_TOKEN" != "" -a "$OAUTH_TOKEN_SECRET" != "" ]; then
130 | echo -ne " 第一步成功\n"
131 | else
132 | cat $RESPONSE_FILE
133 | echo -ne "\n"
134 | echo -ne " 获取request token失败\n\n 请确认你的consumer_key以及cosumer_secret的正确性...\n\n"
135 | remove_temp_files
136 | exit 1
137 | fi
138 |
139 | while (true); do
140 |
141 | #USER AUTH
142 | echo -ne "\n > 获取授权第二步: 请使用浏览器打开这个URL,并授权该脚本访问你的快盘--> ${API_USER_AUTH_URL}&oauth_token=$OAUTH_TOKEN\n"
143 | echo -ne "\n 完成以后,请按<回车>键...\n"
144 | read
145 |
146 | echo -n " # 授权码: "
147 | read OAUTH_VERIFIER
148 |
149 | #API_ACCESS_TOKEN_URL
150 | echo -ne " > 最后: 正在获取授权... "
151 |
152 | OAUTH_TIMESTAMP="$(OAuth_timestamp)"
153 | OAUTH_NONCE="$(OAuth_nonce)"
154 | params=(
155 | $(OAuth_param 'oauth_consumer_key' "$CONSUMER_KEY")
156 | $(OAuth_param 'oauth_signature_method' "$SIGNATURE_METHOD")
157 | $(OAuth_param 'oauth_version' "$OAUTH_VERSION")
158 | $(OAuth_param 'oauth_nonce' "$OAUTH_NONCE")
159 | $(OAuth_param 'oauth_timestamp' "$OAUTH_TIMESTAMP")
160 | $(OAuth_param 'oauth_verifier' "$OAUTH_VERIFIER")
161 | $(OAuth_param 'oauth_token' "$OAUTH_TOKEN")
162 | )
163 |
164 | BASE_STRING=$(OAuth_base_string 'GET' "$API_ACCESS_TOKEN_URL" ${params[@]})
165 | SIGNATURE=$(_OAuth_signature "$SIGNATURE_METHOD" "$BASE_STRING" "$CONSUMER_SECRET" "$OAUTH_TOKEN_SECRET")
166 |
167 | curl -k -s --show-error -i -o $RESPONSE_FILE "$API_ACCESS_TOKEN_URL?oauth_version=$OAUTH_VERSION&oauth_consumer_key=$CONSUMER_KEY&oauth_token=$OAUTH_TOKEN&oauth_signature_method=$SIGNATURE_METHOD&oauth_signature=$SIGNATURE&oauth_timestamp=$OAUTH_TIMESTAMP&oauth_nonce=$OAUTH_NONCE&oauth_verifier=$OAUTH_VERIFIER"
168 | OAUTH_ACCESS_TOKEN_SECRET=$(sed -n -e 's/{"oauth_token_secret": "\([a-z A-Z 0-9]*\).*/\1/p' "$RESPONSE_FILE")
169 | OAUTH_ACCESS_TOKEN=$(sed -n -e 's/.*oauth_token": "\([a-zA-Z0-9]*\)", ".*}/\1/p' "$RESPONSE_FILE")
170 | OAUTH_ACCESS_USER_ID=$(sed -n -e 's/.*user_id": \([0-9]*\), ".*}/\1/p' "$RESPONSE_FILE")
171 |
172 | if [ "$OAUTH_ACCESS_TOKEN" != "" -a "$OAUTH_ACCESS_TOKEN_SECRET" != "" -a "$OAUTH_ACCESS_USER_ID" != "" ]; then
173 | echo -ne "获取授权成功,请重新运行该脚本,开始使用!\n"
174 |
175 | #Saving data
176 | echo "CONSUMER_KEY:$CONSUMER_KEY" > $CONFIG_FILE
177 | echo "CONSUMER_SECRET:$CONSUMER_SECRET" >> $CONFIG_FILE
178 | echo "OAUTH_ACCESS_TOKEN:$OAUTH_ACCESS_TOKEN" >> $CONFIG_FILE
179 | echo "OAUTH_ACCESS_TOKEN_SECRET:$OAUTH_ACCESS_TOKEN_SECRET" >> $CONFIG_FILE
180 |
181 | echo -ne "\n 授权设置完成,请重新运行脚本开始使用!\n"
182 | break
183 | else
184 | cat $RESPONSE_FILE
185 | printf "获取授权失败,请重试!\n"
186 | fi
187 |
188 | done;
189 |
190 | remove_temp_files
191 | exit 0
192 | fi
193 |
194 | COMMAND=$1
195 |
196 | #CHECKING PARAMS VALUES
197 | case $COMMAND in
198 |
199 | upload)
200 |
201 | FILE_SRC=$2
202 | FILE_DST=$(urlencode "$3")
203 |
204 | #Checking FILE_SRC
205 | if [ ! -f "$FILE_SRC" ]; then
206 | echo -e "请指定一个有效的本地文件!"
207 | remove_temp_files
208 | exit 1
209 | fi
210 |
211 | #Checking FILE_DST
212 | if [ -z "$FILE_DST" ]; then
213 | FILE_DST=$(basename "$FILE_SRC")
214 | fi
215 |
216 | ;;
217 |
218 | *)
219 | usage
220 | ;;
221 | esac
222 |
223 | ################
224 | #### START ####
225 | ################
226 |
227 | #COMMAND EXECUTION
228 | case "$COMMAND" in
229 |
230 | upload)
231 | printf " > 获取上传地址... \n"
232 | OAUTH_TIMESTAMP="$(OAuth_timestamp)"
233 | OAUTH_NONCE="$(OAuth_nonce)"
234 | params=(
235 | $(OAuth_param 'oauth_consumer_key' "$CONSUMER_KEY")
236 | $(OAuth_param 'oauth_signature_method' "$SIGNATURE_METHOD")
237 | $(OAuth_param 'oauth_version' "$OAUTH_VERSION")
238 | $(OAuth_param 'oauth_nonce' "$OAUTH_NONCE")
239 | $(OAuth_param 'oauth_timestamp' "$OAUTH_TIMESTAMP")
240 | $(OAuth_param 'oauth_verifier' "$OAUTH_VERIFIER")
241 | $(OAuth_param 'oauth_token' "$OAUTH_TOKEN")
242 | )
243 |
244 | BASE_STRING=$(OAuth_base_string 'GET' "$API_ACCESS_TOKEN_URL" ${params[@]})
245 | SIGNATURE=$(_OAuth_signature "$SIGNATURE_METHOD" "$BASE_STRING" "$CONSUMER_SECRET" "$OAUTH_TOKEN_SECRET")
246 |
247 | curl -k -s --show-error -i -o $RESPONSE_FILE "$API_LOCATE_URL?oauth_version=$OAUTH_VERSION&oauth_consumer_key=$CONSUMER_KEY&oauth_signature_method=$SIGNATURE_METHOD&oauth_signature=$SIGNATURE&oauth_timestamp=$OAUTH_TIMESTAMP&oauth_nonce=$OAUTH_NONCE&oauth_token=$OAUTH_ACCESS_TOKEN"
248 |
249 | GOT_UPLOAD_URL=$(sed -n -e 's/.*url": "\(.*\)", ".*}/\1/p' "$RESPONSE_FILE")
250 |
251 | if [ -z "$GOT_UPLOAD_URL" ]; then
252 | cat $RESPONSE_FILE
253 | echo -ne "获取获取上传地址失败!\n"
254 | else
255 | echo -ne " > 正在上传 $FILE_SRC 至 $KUAIPAN_PATH ... \n"
256 | OAUTH_TIMESTAMP="$(OAuth_timestamp)"
257 | OAUTH_NONCE="$(OAuth_nonce)"
258 | UPLOAD_PATH="$KUAIPAN_PATH$FILE_DST"
259 | UPLOAD_ROOT="app_folder"
260 | UPLOAD_OVERWRITE="true"
261 | UPLOAD_FULL_URL="$GOT_UPLOAD_URL$API_UPLOAD_URL"
262 | params=(
263 | $(OAuth_param 'oauth_consumer_key' "$CONSUMER_KEY")
264 | $(OAuth_param 'oauth_signature_method' "$SIGNATURE_METHOD")
265 | $(OAuth_param 'oauth_version' "$OAUTH_VERSION")
266 | $(OAuth_param 'oauth_nonce' "$OAUTH_NONCE")
267 | $(OAuth_param 'oauth_timestamp' "$OAUTH_TIMESTAMP")
268 | $(OAuth_param 'oauth_token' "$OAUTH_ACCESS_TOKEN")
269 | $(OAuth_param 'root' "$UPLOAD_ROOT")
270 | $(OAuth_param 'overwrite' "$UPLOAD_OVERWRITE")
271 | $(OAuth_param 'path' "$UPLOAD_PATH")
272 | )
273 |
274 | BASE_STRING=$(OAuth_base_string 'POST' "$UPLOAD_FULL_URL" ${params[@]})
275 | SIGNATURE=$(_OAuth_signature "$SIGNATURE_METHOD" "$BASE_STRING" "$CONSUMER_SECRET" "$OAUTH_ACCESS_TOKEN_SECRET")
276 |
277 | curl --progress-bar -k -i -o "$RESPONSE_FILE" -F "file=@$FILE_SRC" "$UPLOAD_FULL_URL?oauth_consumer_key=$CONSUMER_KEY&oauth_token=$OAUTH_ACCESS_TOKEN&oauth_signature_method=$SIGNATURE_METHOD&oauth_signature=$SIGNATURE&oauth_timestamp=$OAUTH_TIMESTAMP&oauth_nonce=$OAUTH_NONCE&oauth_version=$OAUTH_VERSION&root=$UPLOAD_ROOT&overwrite=$UPLOAD_OVERWRITE&path=$UPLOAD_PATH"
278 | #Check
279 | grep "HTTP/1.1 200 OK" "$RESPONSE_FILE" > /dev/null
280 | if [ $? -eq 0 ]; then
281 | printf " >上传完成!<\n"
282 | else
283 | cat $RESPONSE_FILE
284 | printf " >上传失败!<\n"
285 | fi
286 | fi
287 | ;;
288 |
289 | *)
290 | usage
291 | ;;
292 |
293 | esac
294 |
295 | remove_temp_files
296 |
297 |
--------------------------------------------------------------------------------
/zabbix-templates/Template Percona MySQL/templates/userparameter_percona_mysql.conf:
--------------------------------------------------------------------------------
1 | UserParameter=MySQL.Sort-scan,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kt
2 | UserParameter=MySQL.slave-stopped,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jh
3 | UserParameter=MySQL.Com-replace,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jz
4 | UserParameter=MySQL.innodb-lock-structs,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lp
5 | UserParameter=MySQL.Com-load,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kg
6 | UserParameter=MySQL.State-updating,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mi
7 | UserParameter=MySQL.Aborted-clients,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ip
8 | UserParameter=MySQL.innodb-lock-wait-secs,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ni
9 | UserParameter=MySQL.Handler-read-key,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mr
10 | UserParameter=MySQL.file-reads,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gy
11 | UserParameter=MySQL.Query-time-count-12,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ox
12 | UserParameter=MySQL.relay-log-space,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lj
13 | UserParameter=MySQL.Threads-connected,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iu
14 | UserParameter=MySQL.Qcache-lowmem-prunes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jp
15 | UserParameter=MySQL.Binlog-cache-use,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lm
16 | UserParameter=MySQL.State-freeing-items,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lt
17 | UserParameter=MySQL.Query-time-count-10,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ov
18 | UserParameter=MySQL.read-views,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gm
19 | UserParameter=MySQL.Bytes-received,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ky
20 | UserParameter=MySQL.os-waits,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hv
21 | UserParameter=MySQL.Handler-commit,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mm
22 | UserParameter=MySQL.Com-select,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jx
23 | UserParameter=MySQL.Qcache-total-blocks,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh js
24 | UserParameter=MySQL.Handler-read-prev,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mt
25 | UserParameter=MySQL.Sort-rows,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ks
26 | UserParameter=MySQL.Qcache-free-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jm
27 | UserParameter=MySQL.pages-read,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gu
28 | UserParameter=MySQL.Key-read-requests,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
29 | UserParameter=MySQL.State-other,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ml
30 | UserParameter=MySQL.Qcache-inserts,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jo
31 | UserParameter=MySQL.State-none,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mk
32 | UserParameter=MySQL.pending-normal-aio-writes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hp
33 | UserParameter=MySQL.hash-index-cells-total,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nj
34 | UserParameter=MySQL.pool-size,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gq
35 | UserParameter=MySQL.pending-ibuf-aio-reads,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hl
36 | UserParameter=MySQL.Handler-write,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ng
37 | UserParameter=MySQL.innodb-sem-waits,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ny
38 | UserParameter=MySQL.Handler-savepoint-rollback,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh my
39 | UserParameter=MySQL.Query-time-total-01,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pg
40 | UserParameter=MySQL.Query-time-total-00,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oz
41 | UserParameter=MySQL.Table-locks-waited,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ig
42 | UserParameter=MySQL.Handler-rollback,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mw
43 | UserParameter=MySQL.unflushed-log,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lg
44 | UserParameter=MySQL.Query-time-total-04,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pj
45 | UserParameter=MySQL.Query-time-total-07,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pm
46 | UserParameter=MySQL.Handler-savepoint,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mx
47 | UserParameter=MySQL.Query-time-total-09,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh po
48 | UserParameter=MySQL.Query-time-total-08,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pn
49 | UserParameter=MySQL.Select-range-check,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ko
50 | UserParameter=MySQL.Threads-running,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iw
51 | UserParameter=MySQL.State-init,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lu
52 | UserParameter=MySQL.Aborted-connects,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iq
53 | UserParameter=MySQL.Handler-read-first,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mq
54 | UserParameter=MySQL.Created-tmp-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ku
55 | UserParameter=MySQL.Created-tmp-disk-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kv
56 | UserParameter=MySQL.Select-full-range-join,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh km
57 | UserParameter=MySQL.Connections,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iz
58 | UserParameter=MySQL.Com-insert,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jw
59 | UserParameter=MySQL.Query-time-total-11,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pq
60 | UserParameter=MySQL.innodb-transactions,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gl
61 | UserParameter=MySQL.State-sorting-result,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mg
62 | UserParameter=MySQL.State-statistics,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mh
63 | UserParameter=MySQL.innodb-locked-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lo
64 | UserParameter=MySQL.log-bytes-written,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh li
65 | UserParameter=MySQL.innodb-log-buffer-size,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kz
66 | UserParameter=MySQL.Select-full-join,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kl
67 | UserParameter=MySQL.locked-transactions,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh go
68 | UserParameter=MySQL.Handler-read-rnd,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mu
69 | UserParameter=MySQL.Handler-delete,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mn
70 | UserParameter=MySQL.Query-time-total-13,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ps
71 | UserParameter=MySQL.Query-time-total-10,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pp
72 | UserParameter=MySQL.Key-buf-bytes-used,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oh
73 | UserParameter=MySQL.Com-delete-multi,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kj
74 | UserParameter=MySQL.Select-range,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kn
75 | UserParameter=MySQL.pending-aio-log-ios,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hh
76 | UserParameter=MySQL.ibuf-inserts,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hq
77 | UserParameter=MySQL.State-copying-to-tmp-table,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lr
78 | UserParameter=MySQL.Com-replace-select,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kk
79 | UserParameter=MySQL.modified-pages,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gt
80 | UserParameter=MySQL.Com-delete,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jy
81 | UserParameter=MySQL.Threads-cached,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh it
82 | UserParameter=MySQL.hash-index-cells-used,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nk
83 | UserParameter=MySQL.uncheckpointed-bytes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nn
84 | UserParameter=MySQL.Query-time-total-12,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pr
85 | UserParameter=MySQL.Qcache-hits,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jn
86 | UserParameter=MySQL.Questions,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ju
87 | UserParameter=MySQL.Qcache-queries-in-cache,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jr
88 | UserParameter=MySQL.key-buffer-size,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oi
89 | UserParameter=MySQL.total-mem-alloc,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nl
90 | UserParameter=MySQL.spin-rounds,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hu
91 | UserParameter=MySQL.ibuf-merged,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hr
92 | UserParameter=MySQL.rows-inserted,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hw
93 | UserParameter=MySQL.file-fsyncs,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gx
94 | UserParameter=MySQL.Bytes-sent,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kx
95 | UserParameter=MySQL.Query-time-total-03,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pi
96 | UserParameter=MySQL.ibuf-merges,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hs
97 | UserParameter=MySQL.Query-time-total-02,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ph
98 | UserParameter=MySQL.pool-reads,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh qo
99 | UserParameter=MySQL.history-list,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gk
100 | UserParameter=MySQL.Query-time-total-05,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pk
101 | UserParameter=MySQL.rows-updated,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hx
102 | UserParameter=MySQL.max-connections,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ix
103 | UserParameter=MySQL.free-pages,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gr
104 | UserParameter=MySQL.Select-scan,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kp
105 | UserParameter=MySQL.pending-aio-sync-ios,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hi
106 | UserParameter=MySQL.recovery-system-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nw
107 | UserParameter=MySQL.Query-time-total-06,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh pl
108 | UserParameter=MySQL.innodb-sem-wait-time-ms,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nz
109 | UserParameter=MySQL.thread-hash-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nx
110 | UserParameter=MySQL.dictionary-cache-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nt
111 | UserParameter=MySQL.ibuf-used-cells,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh no
112 | UserParameter=MySQL.State-end,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ls
113 | UserParameter=MySQL.slave-running,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jg
114 | UserParameter=MySQL.pending-normal-aio-reads,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ho
115 | UserParameter=MySQL.Innodb-row-lock-waits,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ok
116 | UserParameter=MySQL.active-transactions,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gp
117 | UserParameter=MySQL.Sort-range,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kr
118 | UserParameter=MySQL.spin-waits,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ht
119 | UserParameter=MySQL.Slow-queries,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ii
120 | UserParameter=MySQL.ibuf-cell-count,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nq
121 | UserParameter=MySQL.Qcache-free-blocks,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jl
122 | UserParameter=MySQL.Sort-merge-passes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kq
123 | UserParameter=MySQL.thread-cache-size,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iy
124 | UserParameter=MySQL.Key-write-requests,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gi
125 | UserParameter=MySQL.pending-buf-pool-flushes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hj
126 | UserParameter=MySQL.pending-log-writes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hn
127 | UserParameter=MySQL.Com-update-multi,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kh
128 | UserParameter=MySQL.State-login,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lw
129 | UserParameter=MySQL.State-reading-from-net,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ly
130 | UserParameter=MySQL.State-locked,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lv
131 | UserParameter=MySQL.log-bytes-flushed,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lh
132 | UserParameter=MySQL.ibuf-free-cells,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh np
133 | UserParameter=MySQL.Qcache-not-cached,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jq
134 | UserParameter=MySQL.pending-log-flushes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hm
135 | UserParameter=MySQL.Max-used-connections,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ir
136 | UserParameter=MySQL.State-sending-data,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lz
137 | UserParameter=MySQL.rows-read,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hz
138 | UserParameter=MySQL.lock-system-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nv
139 | UserParameter=MySQL.Handler-read-rnd-next,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mv
140 | UserParameter=MySQL.table-cache,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh io
141 | UserParameter=MySQL.rows-deleted,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hy
142 | UserParameter=MySQL.file-system-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nu
143 | UserParameter=MySQL.file-writes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gz
144 | UserParameter=MySQL.pending-chkp-writes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hk
145 | UserParameter=MySQL.additional-pool-alloc,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nm
146 | UserParameter=MySQL.current-transactions,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gn
147 | UserParameter=MySQL.Key-reads,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gh
148 | UserParameter=MySQL.Handler-read-next,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ms
149 | UserParameter=MySQL.Key-writes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gj
150 | UserParameter=MySQL.Query-time-count-01,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh om
151 | UserParameter=MySQL.pool-read-requests,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh qp
152 | UserParameter=MySQL.Open-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ik
153 | UserParameter=MySQL.Query-time-count-13,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oy
154 | UserParameter=MySQL.Com-insert-select,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ki
155 | UserParameter=MySQL.Query-time-count-11,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ow
156 | UserParameter=MySQL.Query-time-count-03,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oo
157 | UserParameter=MySQL.slave-lag,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jj
158 | UserParameter=MySQL.Handler-update,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mz
159 | UserParameter=MySQL.Created-tmp-files,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kw
160 | UserParameter=MySQL.Key-buf-bytes-unflushed,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh og
161 | UserParameter=MySQL.State-preparing,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lx
162 | UserParameter=MySQL.Binlog-cache-disk-use,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ll
163 | UserParameter=MySQL.Slave-open-temp-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jk
164 | UserParameter=MySQL.innodb-tables-in-use,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nh
165 | UserParameter=MySQL.Threads-created,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iv
166 | UserParameter=MySQL.Slave-retried-transactions,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ji
167 | UserParameter=MySQL.State-writing-to-net,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh mj
168 | UserParameter=MySQL.pages-created,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gv
169 | UserParameter=MySQL.Opened-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh il
170 | UserParameter=MySQL.pages-written,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gw
171 | UserParameter=MySQL.database-pages,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gs
172 | UserParameter=MySQL.query-cache-size,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jt
173 | UserParameter=MySQL.page-hash-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ns
174 | UserParameter=MySQL.Innodb-row-lock-time,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oj
175 | UserParameter=MySQL.Table-locks-immediate,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ih
176 | UserParameter=MySQL.binary-log-space,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ln
177 | UserParameter=MySQL.Com-update,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh jv
178 | UserParameter=MySQL.Query-time-count-00,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ol
179 | UserParameter=MySQL.adaptive-hash-memory,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh nr
180 | UserParameter=MySQL.Query-time-count-02,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh on
181 | UserParameter=MySQL.log-writes,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh hg
182 | UserParameter=MySQL.Query-time-count-04,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh op
183 | UserParameter=MySQL.Query-time-count-05,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh oq
184 | UserParameter=MySQL.Query-time-count-06,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh or
185 | UserParameter=MySQL.Query-time-count-07,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh os
186 | UserParameter=MySQL.Query-time-count-08,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ot
187 | UserParameter=MySQL.Query-time-count-09,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ou
188 | UserParameter=MySQL.Open-files,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh ij
189 | UserParameter=MySQL.State-closing-tables,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lq
190 | UserParameter=MySQL.running-slave,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
191 |
--------------------------------------------------------------------------------
/ops-scripts/lnmp_install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #Description:LNMP
3 | #Author:Geekwolf
4 | #Blog:www.linuxhonker.com
5 | # Check if user is root
6 | [ $(id -u) != "0" ] && echo "Error: You must be root to run this script, please use root to install lnmp" && exit 1
7 |
8 | # Set password
9 | while :
10 | do
11 | read -p "Please input the root password of MySQL:" mysqlrootpwd
12 | # read -p "Please input the manager password of Pureftpd:" ftpmanagerpwd
13 | if (( ${#mysqlrootpwd} >= 5 ));then
14 | #&& ${#ftpmanagerpwd} >=5
15 | break
16 | else
17 | echo "least 5 characters"
18 | fi
19 | done
20 |
21 | yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison gd-devel libtool vim-enhanced zip unzip wget
22 |
23 | # install MySQL
24 | directory=`pwd`
25 |
26 | mkdir -p $directory/lnmp/{source,conf}
27 | cd $directory/lnmp/source
28 | wget -c http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
29 | wget -c http://fossies.org/linux/misc/mysql-5.5.32.tar.gz
30 | useradd -M -s /sbin/nologin mysql
31 | mkdir -p /data/data /usr/local/mysql/etc/ /data/run /data/logs;
32 | chown mysql.mysql -R /data/{data,run,logs} /usr/local/mysql/etc/
33 | cd $directory/lnmp/source
34 |
35 | tar xf cmake-2.8.10.2.tar.gz
36 | cd cmake-2.8.10.2
37 | ./configure
38 | make && make install
39 | cd ../
40 | tar zxf mysql-5.5.32.tar.gz
41 | cd mysql-5.5.32
42 | cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
43 | -DMYSQL_DATADIR=/data/data \
44 | -DMYSQL_UNIX_ADDR=/data/run/mysqld.sock \
45 | -DWITH_INNOBASE_STORAGE_ENGINE=1 \
46 | -DENABLED_LOCAL_INFILE=1 \
47 | -DMYSQL_TCP_PORT=3306 \
48 | -DEXTRA_CHARSETS=all \
49 | -DDEFAULT_CHARSET=utf8 \
50 | -DDEFAULT_COLLATION=utf8_general_ci \
51 | -DMYSQL_UNIX_ADDR=/data/data/mysql.sock \
52 | -DWITH_DEBUG=0
53 | make && make install
54 |
55 | # Modify my.cf
56 | sed -i '38a ##############' /usr/local/mysql/etc/my.cnf
57 | /bin/cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
58 | cp support-files/mysql.server /etc/rc.d/init.d/mysqld
59 | chmod 755 /etc/rc.d/init.d/mysqld
60 | chkconfig --add mysqld
61 | chkconfig mysqld on
62 | cd ..
63 | sed -i s#conf=#conf=/usr/local/mysql/etc# /etc/rc.d/init.d/mysqld
64 | # Modify my.cf
65 |
66 | sed -i '28a pid-file=/data/run/mysqld.pid' /usr/local/mysql/etc/my.cnf
67 | sed -i '38a ##############' /usr/local/mysql/etc/my.cnf
68 | sed -i '39a skip-name-resolve' /usr/local/mysql/etc/my.cnf
69 | sed -i '40a basedir=/usr/local/mysql' /usr/local/mysql/etc/my.cnf
70 | sed -i '41a datadir=/data/data' /usr/local/mysql/etc/my.cnf
71 | sed -i '42a general-log' /usr/local/mysql/etc/my.cnf
72 | sed -i '43a general-log-file=/data/logs/access.log' /usr/local/mysql/etc/my.cnf
73 | sed -i '44a log-error=/data/logs/error.log' /usr/local/mysql/etc/my.cnf
74 | sed -i '44a user=mysql' /usr/local/mysql/etc/my.cnf
75 | sed -i '45a #lower_case_table_names = 1' /usr/local/mysql/etc/my.cnf
76 | sed -i '46a max_connections=1000' /usr/local/mysql/etc/my.cnf
77 | sed -i '47a ft_min_word_len=1' /usr/local/mysql/etc/my.cnf
78 | sed -i '48a expire_logs_days = 7' /usr/local/mysql/etc/my.cnf
79 | sed -i '48a query_cache_size=64M' /usr/local/mysql/etc/my.cnf
80 | sed -i '49a query_cache_type=1' /usr/local/mysql/etc/my.cnf
81 | sed -i '50a ##############' /usr/local/mysql/etc/my.cnf
82 | #日志回滚
83 | cat > /etc/logrotate.d/mysqld </dev/null\`' || true
92 | endscript
93 | }
94 | EOF
95 |
96 | /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/data
97 |
98 | chown mysql.mysql -R /data/data
99 | export PATH=$PATH:/usr/local/mysql/bin
100 | echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
101 | source /etc/profile
102 |
103 | /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$mysqlrootpwd\" with grant option;"
104 | /usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "delete from mysql.user where Password='';"
105 | /sbin/service mysqld restart
106 |
107 |
108 | # install PHP
109 | cd $directory/lnmp/source/
110 | wget -c http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
111 | tar xzf libiconv-1.14.tar.gz
112 | cd libiconv-1.14
113 | ./configure --prefix=/usr/local
114 | make && make install
115 | cd ../
116 |
117 | wget -c http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
118 | tar xzf libmcrypt-2.5.8.tar.gz
119 | cd libmcrypt-2.5.8
120 | ./configure
121 | make && make install
122 | /sbin/ldconfig
123 | cd libltdl/
124 | ./configure --enable-ltdl-install
125 | make && make install
126 | cd ../../
127 |
128 | wget -c http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
129 | tar xzf mhash-0.9.9.9.tar.gz
130 | cd mhash-0.9.9.9
131 | ./configure
132 | make && make install
133 | cd ../
134 |
135 | if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
136 | ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
137 | ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
138 | ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
139 | ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
140 | ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
141 | ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
142 | ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
143 | ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
144 | ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
145 | ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
146 | ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib64/libmysqlclient.so.18
147 | ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1
148 | ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick
149 | cp -frp /usr/lib64/libldap* /usr/lib
150 | else
151 | ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
152 | ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
153 | ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
154 | ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
155 | ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
156 | ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
157 | ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
158 | ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
159 | ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
160 | ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
161 | ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib/libmysqlclient.so.18
162 | ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick
163 | ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1
164 | fi
165 |
166 | wget -c http://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz
167 | tar xzf mcrypt-2.6.8.tar.gz
168 | cd mcrypt-2.6.8
169 | /sbin/ldconfig
170 | ./configure
171 | make && make install
172 | cd ../
173 |
174 | wget -c http://kr1.php.net/distributions/php-5.3.24.tar.gz
175 | tar xzf php-5.3.24.tar.gz
176 | useradd -M -s /sbin/nologin www
177 | cd php-5.3.24
178 | ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --enable-inline-optimization --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-debug
179 | make ZEND_EXTRA_LIBS='-liconv'
180 | make install
181 | cp php.ini-production /usr/local/php/etc/php.ini
182 |
183 | #php-fpm Init Script
184 | cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
185 | chmod +x /etc/rc.d/init.d/php-fpm
186 | chkconfig --add php-fpm
187 | chkconfig php-fpm on
188 | cd ../
189 |
190 | wget -c http://pecl.php.net/get/memcache-2.2.5.tgz
191 | tar xzf memcache-2.2.5.tgz
192 | cd memcache-2.2.5
193 | /usr/local/php/bin/phpize
194 | ./configure --with-php-config=/usr/local/php/bin/php-config
195 | make && make install
196 | cd ../
197 |
198 | wget -c http://superb-dca2.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
199 | tar xjf eaccelerator-0.9.6.1.tar.bz2
200 | cd eaccelerator-0.9.6.1
201 | /usr/local/php/bin/phpize
202 | ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
203 | make && make install
204 | cd ../
205 |
206 | wget -c http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
207 | tar xzf PDO_MYSQL-1.0.2.tgz
208 | cd PDO_MYSQL-1.0.2
209 | /usr/local/php/bin/phpize
210 | ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
211 | make && make install
212 | cd ../
213 |
214 | wget -c http://www.imagemagick.org/download/legacy/ImageMagick-6.8.3-10.tar.gz
215 | tar xzf ImageMagick-6.8.3-10.tar.gz
216 | cd ImageMagick-6.8.3-10
217 | ./configure
218 | make && make install
219 | cd ../
220 |
221 | wget -c http://pecl.php.net/get/imagick-3.0.1.tgz
222 | tar xzf imagick-3.0.1.tgz
223 | cd imagick-3.0.1
224 | export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
225 | /usr/local/php/bin/phpize
226 | ./configure --with-php-config=/usr/local/php/bin/php-config
227 | make && make install
228 | cd ../
229 |
230 | # Support HTTP request curls
231 | wget -c http://pecl.php.net/get/pecl_http-1.7.5.tgz
232 | tar xzf pecl_http-1.7.5.tgz
233 | cd pecl_http-1.7.5
234 | /usr/local/php/bin/phpize
235 | ./configure --with-php-config=/usr/local/php/bin/php-config
236 | make && make install
237 | cd ../
238 |
239 | # Modify php.ini
240 | mkdir /tmp/eaccelerator
241 | /bin/chown -R www.www /tmp/eaccelerator/
242 | sed -i '808a extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"' /usr/local/php/etc/php.ini
243 | sed -i '809a extension = "memcache.so"' /usr/local/php/etc/php.ini
244 | sed -i '810a extension = "pdo_mysql.so"' /usr/local/php/etc/php.ini
245 | sed -i '811a extension = "imagick.so"' /usr/local/php/etc/php.ini
246 | sed -i '812a extension = "http.so"' /usr/local/php/etc/php.ini
247 | sed -i '135a output_buffering = On' /usr/local/php/etc/php.ini
248 | sed -i '848a cgi.fix_pathinfo=0' /usr/local/php/etc/php.ini
249 | sed -i 's@short_open_tag = Off@short_open_tag = On@g' /usr/local/php/etc/php.ini
250 | sed -i 's@expose_php = On@expose_php = Off@g' /usr/local/php/etc/php.ini
251 | sed -i 's@;date.timezone =@date.timezone = Asia/Shanghai@g' /usr/local/php/etc/php.ini
252 | sed -i 's@#sendmail_path.*@#sendmail_path = /usr/sbin/sendmail -t@g' /usr/local/php/etc/php.ini
253 | echo '[eaccelerator]
254 | zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
255 | eaccelerator.shm_size="64"
256 | eaccelerator.cache_dir="/tmp/eaccelerator"
257 | eaccelerator.enable="1"
258 | eaccelerator.optimizer="1"
259 | eaccelerator.check_mtime="1"
260 | eaccelerator.debug="0"
261 | eaccelerator.filter=""
262 | eaccelerator.shm_max="0"
263 | eaccelerator.shm_ttl="0"
264 | eaccelerator.shm_prune_period="0"
265 | eaccelerator.shm_only="0"
266 | eaccelerator.compress="0"
267 | eaccelerator.compress_level="9"
268 | eaccelerator.keys = "disk_only"
269 | eaccelerator.sessions = "disk_only"
270 | eaccelerator.content = "shm_only"' >> /usr/local/php/etc/php.ini
271 | #shm_only 只存放在共享内存 disk_only 只存放在硬盘 none 不缓存数据
272 | cat > /usr/local/php/etc/php-fpm.conf < /usr/local/nginx/conf/nginx.conf </etc/rc.d/init.d/nginx <&1 > /dev/null &
655 | }
656 |
657 | function_stop_nginx(){
658 | printf "Stoping Nginx ...\n"
659 | ps -ef | grep "nginx:" | grep -v grep | awk '{print "kill -9 " \$2}' | /bin/sh
660 | }
661 |
662 | function_reload_nginx(){
663 | printf "Reloading Nginx ...\n"
664 | ps -ef | grep "nginx: master process" | grep -v grep | awk '{print "kill -HUP " \$2}' | /bin/sh
665 | }
666 |
667 | function_restart_nginx(){
668 | printf "Restarting Nginx ...\n"
669 | function_stop_nginx
670 | sleep 3
671 | function_start_nginx
672 | }
673 |
674 | if [ "\$1" = "start" ]; then
675 | function_start_nginx
676 | elif [ "\$1" = "stop" ]; then
677 | function_stop_nginx
678 | elif [ "\$1" = "reload" ]; then
679 | function_reload_nginx
680 | elif [ "\$1" = "restart" ]; then
681 | function_restart_nginx
682 | else
683 | printf "Usage: nginx {start|stop|reload|restart} \n"
684 | fi
685 | EOF
686 | chmod +x /etc/rc.d/init.d/nginx
687 | chkconfig --add nginx
688 | chkconfig nginx on
689 | mkdir /usr/local/nginx/run
690 | sed -i s#logs/nginx.pid#run/nginx.pid#g /usr/local/nginx/conf/nginx.conf
691 | #logrotate nginx log
692 | cat > /etc/logrotate.d/nginx << EOF
693 | /usr/local/nginx/logs/*.log {
694 | daily
695 | rotate 7
696 | dateext
697 | create 0664 daemon daemon
698 | sharedscripts
699 | postrotate
700 | /bin/kill -USR1 \`/bin/cat /usr/local/nginx/run/nginx.pid\`
701 | endscript
702 | }
703 | EOF
704 |
705 | ###网站根目录###
706 | mkdir /data/wwwroot
707 | echo '' > /data/wwwroot/index.php
710 | service nginx restart
711 |
712 |
713 | ## install Pureftpd and pureftpd_php_manager
714 | #cd ../source
715 | #wget -c ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.36.tar.gz
716 | #tar xzf pure-ftpd-1.0.36.tar.gz
717 | #cd pure-ftpd-1.0.36
718 | #./configure --prefix=/usr/local/pureftpd CFLAGS=-O2 --with-mysql=/usr/local/mysql --with-quotas --with-cookie --with-virtualhosts --with-virtualchroot --with-diraliases --with-sysquotas --with-ratios --with-altlog --with-paranoidmsg --with-shadow --with-welcomemsg --with-throttling --with-uploadscript --with-language=simplified-chinese
719 | #make && make install
720 | #cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin
721 | #chmod +x /usr/local/pureftpd/sbin/pure-config.pl
722 | #cp contrib/redhat.init /etc/init.d/pureftpd
723 | #sed -i 's@fullpath=.*@fullpath=/usr/local/pureftpd/sbin/$prog@' /etc/init.d/pureftpd
724 | #sed -i 's@pureftpwho=.*@pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho@' /etc/init.d/pureftpd
725 | #sed -i 's@/etc/pure-ftpd.conf@/usr/local/pureftpd/pure-ftpd.conf@' /etc/init.d/pureftpd
726 | #chmod +x /etc/init.d/pureftpd
727 | #chkconfig --add pureftpd
728 | #chkconfig pureftpd on
729 | #
730 | #cd ../../conf
731 | #wget -c https://raw.github.com/lj2007331/lnmp/master/conf/pure-ftpd.conf
732 | #wget -c https://raw.github.com/lj2007331/lnmp/master/conf/pureftpd-mysql.conf
733 | #wget -c https://raw.github.com/lj2007331/lnmp/master/conf/script.mysql
734 | #/bin/cp pure-ftpd.conf /usr/local/pureftpd/
735 | #/bin/cp pureftpd-mysql.conf /usr/local/pureftpd/
736 | #mysqlftppwd=`cat /dev/urandom | head -1 | md5sum | head -c 8`
737 | #sed -i 's/tmppasswd/'$mysqlftppwd'/g' /usr/local/pureftpd/pureftpd-mysql.conf
738 | #sed -i 's/mysqlftppwd/'$mysqlftppwd'/g' script.mysql
739 | #sed -i 's/ftpmanagerpwd/'$ftpmanagerpwd'/g' script.mysql
740 | #/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd< script.mysql
741 | #service pureftpd start
742 | #
743 | #mkdir -p /data/admin
744 | #cd ../source
745 | #wget -c http://acelnmp.googlecode.com/files/ftp_v2.1.tar.gz
746 | #tar xzf ftp_v2.1.tar.gz
747 | #mv ftp /data/admin;chown -R www.www /data/admin
748 | #sed -i 's/tmppasswd/'$mysqlftppwd'/g' /data/admin/ftp/config.php
749 | #IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
750 | #sed -i 's/myipaddress.com/'$IP'/g' /data/admin/ftp/config.php
751 | #sed -i 's/127.0.0.1/localhost/g' /data/admin/ftp/config.php
752 | #sed -i 's@iso-8859-1@UTF-8@' /data/admin/ftp/language/english.php
753 | #rm -rf /data/admin/ftp/install.php
754 | #
755 | echo "################Congratulations####################"
756 | echo "The path of some dirs:"
757 | echo "Nginx dir: /usr/local/nginx"
758 | echo "MySQL dir: /usr/local/mysql"
759 | echo "PHP dir: /usr/local/php"
760 | #echo "Pureftpd dir: /usr/local/pureftpd"
761 | #echo "Pureftp_php_manager dir : /data/admin"
762 | echo "MySQL Password: $mysqlrootpwd"
763 | #echo "Pureftp_manager url : http://$IP/ftp"
764 | #echo "Pureftp_manager Password: $ftpmanagerpwd"
765 | echo "###################################################"
766 | EOF
767 |
--------------------------------------------------------------------------------