CentOS 下禁止运行screen 或建立新窗口时更改窗口尺寸

Xshell或Putty之类的连接到Centos下使用screen时会改变窗口的尺寸,非常烦人,可以通过如下方法修改使其不更改窗口尺寸。
编辑/etc/screenrc或~/.screenrc 加入下面的代码

# Change the xterm initialization string from is2=\E[!p\E[?3;4l\E[4l\E>
# (This fixes the "Aborted because of window size change" konsole symptoms found
#  in bug #134198)
termcapinfo xterm* 'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l'

Centos/RHEL 6下禁止重复的SNMP连接日志

在默认的情况下,在Centos/RHEL 6下,当SNMPD运行时,系统日志(/var/log/messages)内会产生大量类似如下的记录:

Jan 25 00:30:40 jzbk snmpd[1097]: Connection from UDP: [192.168.1.100]:57460->[192.168.1.1]:161

这是因为正常情况下SNMPD被访问的比较高,在每次远端机器通过SNMPD查询本机的数据时,本机的syslog会记录下每一次访问的信息.

SNMP 日志级别表:

日志等级 说明
0 紧急 – 系统不可用
1 警报– 需要立即采取行动
2 危急 – 临界条件
3 错误 – 错误条件
4 警告 – 警告条件
5 提示 – 提示信息
6 信息 – 提示信息
7 Debugging – Debugging 信息

 

我们可以通过修改SNMPD的启动脚本参数来达到禁止冗余日志提示的作用.
1.编辑 /etc/init.d/snmpd 修改 OPTIONS 变量为以下内容:

OPTIONS="-LS0-5d -Lf /dev/null -p /var/run/snmpd.pid"

2.重启SNMPD来应用修改.

service snmpd restart

Centos MariaDB 5.5.35 编译失败解决办法

在某些Centos上编译MariaDB 5.5.35在make的时候可能会出现以下问题:

root@wsi:/root/src/mariadb-5.5.35# make
.......
[  8%] Building C object mysys/CMakeFiles/mysys.dir/my_context.c.o
cd /root/src/mariadb-5.5.35/mysys && /usr/bin/gcc  -DHAVE_CONFIG_H -Wall  -march=i686 -fPIC -O3 -DNDEBUG -DDBUG_OFF -I/root/src/mariadb-5.5.35/include -I/root/src/mariadb-5.5.35
/mysys    -o CMakeFiles/mysys.dir/my_context.c.o   -c /root/src/mariadb-5.5.35/mysys/my_context.c                                                                              /root/src/mariadb-5.5.35/mysys/my_context.c: Assembler messages:
/root/src/mariadb-5.5.35/mysys/my_context.c:457: Error: CFI instruction used without previous .cfi_startproc
make[2]: *** [mysys/CMakeFiles/mysys.dir/my_context.c.o] Error 1
......

使用以下pactch可以解决编译失败的问题.

--- mariadb-5.5.35/include/my_context.h.org       2014-02-02 21:59:28.724573324 +0800
+++ mariadb-5.5.35/include/my_context.h   2014-02-02 21:59:46.550625376 +0800
@@ -25,17 +25,7 @@
   (This particular implementation uses Posix ucontext swapcontext().)
 */
 
-#ifdef __WIN__
-#define MY_CONTEXT_USE_WIN32_FIBERS 1
-#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__x86_64__) && !defined(__ILP32__)
-#define MY_CONTEXT_USE_X86_64_GCC_ASM
-#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__i386__)
-#define MY_CONTEXT_USE_I386_GCC_ASM
-#elif defined(HAVE_UCONTEXT)
 #define MY_CONTEXT_USE_UCONTEXT
-#else
-#define MY_CONTEXT_DISABLE
-#endif
 
 #ifdef MY_CONTEXT_USE_WIN32_FIBERS
 struct my_context {

Linux使用smartctl检查服务器硬盘状况

1.安装smartmontools.

#CentOS
yum install smartmontools

2.查询通电时间及通电次数

[root@wsi ~]# smartctl -a /dev/sda | grep -E "Power_On_Hours|Power_Cycle_Count"
  9 Power_On_Hours          0x0012   100   100   000    Old_age   Always       -       3987
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       24

3.错误日志查询

[root@wsi ~]# smartctl -l error /dev/sda
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-042stab084.17] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF READ SMART DATA SECTION ===
SMART Error Log Version: 1
No Errors Logged

4.完整检测

[root@wsi ~]# smartctl -t long /dev/sdb
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-042stab084.17] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Extended self-test routine immediately in off-line mode".
Drive command "Execute SMART Extended self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 122 minutes for test to complete.
Test will complete after Sun Feb  2 03:45:23 2014

Use smartctl -X to abort test.

#通过该命令进行磁盘的扩展彻底检查 (大约要持续数小时,应该在低负载进行如果发现错误,基本可以说明需要更换硬盘)

5.查看完整检测日志:

[root@wsi ~]# smartctl -l selftest /dev/sdb
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-042stab084.17] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%      1120         -

Cent0S Tunnelbroker IPV6隧道自动加载

因为服务器ISP给的IPV6不知道什么原因挂掉了.不得不使用Tunnelbroker的IPV6隧道,但是如果使用官方介绍的Linux-net-tools方法进行设置的话,在重启服务器或者执行service network restart之后,IPV6设置会丢失,为了解决这个问题,在各种GOOGLE之后终于找到了一个完美的解决方案.

QQ20140202-2

1.编辑/etc/sysconfig/network,加入以下内容来打开IPV6和设置默认网关:

NETWORKING_IPV6=yes
IPV6_DEFAULTDEV="sit1"

2.编辑/etc/sysconfig/network-scripts/ifcfg-eth0,加入默认IPV6网关地址,请参考上图.
P.S:ifcfg-eth0为你的网卡配置文件,请根据自己的实际情况修改

IPV6ADDR=IPV6网关

3.创建/etc/sysconfig/network-scripts/ifcfg-sit1 配置文件

ONBOOT=yes
DEVICE=sit1
BOOTPROTO=none
IPV6INIT=yes
IPV6TUNNELIPV4=隧道服务器的IPV4
IPV6TUNNELIPV4LOCAL=本机的IPV4地址
IPV6ADDR=本机IPV6开始地址

4.设置完成后,执行/sbin/service network restart,IPV6隧道就应该可以正常工作了,并且在重启之后系统也可以自动加载IPV6地址.

[root@wsi ~]# ping6 ipv6.google.com
PING ipv6.google.com(ord08s08-in-x0e.1e100.net) 56 data bytes
64 bytes from ord08s08-in-x0e.1e100.net: icmp_seq=1 ttl=58 time=13.4 ms
64 bytes from ord08s08-in-x0e.1e100.net: icmp_seq=2 ttl=58 time=13.1 ms
64 bytes from ord08s08-in-x0e.1e100.net: icmp_seq=3 ttl=58 time=13.1 ms
^C
--- ipv6.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2589ms
rtt min/avg/max/mdev = 13.119/13.220/13.421/0.194 ms

[转]Linux下批量删除0K文件(空文件)

find . -name "*" -type f -size 0c | xargs -n 1 rm -f

用这个还可以删除指定大小的文件,只要修改对应的 -size 参数就行,例如:

find . -name "*" -type f -size 1024c | xargs -n 1 rm -f

就是删除1k大小的文件。(但注意不要用 -size 1k,这个得到的是占用空间1k,不是文件大小1k的)。
如果只要删除文件夹或者名字连接等,可以相应的改 -type 参数,具体细节见 man find

转自: http://hi.baidu.com/wuxicn/item/0911d3eecdc01e0f560f1d96

Centos 6.X 下编译安装deluge

1.安装更新源.

rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
wget -c -O /etc/yum.repos.d/linuxtech.repo http://pkgrepo.linuxtech.net/el6/release/linuxtech.repo

2.安装依赖库

yum install GeoIP PyXML SOAPpy boost-filesystem boost-python boost-system boost-thread pyOpenSSL python-chardet python-fpconst python-setuptools python-simplejson python-twisted-core python-twisted-web python-zope-filesystem python-zope-interface pyxdg rb_libtorrent rb_libtorrent-python python-beaker python-mako python-markupsafe python-twisted python-twisted-web

3.编译安装deluge

wget http://download.deluge-torrent.org/source/deluge-1.3.6.tar.gz
tar zxvf deluge-1.3.6.tar.gz
cd deluge-1.3.6/

#开始编译
python setup.py build
python setup.py install

#建立账户
/usr/sbin/groupadd deluge
useradd deluge -g deluge -s /bin/false

4.配置启动文件,把以下文件保存为/etc/init.d/deluge-daemon

#!/bin/bash
#
# Startup script for deluged
#
# chkconfig: - 86 14
# description: deluged is the Deluge bit torrent daemon. It manages torrents
# processname: deluged
# pidfile: /var/run/deluged.pid
# config:

# Source function library.
. /etc/init.d/functions

# Get network config
. /etc/sysconfig/network

[ "${NETWORKING}" = "no" ] && exit 0

prog=deluged
prog2=deluge
lockfile=/var/lock/subsys/deluged
lockfile2=/var/lock/subsys/deluge

LANG="zh_CN.UTF-8" 
LANGUAGE="zh_CN.UTF-8:zh_CN.UTF-8:zh_CN" 
SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en" 
SYSFONT="lat0-sun16"
ulimit -HSn 65535

start() {
  echo -n $"Starting deluged service: "
  daemon --user deluge "$prog $OPTIONS"
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch $lockfile

  echo -n $"Starting deluge web ui: "
  daemon --user deluge "$prog2 --ui web >/dev/null 2>&1 &"
  RETVAL=$(($RETVAL|$?))
  echo
  [ $RETVAL -eq 0 ] && touch $lockfile2

  return $RETVAL
}

stop() {
  echo -n $"Shutting down deluged service: "
  killproc $prog
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f $lockfile

  echo -n $"Shutting down deluge web ui: "
  killproc $prog2
  RETVAL2=$?
  echo
  [ $RETVAL2 -eq 0 ] && rm -f $lockfile2

  return $(($RETVAL|$RETVAL2))
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $prog
        status $prog2
        ;;
  restart)
        stop
        start
        ;;
  reload)
        exit 3
        ;;
  *)
        echo $"Usage: $prog {start|stop|status|restart|reload}"
        exit 1
esac

5.给启动脚本权限&启动deluge

chmod +x /etc/init.d/deluge-daemon
service deluge-daemon start

Centos下编译安装Vnstat.

Vnstat是一个Linux下强大的流量监控软件,使服务器管理员可以使用PHP程序来分析Vnsata的数据库文件来得到可视化的服务器流量图.

1.下载&安装Vnstat

wget http://humdi.net/vnstat/vnstat-1.11.tar.gz
tar zxvf vnstat-1.11.tar.gz
cd vnstat-1.11
make
make install

2.下载&设置init.d启动脚本

wget http://humdi.net/vnstat/init.d/redhat/vnstat -O /etc/init.d/vnstat
chmod +x /etc/init.d/vnstat
service vnstat start
chkconfig vnstat on

3.创建计划任务脚本.

cat << EOF > /usr/sbin/vnstat_dump.sh
#/bin/bash
/usr/bin/vnstat -u -i eth0
EOF

chmod +x /usr/sbin/vnstat_dump.sh

4.设置计划任务
(1).输入crontab -e
(2).加入: */1 * * * * /usr/sbin/vnstat_dump.sh

5.Done