IPIP是在两台主机之间的IP层上建立一条虚拟的通道(没有加密,没有压缩),相当于建立一条VPN.
下面是一个例子:
我们想在两台机器之间建立ipip,它们分别为:Router A 和 Router B. 它们分别都连接到网络上.
Router A:
外网地址是: 192.0.2.34
内网地址是: 192.168.1.1
Router B:
外网地址是: 192.0.2.69
内网地址是: 192.168.1.254
在Router A上执行命令:
ip tunnel add tunnel0 mode ipip remote 192.0.2.69 local 192.0.2.34
ip link set tunnel0 up
ip addr add 192.168.1.1/24 dev tunnel0
在Router B执行命令:
ip tunnel add tunnel0 mode ipip remote 192.0.2.34 local 192.0.2.69
ip link set tunnel0 up
ip addr add 192.168.1.254/24 dev tunnel0Skip to 'testing the tunnel'.
Debian sample setup
Router A
Edit /etc/network/interfaces:
auto tunnel0
iface tunnel0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
pre-up /sbin/ip tunnel add tunnel0 mode ipip remote 192.0.2.69 local 192.0.2.34
post-down /sbin/ip tunnel del tunnel0Then execute
ifup tunnel0.
Router B
Edit /etc/network/interfaces:
auto tunnel0
iface tunnel0 inet static
address 192.168.1.254
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
pre-up /sbin/ip tunnel add tunnel0 mode ipip remote 192.0.2.34 local 192.0.2.69
post-down /sbin/ip tunnel del tunnel0Then execute
ifup tunnel0
Testing your tunnel
After you have configured your tunnel via one of the examples above you should be able to ping the remote end:
Router A
ping 192.168.1.254
Router B
ping 192.168.1.1
Both pings should succeed without problems.
使用你建立的IP tunnel
You can now use your tunnel - just pretend it's a piece of Ethernet between the two computers.
Remember the MTU on the tunnel will be lower than normal because of the extra IP header.
You can setup routing and whatever you like over the tunnel.
If you lose your route to the tunnel endpoint, the tunnel will not work either.
--------------------------------------------------------------------------------
More complex situations
When tunneling between 2 routers, and 1 router has a private network on another interface, routing between the two can be confusing. Here is the network layout:
Router 1
eth0: 1.2.3.4 (public)Router 2
eth0: 4.3.2.1 (public)
eth1: 10.0.0.1In my particular case, Router 1 is an asterisk system on a public network, and Router 2 is a NAT router that is also a gateway for my private 10.0.0.0/24 network. I have multiple SIP phones (which don't work through NAT) on the 10.0.0.0/24 network and I need to establish routes between the 2.
IN THIS ORDER ENTER THESE COMMANDS
Router 1
iptunnel add iptun mode ipip remote 4.3.2.1
ifconfig iptun 10.0.1.1
route add -net 10.0.2.0/24 dev iptunRouter 2
iptunnel add iptun mode ipip remote 1.2.3.4
ifconfig iptun 10.0.2.1
route add -net 10.0.1.0/24 dev iptunRouter 1
route add -net 10.0.0.0/24 dev iptun
route add -net 10.0.0.0/24 gw 10.0.0.1Now from Router 2 you can ping any device on the 10.0.0.0/24 network behind Router 1, and from any device on the 10.0.0.0/24 network, you can ping Router 1 using the address 10.0.1.1
This article is focusing installing and configure MRTG with CPU,Memory and Disk Usage Graphs examples for Debian Ubuntu and Kubuntu Users and may be work for some debian based distributions.
MRTG is Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network links. MRTG generates HTML pages containing PNG images which provide a LIVE visual representation of this traffic.
MRTG Requirements
Apache webserver with perl support
NET-SNMP
GD
Libpng
zlib
If you want to download MRTG you can download from here
Preparing you System for MRTG Instalaltion
First you need to install the required compilers
#apt-get install gcc make g++
Apache 2 Installation with perl support
Follow these instructions to install apache2 with perl support
MRTG Installation
Now we need to install mrtg and snmp
Installing MRTG in Debian, Ubuntu and Kubuntu
#apt-get install mrtg snmpd
The installation will create an mrtg subdirectory where the Apache Web pages reside. On your Debian,ubnutu,kubuntu systems the path of this subdirectory is:
/var/www/mrtg
Now you need to edit the mrtg configuration file to edit the some of the settings
File is located at /etc/mrtg.cfg you need to change the global settings as follows
# Global Settings
RunAsDaemon: yes
EnableIPv6: no
WorkDir: /var/www/mrtg
Options[_]: bits,growright
WriteExpires: Yes
Title[^]: Traffic Analysis for
You will find a crontab running every 5 minutes as user root
# cat /etc/cron.d/mrtg
0-55/5 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then env LANG=C /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log 2>&1; fi
Now we need to assign the snmp community name in snmp configration file /etc/snmp/snmpd.conf
# sec.name source community
# com2sec paranoid default public
com2sec readonly default public
#com2sec readwrite default private
Now you need to restart the snmp service
#/etc/init.d/snmpd restart
The configuration file creating using
#cfgmaker public@localhost > /etc/mrtg.cfg
Creating a configuration file for a device using cfgmaker
#cfgmaker public@192.168.0.1 >> /etc/mrtg.cfg
With the configuration file created correctly there’s only one other thing you have to do and that’s to use the indexmaker utility to create the summary home page. Since you have to re-run this command every time you make certain changes to the /etc/mrtg.cfg configuration file.
Creating index file for the webserver using indexmaker
#indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html
Now you need to reboot your system wait for five minutes or so and then take a look at your summary home page. If your Debian,ubuntu,kubuntu system’s IP address is 192.168.0.1 then you’d type in the following in the address bar of a browser running on a system on the same network:
http://192.168.0.1/mrtg/
Your summary home page should come up with a graph for each target entry in the configuration file. If a graph looks like there’s no data on it, click on it and check the statistics to see if any traffic is being seen. Small amounts of traffic won’t show up on the graphs because we used the Unscaled statement
Some of examples how to monitor cpu , memory , Disk usage
CPU Usage
/etc/mrtg/cpu.cfg
WorkDir: /var/www/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@127.0.0.1+ ssCpuRawSystem.0&ssCpuRawSystem.0:public@127.0.0.1+
ssCpuRawNice.0&ssCpuRawNice.0:public@127.0.0.1
RouterUptime[localhost.cpu]: public@127.0.0.1
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: Active CPU Load %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]: Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent
Memory Usage
/etc/mrtg/mem.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost
PageTop[localhost.mem]:Free Memory
WorkDir: /var/www/mrtg
Options[localhost.mem]: nopercent,growright,gauge,noinfo
Title[localhost.mem]: Free Memory
MaxBytes[localhost.mem]: 1000000
kMG[localhost.mem]: k,M,G,T,P,X
YLegend[localhost.mem]: bytes
ShortLegend[localhost.mem]: bytes
LegendI[localhost.mem]: Free Memory:
LegendO[localhost.mem]:
Legend1[localhost.mem]: Free memory, not including swap, in bytes
Memory Monitoring (Total Versus Available Memory)
/etc/mrtg/memfree.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.memory]: memAvailReal.0&memTotalReal.0:public@localhost
Title[server.memory]: Free Memory
PageTop[server.memory]: < H1 >Free Memory< /H1 >
MaxBytes[server.memory]: 100000000000
ShortLegend[server.memory]: B
YLegend[server.memory]: Bytes
LegendI[server.memory]: Free
LegendO[server.memory]: Total
Legend1[server.memory]: Free memory, not including swap, in bytes
Legend2[server.memory]: Total memory
Options[server.memory]: gauge,growright,nopercent
kMG[server.memory]: k,M,G,T,P,X
Memory Monitoring (Percentage usage)
/etc/mrtg/mempercent.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Title[server.mempercent]: Percentage Free Memory
PageTop[server.mempercent]: < H1 >Percentage Free Memory< /H1 >
Target[server.mempercent]: ( memAvailReal.0&memAvailReal.0:publicy@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:public@localhost )
options[server.mempercent]: growright,gauge,transparent,nopercent
Unscaled[server.mempercent]: ymwd
MaxBytes[server.mempercent]: 100
YLegend[server.mempercent]: Memory %
ShortLegend[server.mempercent]: Percent
LegendI[server.mempercent]: Free
LegendO[server.mempercent]: Free
Legend1[server.mempercent]: Percentage Free Memory
Legend2[server.mempercent]: Percentage Free Memory
Disk Usage
/etc/mrtg/disk.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[server.disk]: dskPercent.1&dskPercent.2:public@localhost
Title[server.disk]: Disk Partition Usage
PageTop[server.disk]: < H1 >Disk Partition Usage /home and /var< /H1 >
MaxBytes[server.disk]: 100
ShortLegend[server.disk]: %
YLegend[server.disk]: Utilization
LegendI[server.disk]: /home
LegendO[server.disk]: /var
Options[server.disk]: gauge,growright,nopercent
Unscaled[server.disk]: ymwd
Creating jobs for CPU , Memory and Disk Usage
CPU
/etc/cron.mrtg/cpu
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/cpu.cfg
Memory
/etc/cron.mrtg/mem
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mem.cfg
Memory Free
/etc/cron.mrtg/memfree
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/memfree.cfg
Memory Percentage
/etc/cron.mrtg/mempercent
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mempercent.cfg
Disk
/etc/cron.mrtg/disk
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/disk.cfg
Run each script 3 times (disregard the warnings)
/etc/cron.mrtg/cpu
/etc/cron.mrtg/mem
/etc/cron.mrtg/memfree
/etc/cron.mrtg/mempercent
/etc/cron.mrtg/disk
Make the Index Files
#/usr/bin/indexmaker --output=/var/www/mrtg/index.html \
--title=”Memory and CPU Usage ” \
--sort=name \
--enumerate \
/etc/mrtg/cpu.cfg \
/etc/mrtg/mem.cfg \
/etc/cron.mrtg/memfree \
/etc/cron.mrtg/mempercent \
/etc/cron.mrtg/disk
Make the mrtg.cfg file
#cfgmaker --global “WorkDir: /var/www/mrtg/” \
--global “Options[_]: growright,bits” \
--ifref=ip \
public@localhost > /etc/mrtg/mrtg.conf
Cronjob setup
/bin/cat >> /var/spool/cron/crontabs/root
*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null
Now you logon to your web browser http://192.168.0.1/mrtg/ and Now you should see CPU,Memory and Disk Usage graphs.
If you want more documentation about MRTG check here
服务器系统CentOS 5, 网内还有其它设备对外提供服务。
# uname -rvp
2.6.18-238.12.1.el5 #1 SMP Tue May 31 13:22:04 EDT 2011 x86_64
# ethtool -i eth0
driver: bnx2
version: 2.0.8-rh
firmware-version: bc 4.4.1 UMP 1.1.9
bus-info: 0000:03:00.0
---------------
服务器性能足够,通过80端口提供服务,不限量的话流量能跑满eth0,现在我想限速到最高450mbit,以免影响到其它设备的服务,但是限速貌似不是很灵,还是跑到600左右(之后使用iptables 把新连接给REJECT喽)请达人帮忙看看脚本有什么问题没? #!/bin/bash
tc qdisc del dev eth0 root 2>/dev/null
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1: classid 1:1 htb rate 450mbit ceil 450mbit
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 400mbit ceil 400mbit
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 30mbit ceil 50mbit
tc class add dev eth0 parent 1:1 classid 1:30 htb rate 20mbit ceil 50mbit
tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip sport 80 0xffff flowid 1:10
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip sport 22 0xffff flowid 1:30
问题的解决方案:见8楼。
tc -s class ls dev eth0
class htb 1:1 root rate 450000Kbit ceil 450000Kbit burst 57825b cburst 57825b
Sent 410270340209 bytes 188442731 pkt (dropped 0, overlimits 0 requeues 0)
rate 619391Kbit 35404pps backlog 0b 0p requeues 0
lended: 109 borrowed: 0 giants: 151676252
tokens: 835 ctokens: 835
ethtool -K tso off
关闭tso后,貌似正常了吖
see here -> https://bugzilla.redhat.com/show_bug.cgi?id=481546#c32
rpm -ivh http://people.redhat.com/jwilson/el5/269.el5/x86_64/kernel-2.6.18-269.el5.x86_64.rpm http://people.redhat.com/jwilson/el5/269.el5/x86_64/kernel-devel-2.6.18-269.el5.x86_64.rpm && reboot
跑了一下午,目前看起来蛮正常的
转
安装虚拟机的时候,没太注意时区,装好后发现时区比中国上海的慢了16个小时,寻得一些方法,分享给大家:
时区的配置文件是/etc/sysconfig/clock。用tzselect命令就可以修改这个配置文件,根据命令的提示进行修改就好了。
但是在实际工作中,发现这种方式是不能够使得服务器上的时间设置马上生效的,而且使用ntpdate去同步时间服务器也不能够更改时间。即使你使用了 date命令手工设置了时间的话,如果使用ntpdate去进行时间同步的话,时间又会被改动到原来的错误时区的时间。而生产的机器往往是非常重要的,不能够进行重启等操作。
如果要修改时区并且马上生效,可以更换/etc/localtime 文件来实现。比如修改时区为中国上海,那么就可以使用如下的命令来使得时区的更改生效。
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
然后最好使用下面的命令将更改写入bios。
hwclock
--------------------------------
具体操作:
[root@localhost ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite `/etc/localtime'? y
[root@localhost ~]# date
Sat Feb 20 16:04:43 CST 2010
[root@localhost ~]# hwclock
Sat 20 Feb 2010 04:05:12 PM CST -0.474966 seconds