搭建私有的apt源

内部搞了个apt源,简单记录一下,主要参考了:http://www.debian-administration.org/articles/286 新建立目录结构mkdir test/{conf,dists,incoming,indices,logs,pool,project,tmp} 2.新建配置文件 2.1 conf/distributionsOrigin: GNUerLabel: GNUer’s repositoryCodename: testingArchitectures: amd64Components: mainDescription: Description of repository you are creating2.2 conf/optionsverboseask-passphrasebasedir . 3.包的维护 导入包需要使用reprepro reprepro -b /home/mirrors/test/ includedeb testing /home/test_deb/dropbox_1.6.0_amd64.deb删除包reprepro -v -b /home/mirrors/test/ remove testing dropbox apt源的配置新增deb http://192.168.2.2/test testing main

July 13, 2013 · 1 min · pm

二分法查找指定时间的日志

二分法是很基础的一个查询方法。试想一个场景,应用的访问量非常大,单天的日志单个文件上100G,要准实时地统计出TPM的大小。没有什么storm之类的高级玩意,就自己写脚本进行统计的话其实不太好搞。这个时候可以试试每次用二分法找出上一分钟的日志所在的偏移量,然后再顺序读入日志进行处理,可以比较高效地跳过大量的日志。python简单写了个 #!/usr/bin/env python import re import datetime import sys class logtools: """this tools can get the bind qps and the ips which query with high frequency""" def __init__(self,filename="/xx/acess.log"): self.logname=filename try: #print "logs is",filename self.fd=open(filename,"r") except IOError: print "open log failed" sys.exit(1) def __del__(self): try: self.fd.close() except: print "close fd failed" def get_last_min(self): now=datetime.datetime.now() last=datetime.datetime.now()+datetime.timedelta(minutes=-2) qps_time=datetime.datetime.now()+datetime.timedelta(minutes=-1) t=qps_time.strftime(‘\s+%H:%M:’) t2=qps_time.strftime(‘%H:%M’) return (int(last.strftime("%s")),t,t2) def get_current_min(self): time_reg=re.compile("\s+(?P\d+):(?P\d+):(?P\d+)") now=datetime.datetime.now() i=1 while True: line=self.fd.readline() if not line: return None match=time_reg.search(line) i=i+1 if match: match_time=datetime.datetime(year=now.year,month=now.month,day=now.day,hour=int(match.group("hour")),minute=int(match.group("min")),second=int(match.group("sec")),) break return int(match_time.strftime("%s")) def get_last_seek(self,last_time): old_seek=self.fd.tell() self.fd.seek(0,0) start_seek=self.fd.tell() start_time=self.get_current_min() pos_off=len(self.fd.readline())*2 self.fd.seek(0,2) end_seek=self.fd.tell() self.fd.seek(-pos_off,2) end_time=self.get_current_min() #print "time range:",start_time,last_time,end_time #print "pos_off:",pos_off if last_time < start_time: print "error last-time return end_seek elif last_time > end_time: print "error %d > %d"%(last_time,end_time) return end_seek time=0 while (end_seek – start_seek > 2*pos_off and end_time – start_time > 3) : half_seek=int((end_seek+start_seek)/2) self.fd.seek(half_seek,0) half_time=self.get_current_min() #print "%d –<%d>—%d"%(start_seek,half_seek,end_seek) if last_time<=half_time: end_seek=half_seek self.fd.seek(end_seek,0) end_time=self.get_current_min() else: start_seek=half_seek self.fd.seek(start_seek,0) start_time=self.get_current_min() time+=1 #print "search %d times"%time return half_seek def get_tpm(self): reg=self.get_last_min()[1]+"\d{2}" reg_time=self.get_last_min()[2] regex=re.compile(reg) time_pre=self.get_last_min()[0] pos=self.get_last_seek(time_pre) self.fd.seek(pos,0) query=0 line=self.fd.readline() while line: if line == None: break elif regex.search(line): query+=1 line=self.fd.readline() print "%s qps %d"%(str(reg_time),query) a=logtools(filename=sys.argv[1]) a.get_tpm()

July 10, 2013 · 1 min · pm

策略路由的配置

最近测试DNS服务器直接和交换机跑OSPF。2上联网卡分别接入2交换机,形成邻居。服务器不设置静态的默认路由,通过和上层路由器交换路由信息的时候学习默认路由。另外的办公网接入的网卡只是绑定了IP。因为是在测试环境所以有个问题是上联的链路其实是不能访问外网的。我就单独设置了一下策略路由解决。需要达到的目的其实只是能从办公网络ssh登陆服务器,服务器上能访问部分外网(比如8.8.8.8进行DNS解析)。配置其实比较简单:1. 先新增策略路由#cat /etc/iproute2/rt_tables## reserved values#255 local254 main253 default0 unspec## local200 dns 2.给table 200增加默认的路由#cat route-eth0table dns 192.1.159.0/24 via 192.1.159.254 dev eth0table dns default via 192.1.159.254 dev eth0 ip route add 192.1.159.0/24 via 192.1.159.254 dev eth0 table dnsip route add default via 192.1.159.254 dev eth0 table dns 3.增加策略路由表#cat rule-eth0from 192.1.159.210 table dnsto 8.8.8.8 table dnsto 192.242.252.0/24 table dns ip rule add to 8.8.8.8 table dnsip rule add from 192.1.159.210 table dnsip rule add to 192.242.252.0/24 table dns

July 6, 2013 · 1 min · pm

gnome-shell下开机亮度的调节

gnome3下现在屏幕的默认亮度不能保存,网上搜了一圈简单的方式是在rc.local里加 echo 70 > /sys/class/backlight/acpi_video0/brightness

July 2, 2013 · 1 min · pm

服务影响时间测量

这几天配置dns集群,为了测试各种场景下的服务影响时间,需要自己写个脚本进行统计。没有什么现成的好的工具,就用python里面的dnspython模块写了个小的脚本 #!/usr/bin/python #****************************************************************## ScriptName: dnsquery.py # Author: GNUer # Create Date: 2013-06-28 12:52 # Modify Author: GNUer # Modify Date: 2013-06-28 12:52 # Function: #*************************************************************** #import dns.resolver import dns.exception import time import datetime import signal import sys def get_time(): t=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") return t def get_mtime(): t=datetime.datetime.now().strftime("%H:%M:%S.%f") return t def get_second(): return time.time() def do_exit(sig,arg): print "exit dns test" sys.exit(1) def dns_test(num,sleep_time): resolver = dns.resolver.Resolver() #resolver.timeout = 0.01 resolver.lifetime =0.0013 #change this time accord to reponse time resolver.nameservers=[‘7.7.7.7′,’6.6.6.6’] testlist=("search.xxx.com","obs.xxx.com","if.xxx.com") last_flag=True fail_start=0 fail_finish=0 for i in range(num): for test in testlist: try: for target in resolver.query(qname=test): print "\x1b[32m",get_time(),test,target,"\x1b[m" if last_flag == False: last_flag= True fail_finish=get_second() errortime=fail_finish-fail_start print "\x1b[1;31m","error time is:",errortime,"\x1b[m" except dns.exception.Timeout: print "\x1b[31m",get_time(),test,"failed","\x1b[m" if last_flag == True: fail_start=get_second() last_flag = False time.sleep(sleep_time) signal.signal(signal.SIGINT,do_exit) dns_test(10000000,0.33) 需要比较注意的是需要根据自己的实际情况把resolver.lifetime设置为比dns服务器的响应时间稍微大一点的值,但是需要小于平均响应时间的2倍。不然测试的时间不是太准确。因为总共测试的域名是3个,所以我把每次sleep的时间设置为0.32左右,使得1s总共能发3个请求左右。测试的时候可以先把这个脚本一直跑着,然后去做各种操作,看中间的影响时间是多少。虽然这个脚本是测试dns的,但是也可以修改一下做HTTP请求等等,方便在做各种HA切换的时候测试影响的时间。 ...

June 28, 2013 · 1 min · pm

一次ssh信任登录失败的排查

昨天遇到有同事帮忙看一下信任登录打通的问题,已经把跳板机的公钥加到服务器上了,但是每次登录都要输入密码。ssh -v看了一下能成功登录的机器是debug1: Next authentication method: publickeydebug1: Trying private key: /home/admin/.ssh/identitydebug1: Offering public key: /home/admin/.ssh/id_rsadebug1: Server accepts key: pkalg ssh-rsa blen 277debug1: read PEM private key done: type RSAdebug1: Authentication succeeded (publickey).debug1: channel 0: new [client-session]debug1: Entering interactive session.不能成功登录的机器是debug1: Next authentication method: publickeydebug1: Trying private key: /home/admin/.ssh/identitydebug1: Offering public key: /home/admin/.ssh/id_rsadebug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,passworddebug1: Trying private key: /home/admin/.ssh/id_dsadebug1: Next authentication method: password区别是不能成功登录的服务器没有接受到私钥。查看一下是.ssh整个目录的宿主uid是有问题:# stat .sshFile: “.ssh”Size: 4096 Blocks: 8 IO Block: 4096 目录Device: ca20h/51744d Inode: 311305 Links: 2Access: (0755/drwxr-xr-x) Uid: ( 500/ UNKNOWN) Gid: ( 500/ XXX)Access: 2013-06-15 23:04:15.000000000 +0800Modify: 2013-04-03 11:24:29.000000000 +0800Change: 2013-06-15 23:04:15.000000000 +0800 ...

June 27, 2013 · 1 min · pm

指定dns查询的超时时间

最近在做些打杂的事情,需要对dns做一下健康检查。脚本直接shell写的,以前的同事的方案只是直接检查一下named进程是否存在,存在就是表示OK的,这个策略显然是有问题的,比如进程假死之类的其实是没有办法检查的。然后我就想着改成nslookup或者host命令进行一个查询,检测返回值,由于nslookup的返回值不能体现出查询是否成功,就只有host可以用了。 check_dns(){local domainlocal serverdomain="www.xxx.com"server=’127.0.0.1′ host -W1 $domain $server &>/dev/nullerror=$?if [ $error -ne $STATUS_OK ];thenwarn "can’t resolve $domain,error."fireturn $error} check_dns(){local domainlocal serverdomain="www.xxx.com"server=’127.0.0.1′dig @$server $domain +time=1 +retry=1 +tries=1 &>/dev/nullerror=$?if [ $error -ne $STATUS_OK ];thenwarn "can’t resolve $domain,error."fireturn $error

June 27, 2013 · 1 min · pm

配置nginx不暂存服务端的响应到缓冲区

nginx做代理的服务器的时候是默认等后端服务器完成响应后再一次把内容返回给用户。这个关键的配置项目是proxy_buffering.proxy_buffering 默认是on [proxy_buffering](http://wiki.nginx.org/HttpProxyModule#proxy_buffers) This directive activate response buffering of the proxied server.If buffering is activated, then nginx reads the answer from the proxied server as fast as possible, saving it in the buffer as configured by directives proxy_buffer_size andproxy_buffers. If the response does not fit into memory, then parts of it will be written to disk.

June 27, 2013 · 1 min · pm

gnome-terminal的常用快捷键

平时很山使用快捷键什么的,主要是经常记不住。不过现在买了个机械键盘就是为了多试试用快捷键提高自己的日常的操作效率(其实主要是不能用小红点了。。。)。刚看下了,其实gnome-terminal自己也带了很多常用的快捷键。我自己单独定义了一个期待term的快捷键是ctrl+alt+t.gnome-terminal的快捷键主要有:新建一个标签页:ctrl+shift+t新建一个窗口:ctrl+shift+n多个标签页的切换可以有2种方式:1.使用alt+数字N 直接切换到第N个标签页。2.使用ctrl+pageup/pagedown做前后的切换关闭一个标签页:ctrl+shift+w关闭整个窗口:ctrl+shift+q

June 21, 2013 · 1 min · pm

vichrome插件使用

今天买了个机械键盘,不过买了机械键盘后第一个感觉是之前用习惯了小红点现在非常不习惯。之前小红点完全可以代替鼠标的很多操作,现在却是很多操作需要另外去用鼠标才能搞定。想起了之前有个浏览器的vi插件就装了下。不过很久没有用这个玩意了早就忘记了。主要需要记住的操作是:t 打开新的标签页o 在当前的表情页打开新的urlctrl+u 向上一页ctrl+d 向下一页上下左右和vim里面一样的k/j h/lctrl+h转向左边的标签页ctrl+l转向右边的标签页/ 搜索 Vichrome’s default key bindings are: j : scroll downk : scroll uph : scroll leftl : scroll right: scroll down: scroll upt : open new tabx : close tabX : Close the current tab and focus the previous tabr : reload tab/ : enter search mode? : enter backward search modea : enter link text search mode(search only text that have a link and focus it)n : next search resultN : previous search resultgg : go to top of the pageG : go to bottom of the pagegt,: move to left tabgT,: move to right tabH : back historyL : forward historyu : restore last closed tabgp : pop out current tab to new windowgs : open source of the current page in a new tabf : enter f Mode (like HIT-A-HINT)F : enter f Mode (open links with new tab)i : focus on first input areao : Open new page with awesome completionO : Open new page in new tab with awesome completions : Google SearchS : Google Search in new tabb : Open bookmarkB : Open bookmark in new tab: page down: page up: page half down: page half up: : enter Command Mode” : back to last auto page markyy : copy URL to clipboardp : Open a URL based on the current clipboard contents in the current tabP : Open a URL based on the current clipboard contents in a new tab: switch tab focus to the previously focused tab,z : toggle image size: cancel all input/command and blur focused element

June 21, 2013 · 2 min · pm