联系我们:416326801#qq.com(#改成@)

Latest from the blog

Linux挂载新硬盘

标签: Shell Linux

#硬盘分区,创建1个分区
fdisk /dev/vdb
n
p
1
#回车,默认值
#回车,默认值
w

#格式化硬盘
mkfs.ext3 /dev/vdb1
#挂载到目录
mkdir /mydata
mount /dev/vdb1 /mydata

#开机自动挂载
echo '/dev/vdb1 /mydata ext3 defaults 0 0' >> /etc/fstab

Linux增加新硬盘扩展VolGroup空间大小

标签: Shell Linux

fdisk -l | grep dev
#硬盘分区,创建1个分区
fdisk /dev/sdc
n
p
1
#回车,默认值
#回车,默认值
w
#建立物理卷 
pvcreate /dev/sdc1
#把新物理卷加入到卷组中去
vgextend VolGroup /dev/sdc1
#把新的空间加到逻辑卷中去
lvextend -L +40G /dev/mapper/VolGroup-lv_root
#激活之后用df -h就可以看到了
resize2fs -p /dev/mapper/VolGroup-lv_root
df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   77G   36G   38G  49% /
tmpfs                         935M     0  935M   0% /dev/shm
/dev/sda1                     485M   32M  428M   7% /boot

已有的lv逻辑卷,把所有剩余空间都加到逻辑卷

#把所有剩余空间加到逻辑卷中去
lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root
新的lv逻辑卷
lvcreate -l +100%FREE -n home VolGroup
mkfs.ext3 /dev/VolGroup/lv_home
mkdir /home
mount /dev/VolGroup/lv_home /home
df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       18G  671M   16G   5% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/vda1             477M   32M  420M   8% /boot
/dev/mapper/VolGroup-lv_home
                       99G  188M   94G   1% /home
修改/etc/fstab,开机自动挂载
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=de016c21-a3a6-43f1-89e3-046f55d67ade /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/mapper/VolGroup-lv_data /data                       ext4    defaults        1 2

重新挂载

umount -a & mount -a

服务器ping监控脚本

标签: Shell Linux ping

[root@zzfwb src]# cat monitor_ping.sh
#!/bin/sh

#ping count
COUNT=30

#if lose% > max%
MAX=80

#nowtime
LogFileName=/var/ping/monitor_$(date "+%Y%m%d%H%M%S").log
HostFileName=/var/ping/host_$(date "+%Y%m%d%H%M%S").txt

#list_hosts
curl  http://api.zzfwb.com/monitor/list_hosts.php >  $HostFileName

for ipadd in `cat $HostFileName`
do
  timing=`date "+%Y-%m-%d %H:%M:%S"`
  PingFileName=/var/ping/ping_${ipadd}_$(date "+%Y%m%d%H%M%S").log
  ping -i 0.2 $ipadd -c $COUNT > $PingFileName
  losspag=`grep "packet loss" $PingFileName |awk '{print $6}' |sed 's/%//g'`
  FLAG=`grep "min/avg/max" $PingFileName -c`
  if [ $losspag -ge $MAX ] ;
  then
    STR=`echo -n "$timing|$ipadd|$losspag|$COUNT|down|$FLAG" | base64`
    echo "$timing|$ipadd|$losspag|$COUNT|down|$FLAG" >> $LogFileName
  else
    STR=`echo -n "$timing|$ipadd|$losspag|$COUNT|up|$FLAG" | base64`
    echo "$timing|$ipadd|$losspag|$COUNT|up|$FLAG" >> $LogFileName
  fi

 /usr/bin/curl  http://api.zzfwb.com/monitor/send_ping.php?str=$STR >> $LogFileName

 echo '' >>  $LogFileName
 echo '' >>  $LogFileName

done

cd /var/ping
find /var/ping -name "*.log" -ctime +1 -exec rm -f {} \;

Linux检查网络并自动重启网卡

标签: Shell Linux ping

添加crontab定时任务,可以用作心跳检测.


[root@mail src]# cat check_network.sh 
#!/bin/bash
date="`date '+%Y-%m-%d %H:%M:%S'`"
ip="116.205.11.145"
nic="eth0"
lost_rate=`ping -c 8 -w 8 $ip | grep 'packet loss' \
                | awk -F'packet loss' '{ print $1 }' \
                | awk '{ print $NF }' | sed 's/%//g'`

if [ $lost_rate -eq 0 ]
then
echo "network_ok $date $ip $nic lose $lost_rate" >>/var/log/network_ok.log
elif [ $lost_rate -le 100 ]
then
echo "network_error $date $ip $nic lose $lost_rate" >>/var/log/network_error.log 
/sbin/service network restart
else
echo "network_error $date $ip $nic lose $lost_rate" >>/var/log/network_error.log
/sbin/service network restart
fi


1 2 3 ... Next »