linux路由配置

 场景描述:服务器一般有两块网卡,一个连接外网,一个连接内网。在linux系统下,通常会用eth0, eth1来标识。在redhat系列下,IP配置文件一般在 /etc/sysconfig/network-scripts/ifcfg-eth0和 /etc/sysconfig/network-scripts/ifcfg-eth1 里面。格式类似于下面: # Intel Corporation 82576 Gigabit Network Connection DEVICE=eth1 BOOTPROTO=none HWADDR=00:26:55:23:23:E7 ONBOOT=yes TYPE=Ethernet NETMASK=255.255.255.224 IPADDR=132.77.127.75 GATEWAY=132.77.127.65 USERCTL=no IPV6INIT=no PEERDNS=yes 现在我们问题来了,由于两块网卡eth0和eth1都配置了网关,当后一个网卡激活后,默认网关就会变成后一个网卡的网关,这样会导致内网、外网数据都走这个网关,从而引起网络出现问题。为了解决内网、外网都可以访问,我们需要通过路由来对数据分流。让外网的数据走外网网卡的网关,内网的走内网的网关。比如,内网网卡为eth1, 我们希望访问132.77.127.12时走网关132.77.127.65, 那么我们可以在 /etc/sysconfig/network-scripts/下创建文件 route-eth1, 格式: / via dev <eth#> 内容为: 132.77.127.12/32 via 132.77.127.65 dev eth1 其中32表示32位的子网掩码。 表示到 访问132.77.127.12 时走网关 132.77.127.65 然后在终端下执行: ifdown eth1 ifup eth1 这时在执行: route 就可以看到路由表信息里面两个网关都有了。内网、外网通讯会分别走内网网关和外网网关。

June 14, 2011 · 1 min · Space

linux递归删除文件夹

If you want remove directory named “.svn” under basedir recutively, you can use the command, find basedir -name .svn |xargs rm -rf 作者:豆博草堂

June 14, 2011 · 1 min · Space

mysql 数据热备份

http://www.fengfly.com/plus/view-28380-1.html http://www.koven.org/archives/203.html

June 14, 2011 · 1 min · Space

MySQL中文问题

 今天花了一个晚上终于解决了MySQL中中文插入显示问题,当然少不了Google的帮忙:)把解决方法写出来以供参考。 现象: 用JDBC将中文字段插入MySQL数据库中,然后打开表发现,那些字段都是"??".用java做出select方法进行select后也是"??". 原因: 1.创建数据库时没有指定默认的编码方式,导致数据库使用了MySql的默认字符集latin1。 2.Client端字符集为latin1. 3.进行jdbc链接时使用了不匹配的字符集。 解决办法: 1.创建数据库时将数据库的缺省字符集指定为utf8。sql: create database dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 2.修改Client默认字符集为utf8。windows下在mysql安装目录下找到my.ini(linux下,mysql的配置一般是/etc/my.conf,其中的datadir指明了数据存储目录。),将里面的default-character-set=latin1 改为default-character-set=UTF8,然后重起mysql服务即可将数据库默认字符集改为utf8.此时应该在mysql命令行用s命令检查一下看是否改好了。 3.修改jdbc的链接,将原来的 jdbc:mysql://localhost:3306/YourDb 改为 jdbc:mysql://localhost:3306/YourDb?useUnicode=true& characterEncoding=UTF-8 做完以上工作后,插入到mysql的中文应该不会再是乱码了. 作者:豆博草堂

June 14, 2011 · 1 min · Space

MySQL最大连接数设置

客户端登录:mysql -uusername -ppassword 设置新的最大连接数为200:mysql> set GLOBAL max_connections=200 显示当前运行的Query:mysql> show processlist 显示当前状态:mysql> show status 退出客户端:mysql> exit 查看当前最大连接数:mysqladmin -uusername -ppassword variables |find “max_con”

June 14, 2011 · 1 min · Space

mysql表结构修改命令

/主键 alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id); //增加一个新列 alter table t2 add d timestamp; alter table infos add ex tinyint not null default ‘0’; //删除列 alter table t2 drop column c; //重命名列 alter table t1 change a b integer; //改变列的类型 alter table t1 change b b bigint not null; alter table infos change list list tinyint not null default ‘0’; ...

June 14, 2011 · 1 min · Space

platform

Platform is a product engine, its owner would effect product trends. Microsoft’s windows and Linux/Unix are platforms based on personal computer, Google, Facebook and Live.com have been developing their own platform based on internet. If you have been used google search engine, google earth, google doc, gmail, reader, map etc, you may find there have many API supplied with these products, which can be used to develop your own products,for example, you can develop a guide system based on google earth. These products and API can be viewed as platforms. Platform is a great thing, which can be used to improve the power and efficiency of developer, also the manufacturer’s power in market. ...

June 14, 2011 · 1 min · Space

python解析xml

import xml.parsers.expat level = 0 def start_element(name, attrs): global level print ’ ’ * level, ‘Start element:’, name, attrs level = level + 1 def end_element(name): global level level = level - 1 print ’ ’ * level, ‘End element:’, name def char_data(data): if(data == ’n’): return if(data.isspace()): return global level print ’ ’ * level, ‘Character data:’, data if __name__ == “__main__”: p = xml.parsers.expat.ParserCreate() p.StartElementHandler = start_element p.EndElementHandler = end_element p.CharacterDataHandler = char_data p.returns_unicode = False ...

June 14, 2011 · 1 min · Space

Tomcat 6.x 和 Apache 2.2.11 集群负载均衡搭建

本文根据 http://www.cnblogs.com/shiyangxt/archive/2009/02/26/1398902.html 整理,如有不明,请参阅原文。 所需软件: Apache 2.2.11 Tomcat 6.x压缩版(.zip, .tar等压缩格式的版本)。 2. 配置步骤: 1) 安装Apache 2.2.11。tomcat 集群负载均衡需要apache服务器来配合实现,所以我们需要安装apache。另外,由于apache 2.2.11已经集成了jk2等负载工具,这将简化我们的配置。可以用安装版或解压版安装apache。 如果用windows下安装版安装,根据向导填写相应参数即可完成。 如果用压缩版,需要将apache解压到一个目录下面,然后打开$APACHE_HOME/conf/httd.conf, 根据实际配置下面参数: #apache安装根目录 ServerRoot “D:/devCenter/cluster_lab/Apache2.2 " #端口 Listen 80 # ServerAdmin 邮件 #http文档根目录 DocumentRoot “D:/devCenter/cluster_lab/Apache2.2/htdocs” # # This should be changed to whatever you set DocumentRoot to. # <Directory “D:/devCenter/cluster_lab/Apache2.2/htdocs”> # # Possible values for the Options directive are “None”, “All”, # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that “MultiViews” must be named *explicitly* — “Options All” # doesn’t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be “All”, “None”, or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all <IfModule alias_module> # directives as to Alias. ScriptAlias /cgi-bin/ “D:/devCenter/cluster_lab/Apache2.2/cgi-bin/” # # “D:/devCenter/cluster_lab/Apache2.2/cgi-bin” should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory “D:/devCenter/cluster_lab/Apache2.2/cgi-bin”> AllowOverride None Options None Order allow,deny Allow from all 2) 启动apache, 然后通过http://localhost/来测试,检查apache是否已经启动。 ...

June 14, 2011 · 2 min · Space

Windows下软件在Linux下的对应软件

我是个Linux初学者,由于在Windows上养成的习惯,在学习Linux时非常不习惯,特别是刚开始,在windows下使用的许多软件不知道在Linux用什么替代时,心里感觉非常不舒服,与其他人的网上交流也成了问题。现在,我把我知道的一些常用的在Linux下对应Windows的软件写出来,希望给大家些帮助. Windows Linux 备注 Office OpenOffice openoffice默认都会安装到Linux,而且还可以打开微软office的文档格式。 腾讯QQ LumaQQ Java开发的,具有QQ的基本功,但在登录后下载好友属性时常死掉,不知为什么。 Notepad KWriter, VI等 Linux安装后就有几个文本编辑器。功能都比 较强大。 播放器 MPlayer+ MPlayer-GUI 这个功能比较强大,但需要装解码器, 可装all-20060611.tar.bz2解码器下载下来解压后可以 放在/usr/lib/win32 下面,这样就可以播放windows下大多数格式了. Matlab SCILab 语法和功能与Matlab相似的开源数学软件,很好用。 RealPlayer RealPlayer 装完后也需要装插件,否则会不好用。可以google下看怎么装插件。:) PDF阅读器 XPDF Linux下默认安装的. CHM阅读器 GnoCHM 很不错的工具,这样在Linux下阅读CHM也就没问题了。 Photoshop GIMP 没用过,听说不错。 输入法 SCIM 很好的输入法,但是,如果你的系统默认语言是非中文的话,想输入中文就有点麻烦了,需要配置,我自己还没有配出来,也不知为什么. 另外还有编程类软件就更不用说了,Linux天生就是酷爱技术的人员搞出来的,做开发的工具当然应有尽有了:).要补充的是, 现在很多Linux发行版都有yum命令,需要装什么软件的话可以在终端下用 yum install <要装的软件的名字>来安装, 能不能找到你的软件很大程度上取决于你的软件仓库配置(可以上网找仓库的rpm包,用rpm来添加。)。另外,也 可以下载软件的rpm包来安装,可以在网上找到很多。在安装rpm过程中如果发现lib依赖问题,也可以用 yum install 总的说来,windows下有的软件Linux下也有,但Linux下有的,windows未必有,因为Linux走的是开放 路线,特别是在技术领域,Linux和Unix可以说真的值得投资. 学Linux开始很难,主要是不习惯,等过了一个坎就好了,学Linux没错的!:0) 作者:豆博草堂

June 14, 2011 · 1 min · Space