Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1118240
  • 博文数量: 113
  • 博客积分: 2422
  • 博客等级: 大尉
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-25 17:54
文章分类
文章存档

2016年(1)

2014年(8)

2013年(7)

2012年(13)

2011年(42)

2010年(26)

2009年(6)

2008年(6)

2007年(4)

我的朋友

分类: LINUX

2011-01-14 10:09:29

linux配置虚拟IP地址方法

在日常linux管理工作中,需要为应用配置单独的IP地址,以达到主机与应用的分离,在应用切换与迁移过程中可以做到动态切换,特别是在使用HA的时候,这种方案可以保证主机与应用的隔离,对日常的运维有很大的益处.

但在有些应用中还没有配置HA,后期需要配置HA,我们可以先配置虚拟IP给在线的应用使用,这要后期的系统运维可以做到更好的可扩展性.

本文主要是对IP地址如何配置做一些简单的介绍,只当是记录备忘.呵呵.

 

PS:以下实例在redhat linux实施成功!

 

1.         在线配置虚拟IP

 

ifconfig eth0:1 192.168.109.108 netmask 255.255.255.0

 

2.         查看新增加的子接口配置信息是否正确.主要是看IP与子网掩码.

ifconfig eth0:1

# ifconfig eth0:1

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:45:62:3B 

          inet addr:192.168.109.108  Bcast:192.168.109.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Base address:0x2000 Memory:d8920000-d8940000

 

3.         启动网卡eth0的子接口

ifconfig eht0:1 up

 

查看IP是否可以联通

ping -c 3 192.168.109.108

# ping -c 3 192.168.109.108

PING 192.168.109.108 (192.168.109.108) 56(84) bytes of data.

64 bytes from 192.168.109.108: icmp_seq=1 ttl=64 time=0.032 ms

64 bytes from 192.168.109.108: icmp_seq=2 ttl=64 time=0.053 ms

64 bytes from 192.168.109.108: icmp_seq=3 ttl=64 time=0.036 ms

 

--- 192.168.109.108 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2000ms

rtt min/avg/max/mdev = 0.032/0.040/0.053/0.010 ms

 

4.         修改配置文件,使配置在主机重启后自动生效.

 

cd /etc/sysconfig/network-script/

cp ifcfg-eth0 ifcfg-eth0:1

vi ifcfg-eth0:1

 

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

DEVICE=eth0:1   ---->子接口名

HWADDR=00:0C:29:45:62:3B

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.109.108

NETMASK=255.255.255.0

 

5.         对于要切换主机IP与应用IP的情可以做如下处理

下面的例子:主机IP192.168.109.105 应用IP192.168.109.108

我们要将IP做对调,

192.168.109.108给主机使用

192.168.109.105给应用使用

 

做法如下:

配置前的信息:

#ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0C:29:45:62:3B 

          inet addr:192.168.109.105  Bcast:192.168.109.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe45:623b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:20340 errors:0 dropped:0 overruns:0 frame:0

          TX packets:16678 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:1800154 (1.7 MiB)  TX bytes:2438822 (2.3 MiB)

          Base address:0x2000 Memory:d8920000-d8940000

# ifconfig eth0:1

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:45:62:3B 

          inet addr:192.168.109.108  Bcast:192.168.109.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Base address:0x2000 Memory:d8920000-d8940000

修改eth0:1的网卡配置信息:

# vi ifcfg-eth0:1

 

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

DEVICE=eth0:1   ---->子接口名

HWADDR=00:0C:29:45:62:3B

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.109.105

NETMASK=255.255.255.0

 

修改eth0的网卡配置信息:

#vi ifcfg-eth0

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

DEVICE=eth0

HWADDR=00:0C:29:45:62:3B

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.109.108

NETMASK=255.255.255.0

 

重启网络生效:这一步很重要!!!

 

nohup    service network restart  &

 

将命令提交给后台去执行,这样子可以保证系统正常重启网络

 

PS:对于生产系统最好在console上操作,不然有异常就杯具了。。。

 

阅读(25227) | 评论(1) | 转发(1) |
0

上一篇:lvm使用详解

下一篇:apache操作员重启脚本

给主人留下些什么吧!~~

chinaunix网友2011-03-07 08:45:08

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com