分类:运维技术日期:2018-06-13 - 19:34:41评论:1条作者:老谢
创建top.sh
#!/bin/sh
top -n 1 -b> /tmp/top.txt |
#!/bin/sh
top -n 1 -b> /tmp/top.txt
#注: 所有脚本请放至/usr/local/zabbix/share/scripts中
#注: 该脚本的意思是执行一次top命令并将结果重定向到top.txt
crontab -e
*/1 * * * * /usr/local/zabbix/share/scripts/top.sh > /dev/null |
crontab -e
*/1 * * * * /usr/local/zabbix/share/scripts/top.sh > /dev/null
#注: 使用crond每分钟执行一次脚本,输出最新top数据到top.txt
创建check_process.sh获取进程名
#!/bin/bash
TABLESPACE=`tail -n +8 /tmp/top.txt|awk '{a[$NF]+=$6}END{for(k in a)print a[k]/1024,k}'|sort -gr|head -10|cut -d" " -f2`
COUNT=`echo "$TABLESPACE" |wc -l`
INDEX=0
echo '{"data":['
echo "$TABLESPACE" | while read LINE; do
echo -n '{"{#PROCESSNAME}":"'$LINE'"}'
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ','
fi
done
echo ']}' |
#!/bin/bash
TABLESPACE=`tail -n +8 /tmp/top.txt|awk '{a[$NF]+=$6}END{for(k in a)print a[k]/1024,k}'|sort -gr|head -10|cut -d" " -f2`
COUNT=`echo "$TABLESPACE" |wc -l`
INDEX=0
echo '{"data":['
echo "$TABLESPACE" | while read LINE; do
echo -n '{"{#PROCESSNAME}":"'$LINE'"}'
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ','
fi
done
echo ']}'
注: 最关键的是tail -n +8 /tmp/top.txt|awk ‘{a[NF]+=6}END{for(k in a)print a[k]/1024,k}’|sort -gr|head -10|cut -d” ” -f2这条命令:这条命令的意思是从top.txt文件中取出从第八行到末尾行的数据,然后使用awk对这些数据进行累加,效果是以最后一列为关键字,每个关键字对应的第6列的数值进行累加,输出第六列数据的累加结果和最后一列数据,然后使用sort进行排序,注意这里的参数是使用-gr而不是使用-nr是因为获取到的第六列的值是以KB为单位的,假如某进程占用内存大于10G的话,将会使用科学记数法计数,sort -nr参数无法对科学记数法进行计数,需要将参数改成-gr才行,其中的-r是进行反向排序,同时为了防止zabbix获取到该值是科学记数法获取的值从而无法识别,先将该值/1024将单位变成MB,当zabbix获取到数据后再*1024*1024将该值还原成BYTE单位。head -10是取出占用内存最大的十个进程,然后使用cut对数据进行切分,获得十个进程的进程名。
继续阅读…
分类:运维技术日期:2018-06-11 - 20:58:49评论:0条作者:老谢
MySQL基础监控
通过SHOW STATUS 可以提供服务器状态信息,也可以使用mysqladmin extendedstatus 命令获得。
以下几个参数对Myisam 和Innodb 存储引擎都计数:
- Com_select 执行select 操作的次数,一次查询只累加1
- Com_insert 执行insert 操作的次数,对于批量插入的insert 操作,只累加一次
- Com_update 执行update 操作的次数
- Com_delete 执行delete 操作的次数
以下几个参数是针对Innodb 存储引擎计数的:
- Innodb_rows_read select 查询返回的行数
- Innodb_rows_inserted 执行Insert 操作插入的行数
- Innodb_rows_updated 执行update 操作更新的行数
- Innodb_rows_deleted 执行delete 操作删除的行数
通过以上几个参数,可以很容易的了解当前数据库的应用是以插入更新为主还是以查询操作为主,以及各种类型的SQL 大致的执行比例是多少。对于更新操作的计数,是对执行次数的计数,不论提交还是回滚都会累加。对于事务型的应用,通过Com_commit 和Com_rollback 可以了解事务提交和回滚的情况,对于回滚操作非常频繁的数据库,可能应用编写存在问题。
另外还有几个参数可以了解数据库的基本信息:
- Connections 试图连接Mysql 服务器的次数
- Uptime 服务器工作时间
- Slow_queries 慢查询的次数
继续阅读…
分类:乱七八糟日期:2018-06-09 - 19:30:46评论:14条作者:老谢
自h入手顶配X220以来,深深爱上了X系带来的便携性,1366*768的分辨率外出应用一下没问题,但是长时间使用分辨率太低实在影响效率,所以一直使用外接的显示器,但是最近把外接显示器搬走以后,普分的屏用着实在太难受了,于是折腾一波!
改造项目:
- 屏幕:夏普W23 IPS 1920*1080
- 网卡:BCM94360HMB (1300m 蓝牙4.0)
- 白名单BIOS屏蔽LVSD实现单屏模式
- 蓝牙接口转USB内置无线鼠标适配器
继续阅读…
分类:运维技术日期:2018-05-16 - 15:13:15评论:0条作者:老谢
zabbix_proxy编译安装
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix
yum -y install net-snmp net-snmp-devel curl curl-devel perl-DBI net-snmp-utils
wget https://netix.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.11/zabbix-3.2.11.tar.gz
tar -zxf zabbix-3.2.11.tar.gz
mysql -uroot -proot -e "create database zabbix_proxy character set utf8"
cd zabbix-3.2.11
./configure --prefix=/usr/local/zabbix \
--enable-proxy \
--enable-agent \
--with-mysql=/usr/bin/mysql_config \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-openssl
make install
mysql -uroot -proot zabbix_proxy < database/mysql/schema.sql |
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix
yum -y install net-snmp net-snmp-devel curl curl-devel perl-DBI net-snmp-utils
wget https://netix.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.11/zabbix-3.2.11.tar.gz
tar -zxf zabbix-3.2.11.tar.gz
mysql -uroot -proot -e "create database zabbix_proxy character set utf8"
cd zabbix-3.2.11
./configure --prefix=/usr/local/zabbix \
--enable-proxy \
--enable-agent \
--with-mysql=/usr/bin/mysql_config \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-openssl
make install
mysql -uroot -proot zabbix_proxy < database/mysql/schema.sql
修改/usr/local/zabbix/etc/zabbix_proxy.conf配置文件
Server=IP # zabbix服务端IP
Hostname=wyy_proxy # 必须和WEB页面添加代理时设置的名称一致
LogFile=/tmp/zabbix_proxy.log # 日志文件
DBHost=IP # 数据库IP
DBName=zabbix_proxy # 数据库名
DBUser=user # 数据库用户名
DBPassword=password # 数据库密码 |
Server=IP # zabbix服务端IP
Hostname=wyy_proxy # 必须和WEB页面添加代理时设置的名称一致
LogFile=/tmp/zabbix_proxy.log # 日志文件
DBHost=IP # 数据库IP
DBName=zabbix_proxy # 数据库名
DBUser=user # 数据库用户名
DBPassword=password # 数据库密码
启动proxy服务
/usr/local/zabbix/sbin/zabbix_proxy |
/usr/local/zabbix/sbin/zabbix_proxy
iptables开放端口
iptables -A INPUT -p tcp --dport 10050 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 10050 -j ACCEPT
iptables -A INPUT -p tcp --dport 10051 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 10051 -j ACCEPT
/etc/init.d/iptables save |
iptables -A INPUT -p tcp --dport 10050 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 10050 -j ACCEPT
iptables -A INPUT -p tcp --dport 10051 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 10051 -j ACCEPT
/etc/init.d/iptables save
修改/usr/local/zabbix/etc/zabbix_agentd.conf配置文件
Server=proxyIP #proxyIP为proxy服务器IP
#重启agent端,使配置生效
service zabbix_agentd start |
Server=proxyIP #proxyIP为proxy服务器IP
#重启agent端,使配置生效
service zabbix_agentd start
zabbix_agentd及zabbix_proxy的主机名要与zabbix_server中添加的主机名一致,zabbix_agent的server地址填proxy的地址。
下面是重点
ConfigFrequency=60 #zabbix proxy从zabbix server取得配置数据的频率(秒),默认1小时同步一次!
分类:linux日期:2018-05-08 - 19:39:15评论:0条作者:老谢
在配置zabbix主机的时候,有个items抓snmp的oid输出的是字符串,zabbix3.4可以直接通过正则处理snmp抓到的数据,但是为了oneoaas已经降级到了zabbix 3.2,经过一番搜索可以通过外部脚本来处理抓到的字符串,首先编辑vim /usr/local/zabbix/etc/zabbix_server.conf,关掉externalscripts的注释,然后修改为正确路即可。
snmpwalk -v 2c -c public 192.168.1.1 1.3.6.1.4.1.35047.2.10.7.0抓取到的值为SNMPv2-SMI::enterprises.35047.2.10.7.0 = STRING: “35 loginned users in all”,处理脚本如下:
#!/bin/bash
test=$(snmpwalk -v 2c -c public 192.168.1.1 1.3.6.1.4.1.35047.2.10.7.0)
#test1=`$test | grep '"\d+'`
echo $test | awk '
{
string=$0
len=length(string)
for(i=50; i<=len; i++)
{
tmp=substr(string,i,1)
if(tmp ~ /[0-9]/)
{
str=tmp
str1=(str1 str)
}
}
print str1
}' |
#!/bin/bash
test=$(snmpwalk -v 2c -c public 192.168.1.1 1.3.6.1.4.1.35047.2.10.7.0)
#test1=`$test | grep '"\d+'`
echo $test | awk '
{
string=$0
len=length(string)
for(i=50; i<=len; i++)
{
tmp=substr(string,i,1)
if(tmp ~ /[0-9]/)
{
str=tmp
str1=(str1 str)
}
}
print str1
}'
分类:网络技术日期:2018-05-05 - 11:37:31评论:1条作者:老谢
测试3.2和3.4均可用,通知媒介里面,给三个参数,顺序为:{ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
mail_host = 'smtp.xxx.cn'
mail_user = 'xxx'
mail_pass = 'xxx'
mail_postfix = 'xxx.cn'
def send_mail(to_list,subject,content):
me = mail_user+"@"+mail_postfix
msg = MIMEText(content, 'plain', 'utf-8')
msg["Accept-Language"]="zh-CN"
msg["Accept-Charset"]="ISO-8859-1,utf-8"
if not isinstance(subject,unicode):
subject = unicode(subject)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3]) |
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
mail_host = 'smtp.xxx.cn'
mail_user = 'xxx'
mail_pass = 'xxx'
mail_postfix = 'xxx.cn'
def send_mail(to_list,subject,content):
me = mail_user+"@"+mail_postfix
msg = MIMEText(content, 'plain', 'utf-8')
msg["Accept-Language"]="zh-CN"
msg["Accept-Charset"]="ISO-8859-1,utf-8"
if not isinstance(subject,unicode):
subject = unicode(subject)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
分类:linux日期:2018-04-10 - 10:45:17评论:0条作者:老谢
请优先参考:LNMP安装配置Zabbix搭建企业级监控平台
安装zabbix(CentOS 6.9 X64)
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix
yum -y install net-snmp net-snmp-devel curl curl-devel perl-DBI net-snmp-utils
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.8/zabbix-3.4.8.tar.gz
tar -zxf zabbix-3.4.8.tar.gz
mysql -uroot -proot -e "create database zabbix character set utf8"
cd zabbix-3.4.8
mysql -uroot -proot zabbix < database/mysql/schema.sql
mysql -uroot -proot zabbix < database/mysql/images.sql
mysql -uroot -proot zabbix < database/mysql/data.sql
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-openssl
make install
vim /etc/services
#添加下面的字段
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #Zabbix Trapper
zabbix-trapper 10051/udp #Zabbix Trapper
#修改 zabbix server 配置文件
#注意:DBUser和DBPassword请自行根据实际情况填写数据库用户名及密码
vim /usr/local/zabbix/etc/zabbix_server.conf
DBUser=zabbix
DBPassword=zabbix
cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_server
chmod +x /etc/init.d/zabbix_agentd
#添加mysql client库到系统默认库中:
vim /etc/ld.so.conf
#添加:
/usr/local/mysql/lib
#启动
/etc/init.d/zabbix_server start
mkdir /home/wwwroot/zabbix
cp -r -a frontends/php/* /home/wwwroot/zabbix |
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix
yum -y install net-snmp net-snmp-devel curl curl-devel perl-DBI net-snmp-utils
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.8/zabbix-3.4.8.tar.gz
tar -zxf zabbix-3.4.8.tar.gz
mysql -uroot -proot -e "create database zabbix character set utf8"
cd zabbix-3.4.8
mysql -uroot -proot zabbix < database/mysql/schema.sql
mysql -uroot -proot zabbix < database/mysql/images.sql
mysql -uroot -proot zabbix < database/mysql/data.sql
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-openssl
make install
vim /etc/services
#添加下面的字段
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
zabbix-trapper 10051/tcp #Zabbix Trapper
zabbix-trapper 10051/udp #Zabbix Trapper
#修改 zabbix server 配置文件
#注意:DBUser和DBPassword请自行根据实际情况填写数据库用户名及密码
vim /usr/local/zabbix/etc/zabbix_server.conf
DBUser=zabbix
DBPassword=zabbix
cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_server
chmod +x /etc/init.d/zabbix_agentd
#添加mysql client库到系统默认库中:
vim /etc/ld.so.conf
#添加:
/usr/local/mysql/lib
#启动
/etc/init.d/zabbix_server start
mkdir /home/wwwroot/zabbix
cp -r -a frontends/php/* /home/wwwroot/zabbix
配置fping
yum install epel-release.noarch
yum update
yum install fping
chown root:zabbix /usr/sbin/fping
chmod 710 /usr/sbin/fping
chmod ug+s /usr/sbin/fping
#修改/usr/local/zabbix/etc/zabbix_server.conf,删除FpingLocation=/usr/sbin/fping前的注释。 |
yum install epel-release.noarch
yum update
yum install fping
chown root:zabbix /usr/sbin/fping
chmod 710 /usr/sbin/fping
chmod ug+s /usr/sbin/fping
#修改/usr/local/zabbix/etc/zabbix_server.conf,删除FpingLocation=/usr/sbin/fping前的注释。
分类:网络技术日期:2018-04-09 - 19:23:01评论:6条作者:老谢
需求说明
由于设备量较大,如何有效的备份交换机设备配置文件就成了问题,经过一番搜索和对比,最终决定使用上传配置文件到tftp的方式进行备份,下面的脚本使用telnetlib库进行操作,感谢大D牛倾情技术支持,再次谢过大D神犇。
修改说明
Guge上传的V3.0源码仅支持Cisco的交换机,在大D牛的技术支持下,增加了H3C的支持(部分老版本的H3C可能会备份失败),同时也会按照时间自动分目录进行备份,下一步的想法会加入json的支持以及GUI。
main.py V4.0(测试环境Python 2.7.14)
#!/usr/bin/python
#by Kuhn 2014-03-29
#Updata by Derek.s && Jason 2018-04-09
import sys
import os
import telnetlib
import getpass
import datetime
import pexpect
import re
host = ""
user = "123"
password = "123"
#password = "123"
enpw = "123"
h3cpw = "123"
tftpserver = "8.8.8.8"
now = datetime.datetime.now()
def main():
for host in open("sw.txt", "r").readlines():
dsthost = host.strip('\n')
try:
tn = telnetlib.Telnet(dsthost,port=23,timeout=10)
except:
print "Can't connection %s"%dsthost
continue
#tn.read_until("Username:")
#tn.write(user+"\n")
try:
tn.read_until("Password:")
tn.write(password+"\n")
result = tn.read_some()
rex_h3c_bin_1 = r'%Wrong password'
login_Failed_H3C_1 = re.search(rex_h3c_bin_1, result)
rex_h3c_bin_2 = r'%Username or password is invalid.'
login_Failed_H3C_2 = re.search(rex_h3c_bin_2, result)
except:
print "Connection error %s"%dsthost
continue
#print(login_Failed_H3C_1, login_Failed_H3C_2)
if((login_Failed_H3C_1 is None) and (login_Failed_H3C_2 is None)):
#print("cisco")
try:
tn.write("en\n")
tn.read_until("Password:")
tn.write(enpw+"\n")
tn.read_until("#")
tn.write("copy running-config tftp:\n")
tn.write(tftpserver+"\n")
tn.write(now.strftime("%Y/%m/%d")+"/"+host+"\n")
tn.read_until("#")
tn.close
print now.strftime("%Y/%m/%d") + " " + dsthost + " Backup successful."
except:
print "Connection error %s"%dsthost
continue
else:
#print("H3c")
try:
tn.write(h3cpw+"\n")
tn.read_until(">")
tn.write("tftp "+tftpserver+" put flash:/startup.cfg"+" "+now.strftime("%Y/%m/%d")+"/"+host+"\n")
tn.read_until(">")
tn.close
print now.strftime("%Y/%m/%d") + " " + dsthost + " Backup successful(h3c)."
except:
print "Connection error %s"%dsthost
continue
if __name__=="__main__":
main() |
#!/usr/bin/python
#by Kuhn 2014-03-29
#Updata by Derek.s && Jason 2018-04-09
import sys
import os
import telnetlib
import getpass
import datetime
import pexpect
import re
host = ""
user = "123"
password = "123"
#password = "123"
enpw = "123"
h3cpw = "123"
tftpserver = "8.8.8.8"
now = datetime.datetime.now()
def main():
for host in open("sw.txt", "r").readlines():
dsthost = host.strip('\n')
try:
tn = telnetlib.Telnet(dsthost,port=23,timeout=10)
except:
print "Can't connection %s"%dsthost
continue
#tn.read_until("Username:")
#tn.write(user+"\n")
try:
tn.read_until("Password:")
tn.write(password+"\n")
result = tn.read_some()
rex_h3c_bin_1 = r'%Wrong password'
login_Failed_H3C_1 = re.search(rex_h3c_bin_1, result)
rex_h3c_bin_2 = r'%Username or password is invalid.'
login_Failed_H3C_2 = re.search(rex_h3c_bin_2, result)
except:
print "Connection error %s"%dsthost
continue
#print(login_Failed_H3C_1, login_Failed_H3C_2)
if((login_Failed_H3C_1 is None) and (login_Failed_H3C_2 is None)):
#print("cisco")
try:
tn.write("en\n")
tn.read_until("Password:")
tn.write(enpw+"\n")
tn.read_until("#")
tn.write("copy running-config tftp:\n")
tn.write(tftpserver+"\n")
tn.write(now.strftime("%Y/%m/%d")+"/"+host+"\n")
tn.read_until("#")
tn.close
print now.strftime("%Y/%m/%d") + " " + dsthost + " Backup successful."
except:
print "Connection error %s"%dsthost
continue
else:
#print("H3c")
try:
tn.write(h3cpw+"\n")
tn.read_until(">")
tn.write("tftp "+tftpserver+" put flash:/startup.cfg"+" "+now.strftime("%Y/%m/%d")+"/"+host+"\n")
tn.read_until(">")
tn.close
print now.strftime("%Y/%m/%d") + " " + dsthost + " Backup successful(h3c)."
except:
print "Connection error %s"%dsthost
continue
if __name__=="__main__":
main()
参考:http://mybeibei.net/157.html
最新评论
大D:只能单走一个6了哈哈哈
zwwooooo:买特斯拉和买iPhone的人群其实相似...
平安家属子痕:一直坚持油车,看你写的心里有...
秦大叔:室内每年能开2万公里电车确实划算 ...
灰常记忆:尊贵的特斯拉车主啊,对了一直对单...
拳废神域界:我的车现在平常跑不了啥,就放假...
大峰:电车起步超级快,我油车反正是跟不上,...
Mr.Chou:电车高速上真120和油车120真的有区...
Mr.Chou:18 19年入手的房子现在死的心都有了...
老何:不至于跌得这么狠吧