debian cpufreq配置

x220在windows下的待机一直是非常好的,但是在debian下经常耗电非常快,而且很烫。因为gnome3下设置cpu频率的那个插件不能使用了。所以就直接修改一下配置文件。因为获取电池电量有点问题,所以就把那部分去掉了。[General]pidfile=/var/run/cpufreqd.pidpoll_interval=2verbosity=4#enable_remote=1#remote_group=root#定义一般模式 0.8G-2.3G ondemand[/General][Profile]name=ac_normalminfreq=1000000maxfreq=2300000policy=ondemand[/Profile] [/Profile] #定义高性能模式[Profile]name=performance_highminfreq=1600000maxfreq=2300000policy=performance[/Profile] 这样插上电源的时候使用 ondemand模式,cpu的频率设置为1g-2.3G,拔掉电源后使用 conservative,cpu的频率设置为0.8g-1.6g。不过现在风扇设置好像还有点问题,需要继续配置一下thinkfan才行。 今天只是把thinkfan安装上了,增加了模块加载的参数pm@debian:/etc/modprobe.d$ cat /etc/modprobe.d/thinkfan.confoptions thinkpad_acpi fan_control=1

September 23, 2012 · 1 min · pm

shell版本的12306等待

看微博上大家在搞就搞了一个 #!/bin/bas h stty erase ^H hello(){ echo -e "\e[1; 31m欢迎使用铁路客运服务中心\e[m" echo "=======================" echo -e -n "\e[1; 34m用户名:\e[m" read echo -e -n "\e[1; 34m密码:\e[m" stty - echo read stty echo ```bash echo -e "\n=======================\n" } wait_2m(){ second=120 length=240 ```bash while [ $second -gt 0 ] do sleep 1; second=$((second -1 )) length=$((length -2 )) echo -e -n "\r您前面还有\e[1; 32m$length\e[m人在等待,您还需要等待\e[32m$second\e[m秒" done echo -e "\e[1; 32m\n恭喜您,轮到您购票了!\e[m" } hello wait_2m 运行示范

September 18, 2012 · 1 min · pm

ssl证书有效性检测

因为公司的业务原因,所以基本上全站都是使用https。然后又因为各种各样的问题造成有的域名不能使用通配符证书,只能使用单独的证书,这样就造成了网络配置上同一个应用要配置多个公网IP以便绑定不同的证书(很多浏览器不支持SNI,所以只能配置多个IP了)。今天简单写了一个脚本,测试了一下可以把某个机房全站应用的公网IP对于的证书都检查一遍。 脚本如下: #!/usr/bin/env perl#===============================================================================## FILE: comcheck.pl## USAGE: perl comcheck.pl host_list## DESCRIPTION: test ssl cert## OPTIONS: —# REQUIREMENTS: —# BUGS: —# NOTES: —# AUTHOR: @GNUer ); if ( !( ref $sock eq "IO::Socket::SSL" ) ) {print "connect $hostname failed\n"; return 1; }if ( $sock->verify_hostname( $hostname, ‘http’ ) ) {print "$hostname verification ok\n"; return 0; }else {print STDERR "$hostname verify failed\n"; }my $comname = $sock->peer_certificate("commonName"); my $tname = $hostname; my $tcom = $comname; $tname =~ s/\.xxx.com//g; $tcom =~ s/\.xxx.com//g; if ( $tcom eq "*" && $tname !~ /\./ ) {; print "$hostname $comname\n"; }elsif ( $tname eq $tcom ) {; # print "$hostname eq $comname\n"; }else { } ...

September 18, 2012 · 1 min · pm

LVS负载均衡之DR模式

继续上一篇文章是直接写的TUN模式,现在简单的试试DR模式,其实 DR模式的配置和TUN模式的配置基本类似的。主要就是把keepalived里面的TUN改成DR就行,然后RS上绑定VIP的脚本稍微修改一下,直接把VIP绑定在loopback地址上。DR模式的原理示意图如下 DR模式下RS的配置脚本有一点不同 ###############################DR mode Realserver#############################VIP=10.253.3.21case “$1” instart)NO=0for IP in $VIPdoNO=$((NO+1))ip addr add $IP/32 br $IP label lo:$NO dev lodone echo “1” >/proc/sys/net/ipv4/conf/lo/arp_ignore echo “2” >/proc/sys/net/ipv4/conf/lo/arp_announce echo “1” >/proc/sys/net/ipv4/conf/all/arp_ignore echo “2” >/proc/sys/net/ipv4/conf/all/arp_announce echo “RealServer Start OK”; ; stop)NO=0for IP in $VIPdoNO=$((NO+1))ip addr del $IP/32 br $IP label lo:$NO dev lodone echo “0” >/proc/sys/net/ipv4/conf/lo/arp_ignore echo “0” >/proc/sys/net/ipv4/conf/lo/arp_announce echo “0” >/proc/sys/net/ipv4/conf/all/arp_ignore echo “0” >/proc/sys/net/ipv4/conf/all/arp_announce echo “RealServer Stoped”; ; *) echo “Usage: $0 {start|stop}”exit 1esacexit 0 其实总体来说我还是比较倾向于流量比较小的网站直接使用nginx或者haproxy。使用lvs的配置虽然不麻烦,但是排查问题的时候还是相对麻烦,不抓包很难搞。 ...

September 15, 2012 · 1 min · pm

LVS负载均衡之tun模式

lvs常用的模式就三种,分别是DR、TUN和NAT。其中DR模式的性能最好,但需要Director和RS至少能有在同一VLAN下直接连接,比较适合一个CDN节点下的使用,作为顶层的负载设备对haproxy集群进行负载均衡,haproxy集群通过url hash提高缓存的命中率。NAT模式因为进出的流量都要通过Director,所以如果不使用万兆网卡的本身的网络是瓶颈,而且NAT也会比较耗性能一些,还需要把RS的网关指向Director,实用的价值不是太大,不过现在淘宝做的fullnat还比较好,把部署的架构难度降低了,但是官方的内核和keepalived都还没有合并进去,而且也只有2.6.32 rhel版本内核才能跑,广泛实用性也不是很大。TUN模式其实是从DR模式演化来的,主要是解决了Director和RS跨网段的情况。 其结构比较简单,当用户发出来包达到Director的时候,会把请求的包封装进一个IPIP包,然后发给一个RS,RS接受到包后解包还原成原始的包,然后再进行进一步的处理。需要注意的是Director上不是用内核的ipip处理函数进行标准的封转。 LVS-Tun is an LVS original. It is based on LVS-DR. The LVS code encapsulates the original packet (CIP->VIP) inside an ipip packet of DIP->RIP, which is then put into the OUTPUT chain, where it is routed to the realserver. (There is no tunl0 device on the director; ip_vs() does its own encapsulation and doesn’t use the standard kernel ipip code. This possibly is the reason why PMTU on the director does not work for LVS-Tun – seeMTU.) The realserver receives the packet on a tunl0 device (seeneed tunl0 device) and decapsulates the ipip packet, revealing the original CIP->VIP packet. 简单的配置一下tun模式的双机互备结构,如果机器不够就把备机撤掉。 ...

September 15, 2012 · 2 min · pm

vncserver安装配置

因为工作需要,经常需要远程登陆windows的机器,windows的跳板机又经常不是太稳定,经常遇到登陆不了的问题。所有就打算使用vnc来登陆一个linux的机器,把这个linux机器上安装rdp 客户端来做windows的跳板机。简单的在 centos下配置了一下还是比较简单,其他发行版原理也类似。 1.vnc的安装yum install gnome-session dbus-x11.x86_64 dbus.x86_64 rdesktop.x86_64 gnome-terminal.x86_64 firefox vnc-server.x86_64 2.系统的vnc配置 (/etc/sysconfig/vncservers)VNCSERVERS=”4:admin 5:root” #每个用户都需要添加在这里面,4和5分别表示display的id,每个用户监控的端口不同##用vnc客户端就分别是5904和5905,用网页打开就分别是5804和5805VNCSERVERARGS[2]=”-geometry 1024×768 3.每个用户的vnc配置,直接以新增一个用户vnctest为例进行配置useradd vnctest -msu vnctestvncpasswd 输入密码修改用户的vnc配置文件运行 vncserver 自动生成 xstartup可以看到目录下生成的文件是: test1.net:3.log 等就vncserver -kill :3杀掉本用户的这个服务,修改配置unset SESSION_MANAGERexec /etc/X11/xinit/xinitrc [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresourcesxsetroot -solid greyvncconfig -iconic &gnome-session & 也可以直接在vnctest用户下执行 vncserver :6这时可以使用 vnc client连接 test1.net:5906 4.远程linux服务器上登陆windows服务器rdesktop -z -a 32 -g “1024×768” -u Administrator 10.1.0.51

September 14, 2012 · 1 min · pm

mfs试用

晚上闲着不想做其他的就测试了一下mfs,觉得还是比较简单的。主要就是把master服务器安装好,然后安装metalog服务器再安装chunkserver服务器。简单地记录了一下。需要安装fuse-libs.x86_64 fuse-devel.x86_64 fuse.x86_64(注意挂载机器上要加载fuse模块)从http://pro.hit.gemius.pl/hitredir/id=p4CVHPOzkVa0JJIK.m0Ee6dyHZEgoQb1KaiPmVK29EX.M7/url=moosefs.org/tl_files/mfscode/mfs-1.6.26.tar.gz直接搞了6个测试机器来装,在一台编译好后直接拷贝到另外几个机器上去了。1.master配置基本不需要修改,主要是根据配置文件的范例看看有没有需要改的。mfsexports.cfg根据自己的需求来改10.xx.xx.0/24 / rw,mapall=admin:admin,password=test,maxtrashtime=2m#设置2分钟回收被删除的文件空间 然后把$DIR/var/mfs下的 metadata.mfs.empty复制一份为 metadata.mfs就可以启动了。chown admin:admin /opt/mfs/var/mfs/opt/mfs/sbin/mfsmaster start2.metalog的配置cp mfsmetalogger.cfg.dist mfsmetalogger.cfg然后修改master的hostMASTER_HOST = 10.xx.xx.xx启动metalog服务/opt/mfs/sbin/mfsmetalogger start 4.客户端挂载[test6] /opt/mfs/bin/mfsmount /home/admin/testmfs -H 10.253.85.205 -p/opt/mfs/bin/mfsmount -m /home/admin/meta/ -H 10.253.85.205 -p输入密码即可 速度测试$ dd if=/dev/zero of=testmfs/bigfile count=1024 bs=10240001024+0 records in1024+0 records out1048576000 bytes (1.0 GB) copied, 11.3596 seconds, 92.3 MB/s本地磁盘测试 $ dd if=/dev/zero of=bigfile count=1024 bs=10240001024+0 records in1024+0 records out1048576000 bytes (1.0 GB) copied, 4.5809 seconds, 229 MB/s 测试在客户端上进行删除后文件实际上没有被删除掉。 设置每个目录的份数: ```bash /opt/mfs/bin/mfssetgoal -r 1 /home/admin/testmfs/test1 ```bash $ /opt/mfs/bin/mfsgetgoal -r /home/admin/testmfs/test2/home/admin/testmfs/test2:directories with goal 3 : 测试:分别向test1和test2写入1G的文件,可以统计出chunkserver上的空间分别减少了1G和3G。当设置的份数增加的时候写入的速度也慢了很多。$ dd if=/dev/zero of=test1/bb count=1024 bs=10240001024+0 records in1024+0 records out1048576000 bytes (1.0 GB) copied, 11.7595 seconds, 89.2 MB/s ```bash $ dd if=/dev/zero of=test2/bb4 count=1024 bs=10240001024+0 records in1024+0 records out1048576000 bytes (1.0 GB) copied, 18.9833 seconds, 55.2 MB/s 可以使用mfsfileinfo 查看每个文件分每个份数 删除后的文件可以在meta目录下看到可以直接mv ‘00000003|bigfile2’ undel/ 这样恢复文件各在删除test1和test2下删除1G的文件后总空间2分钟后减少了4G ```bash 启动顺序:masterserver->chunkserver->metalogserver/opt/mfs/sbin/mfsmaster start/opt/mfs/sbin/mfschunkserver start/opt/mfs/sbin/mfsmetalogger start

September 9, 2012 · 1 min · pm

haproxy ssl测试

haproxy终于还是打算直接支持ssl了,目前是放出了一个测试版本的。简单的测试了一下,现在是可以跑起来的。 [测试版本](http://haproxy.1wt.eu/download/1.5/src/snapshot/haproxy-ss-20120904.tar.gz)globallog 127.0.0.1 local1 noticemaxconn 40960uid 99gid 99nbproc 4daemonstats socket /opt/haproxyssl/haproxy.stats level admin ```bash defaultslog globalmode httpoption dontlognullretries 3option redispatchmaxconn 2000contimeout 5000clitimeout 50000srvtimeout 50000frontend httpsbind-process 1,2bind :443 ssl /opt/haproxyssl/cert2/mulapp.crtdefault_backend httpbackend httpbind-process 3mode httpserver pp1 127.0.0.1:80 weight 10 check inter 2000 rise 2 fall 4listen stats 0.0.0.0:8000maxconn 10bind-process 4mode httpstats refresh 30sstats uri /statsstats realm haproxystats auth admin:admin 目前还没有证书的文档说明具体怎么用,只是邮件列表有提到,就照着配置了一下。可以使用bind-process把负责接收请求和ssl加解密的单独绑定到特定的进程。bind后面的ssl指令是指定ssl证书的,需要注意的是证书的格式是和stunnel用的类似的。对于证书链的配置是把依次把服务器证书,…,根证书追加到文件,然后再 把key追加到最后,我也试过直接把key放最前面也是可以的,看来是可以自动识别出来的。

September 4, 2012 · 1 min · pm

convert putty key to openssh key

有的合作方给的是putty生成的私钥,为了方便使用需要 把putty格式的转化成openssh格式的pm@debian:~$ puttygen –helpPuTTYgen unidentified build, Jun 22 2012 15:52:56Usage: puttygen ( keyfile | -t type [ -b bits ] )[ -C comment ] [ -P ] [ -q ][ -o output-keyfile ] [ -O type | -l | -L | -p ]-t specify key type when generating (rsa, dsa, rsa1)-b specify number of bits when generating key-C change or specify key comment-P change key passphrase-q quiet: do not display progress bar-O specify output type:private output PuTTY private key formatprivate-openssh export OpenSSH private keyprivate-sshcom export ssh.com private keypublic standard / ssh.com public keypublic-openssh OpenSSH public keyfingerprint output the key fingerprint-o specify output file-l equivalent to `-O fingerprint’-L equivalent to `-O public-openssh’-p equivalent to `-O public’ 1.如果对方给的ppk是带密码的,可以使用puttygen把秘密去掉puttygen xxx.ppk -P输入原有的密码后,新密码为空就行了。2.把ppk格式的转化成openssh的puttygen xxx.ppk -o xxx.txt -O private-openssh这样就可以把xxx.ppk导出为 openssh 的私钥xxx.txt ...

August 30, 2012 · 1 min · pm

使用SquashFS 来压缩usr目录

usr目录下都是一些小的文件,因此当时du -ms /usr 的时候就可以看到花的时间非常得长,我们可以把usr目录压缩成一个squashfs只读文件系统,可以大大降低在usr目录下频繁读取小文件时耗的时间 pm@debian:~$ time du -ms /usr3231 /usr real 0m38.376suser 0m0.124ssys 0m0.892 这个是我du一下usr目录花的时间,当把/usr目录换成压缩的squashfs的时候大概只需要1秒多。具体的操作可以参考这里。 [这里](http://tldp.org/HOWTO/html_single/SquashFS-HOWTO/) mksquashfs /usr /path/readusr 这样就可以压缩好usr目录了。然后修改一下fstab /path/readusr /usr squashfs ro,defaults 0 0 mount -a就可以直接挂载上了,需要说明的是这个时候/usr分区不能写入的,即系统不能升级等,只有特定的场景才能用上。

August 27, 2012 · 1 min · pm