文件系统异常和修复方法

tune2fs -l /dev/mapper/vm_data-LF_CULGPAPS |grep ‘Filesystem state’|egrep -i ‘dirty|error’
如果显示状态为dirty,或者clean with errors。
umount -f /CULGPAPS
fsck /dev/mapper/vm_data-LF_CULGPAPS 对磁盘进行自检操作
自检完毕之后,再次执行tune2fs -l /dev/mapper/vm_data-LF_CULGPAPS |grep ‘Filesystem state’|egrep -i ‘dirty|error’ 确认状态为clean

cd /etc/lvm/backup/
more vm_data 查看备份信息中记录的pv uuid,执行
pvcreate –restorefile vm_data –uuid v7QHCM-f2fM-eRcr-jqnH-e9XO-A760-jY6jCd /dev/sdc
pvcreate –restorefile vm_data –uuid C8RUEv-tChU-RSpN-c2gH-Odq9-F5Cr-td0Mgo /dev/sdd
恢复vg
vgcfgrestore -f vm_data vm_data
激活vg
vgchange -a y
如果再次出现如下的超级块报错:
ppculgp07:/ # mount -av
mount: wrong fs type, bad option, bad superblock on /dev/mapper/vm_data-LF_CULGPAPS,
missing codepage or helper program, or other error
In some cases useful info is found in syslog – try
dmesg | tail or so
请依次执行如下步骤:
导出lv的磁盘信息:
dumpe2fs /dev/mapper/vm_data-LF_CULGPAPS > /tmp/lipeng
在磁盘信息中查看super block的信息,会包括一个主超级块和多个备份超级块的信息,mount文件系统失败原因为主超级块故障导致
cat /tmp/lipeng|grep -i super|grep -i block
ppculgp03:/CULGPAPS/usr # cat /tmp/lipeng|grep -i super|grep -i block
Primary superblock at 0, Group descriptors at 1-5
Backup superblock at 32768, Group descriptors at 32769-32773
Backup superblock at 98304, Group descriptors at 98305-98309
Backup superblock at 163840, Group descriptors at 163841-163845
Backup superblock at 229376, Group descriptors at 229377-229381
Backup superblock at 294912, Group descriptors at 294913-294917
使用备份超级块,开始恢复磁盘信息,注意红字部分为上面查看得到的block id
e2fsck -b 229376 -f -y /dev/mapper/vm_data-LF_CULGPAPS
系统自动根据超级块信息修复,该操作可能耗时很长。执行完毕之后,对于磁盘再次进行自检,确认无问题
fsck /dev/mapper/vm_data-LF_CULGPAPS
自检无问题之后,再次mount文件系统
mount -av
系统自动修复的文件系统,会把信息全部保存在/CULGPAPS/lost+found目录下,注意使用mv命令移动文件夹位置。

A network traffice control script edited for our env

#!/bin/bash
# Borrowed from linux.org/how-to
# Edited by Zengqiang Xie XTS DC UnionPay
# tc uses the following units when passed as a parameter.
# kbps: Kilobytes per second
# mbps: Megabytes per second
# kbit: Kilobits per second
# mbit: Megabits per second
# bps: Bytes per second
# Amounts of data can be specified in:
# kb or k: Kilobytes
# mb or m: Megabytes
# mbit: Megabits
# kbit: Kilobits
# To get the byte figure from bits, divide the number by 8 bit
#
#
# Name of the traffic control command.
TC=/sbin/tc
# The network interface we're planning on limiting bandwidth.
IF=eth0 # Interface
# Download limit (in mega bits)
DNLD=1mbit # DOWNLOAD Limit
# Upload limit (in mega bits)
UPLD=1mbit # UPLOAD Limit
# IP address of the machine we are controlling
IP=0.0.0.0/0 # Host IP
# Filter options for limiting the intended interface.
U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32"

start() {
# We'll use Hierarchical Token Bucket (HTB) to shape bandwidth.
# For detailed configuration options, please consult Linux man
# page.
$TC qdisc add dev $IF root handle 1: htb default 30
$TC class add dev $IF parent 1: classid 1:1 htb rate $DNLD ceil $DNLD
$TC class add dev $IF parent 1: classid 1:2 htb rate $UPLD ceil $UPLD
$U32 match ip dst $IP flowid 1:1
$U32 match ip src $IP flowid 1:2
# The first line creates the root qdisc, and the next two lines
# create two child qdisc that are to be used to shape download
# and upload bandwidth.
#
# The 4th and 5th line creates the filter to match the interface.
# The 'dst' IP address is used to limit download speed, and the
# 'src' IP address is used to limit upload speed.
}

stop() {
# Stop the bandwidth shaping.
$TC qdisc del dev $IF root
}
restart() {
# Self-explanatory.
stop
sleep 1
start
}

show() {
# Display status of traffic control status.
$TC -s qdisc ls dev $IF
}

##main function added by zqxie
case "$1" in
start)
echo -n "Starting bandwidth shaping: "
start
echo "done"
;;
stop)
echo -n "Stopping bandwidth shaping: "
stop
echo "done"
;;
restart)
echo -n "Restarting bandwidth shaping: "
restart
echo "done"
;;
show)
echo "Bandwidth shaping status for $IF:"
show
echo ""
;;
*)
pwd=$(pwd)
echo "Usage: qos.sh {start|stop|restart|show}"
;;
esac
exit 0

linux ip命令

1、ip网卡信息
ip link list
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 1000
link/ether 00:16:3e:00:04:b5 brd ff:ff:ff:ff:ff:ff
3: eth1: mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 1000
link/ether 00:16:3e:00:04:12 brd ff:ff:ff:ff:ff:ff

2、地址信息
ip address show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:16:3e:00:04:b5 brd ff:ff:ff:ff:ff:ff
inet 10.169.16.154/21 brd 10.169.23.255 scope global eth0
valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:16:3e:00:04:12 brd ff:ff:ff:ff:ff:ff
inet 121.42.136.161/22 brd 121.42.139.255 scope global eth1
valid_lft forever preferred_ft forever

3、路由信息
ip route show
default via 121.42.139.247 dev eth1
10.0.0.0/8 via 10.169.23.247 dev eth0
10.169.16.0/21 dev eth0 proto kernel scope link src 10.169.16.154
100.64.0.0/10 via 10.169.23.247 dev eth0
121.42.136.0/22 dev eth1 proto kernel scope link src 121.42.136.161
127.0.0.0/8 dev lo scope link
169.254.0.0/16 dev eth0 scope link
172.16.0.0/12 via 10.169.23.247 dev eth0

4、mac 地址信息
ip neigh show
121.42.139.247 dev eth1 lladdr 00:00:0c:9f:f3:20 REACHABLE
10.169.23.21 dev eth0 lladdr 00:16:3e:00:b3:ff STALE
10.169.23.249 dev eth0 lladdr 00:2a:6a:b6:77:3c STALE
10.169.23.248 dev eth0 lladdr 00:2a:6a:b1:a3:7c STALE
121.42.139.249 dev eth1 lladdr 00:2a:6a:b6:77:3c STALE
10.169.23.247 dev eth0 lladdr 00:00:0c:9f:f2:bc STALE
121.42.139.248 dev eth1 lladdr 00:2a:6a:b1:a3:7c STALE

删除 mac 地址
ip neigh delete 9.3.76.43 dev ethic

5、路由规则
ip rule list
0: from all lookup local
32766: from all lookup main
32767: from all lookup default

first local 、then main、then default。

关于 tc 的信息
http://tldp.org/HOWTO/Traffic-Control-HOWTO/

docker学习笔记01

1、we can show a list of current containers using the docker ps -a command.
By default, when we run just docker ps, we will only see the running containers.
When we specify the -a flag, the docker ps command will show us all containers,
both stopped and running.
You can also use the docker ps command with the -l flag to show the last
container that was run, whether it is running or stopped.

2、Starting a stopped container
docker start bob_the_container(your container name).
We could also refer to the container by its container ID instead.
docker start aa3f365f0f4e

3、how to daemonized containers:
docker run –name daemon_dave -d ubuntu /bin/sh -c “while ↩
true; do echo hello world; sleep 1; done”
see what happen inside a docker:
docker logs daemon_dave
docker logs -f daemon_dave
docker logs -ft daemon_dave (add timestamps)

4、inspect docker’s process
docker top daemon_dave
docker inspect –format ‘{{ .NetworkSettings.IPAddress }}’

5、delete a container
docker rm 80430f8d0921
delete all containers
docker rm `docker ps -a -q`

一次服务器CPU升高的问题分析过程

1、检查占有cpu较高的进程和线程信息
ps H -e -o pid,tid,pcpu,cmd –sort=pcpu |more

3765 4254 6.3 receiver 0
3835 3835 6.5 sender 0
3781 4108 6.5 receiver 4
3781 4107 6.5 receiver 4
3837 3837 6.5 sender 1
3781 4094 6.5 receiver 4
2、分析占有cpu最高的进程的系统调用,确认什么操作导致繁忙
strace -o output.txt -T -tt -e trace=all -p 3767
tail -f output.txt

10:19:10.540731 nanosleep({0, 1000000}, NULL) = 0 <0.001125>
10:19:10.542406 accept(13, 0x7fff44967490, [16]) = -1 EAGAIN (Resource temporarily unavailable) <0.000214>
10:19:10.543076 nanosleep({0, 1000000}, NULL) = 0 <0.001127>
10:19:10.544876 accept(13, 0x7fff44967490, [16]) = -1 EAGAIN (Resource temporarily unavailable) <0.000222>
10:19:10.546111 nanosleep({0, 1000000}, NULL) = 0 <0.001307>
确认为频繁循环执行导致

分析linux各进程占有内存和swap数据库的脚本工具

Linux下没有工具能够快速统计所有进程占有内存和swap大小的工具,以下脚本可以完成该任务。
ps -eo pid,comm|while read line
do
SWAPSUM=0
MEMSUM=0
PID=`echo $line|awk ‘{print $1}’`
PROGNAME=`echo $line|awk ‘{print $2}’`
MEMSUM=`grep -i rss /proc/$PID/smaps 2>/dev/null|awk ‘BEGIN{sum=0}{sum+=$2}END{print sum}’`
SWAPSUM=`grep -i swap /proc/$PID/smaps 2>/dev/null|awk ‘BEGIN{sum=0}{sum+=$2}END{print sum}’`
if [ $MEMSUM -eq 0 ]
then
continue
else
echo “PID=$PID – MEM Resident: $MEMSUM Swap used: $SWAPSUM – ($PROGNAME )”
fi
done