Wednesday, March 18, 2009
RedHat enterprise linux 4 cvs 配置
Tuesday, September 18, 2007
Uploading Large Files With PHP
Let me first start by saying that I’m currently working at a startup, and for anyone who’s ever done this, you know it sucks up a LOT of your time… in my case pretty much all of it. I’m not complaining by any means, I’m doing some of the coolest work I’ve ever done in fact! However, I just wanted to explain my little posting hiatus…
Anyway, on to the matter at hand. I have found myself in a position where I am writing scripts that may need to upload fairly large files. My scripts were timing out, and I couldn’t seem to figure out why. For the unitiated, there are some standard things that you usually do to both your php.ini and in your script in this situation:
- Set your max_upload_size in php.ini higher (it’s only 2M out of the box)
- Set your script timeout to never (set_time_limit(0); in your scripts… don’t do this in your php.ini)
However, it turns out there are some other php.ini config variables that you may need to look at:
- memory_limit - This may also be an obvious one to some people, but for those of you who don’t know, this restricts how much memory PHP is allowed to consume while processing. When working with images and large files, this needs to be upped to accommodate these needs.
- post_max_size - This was the one killing me, and it was a major “Duh” moment as well. If you aren’t allowed to create a large post, how can you expect to upload a large file?? This should be set the same as your max_upload_size.
- max_input_time - the time that the script should spend in accepting input. This is setting defaults to 60 seconds, and you will probably need to update this as well
That’s about it! Quick and simple solution to a problem that is probably pretty common. I promise my next post won’t disappoint (and should happen soonish)… I’ll be talking about how to set up a MySQL replication environment on one server!
Monday, March 05, 2007
2.6.9-42.EL不編譯kernel給iptables添加模塊(IPP2P、L7-filter)
會導致Kernel Crashes的,故請在加載L7-filter前,轉用SMP以外的Kernel.
以下是L7-filter官方網站上的一句話:
“Some users have reported kernel crashes when they using SMP with l7-filter. (Some have also reported that their SMP systems run fine.) If you have a multi-CPU machine, test carefully before putting it into production with l7-filter.”
安裝環境:Redhat ES 4 Update4
kernel 2.6.9.42.EL
需要準備以下包:
l7-protocols-****.tar.gz (可以在 http://l7-filter.sourceforge.net/下載,用於定義L7可用的
Protocols);
netfilter-layer7-VERSION.tar.gz (可以在http://l7-filter.sourceforge.net/下載,L7的可編譯
代碼)
patch-o-matic-ng-20060706.tar.bz2 (可以在http://www.netfilter.org/下載,最後一個版本
的ipp2p模塊的tar包)
iptables-VERSION.tar.bz2 (可以在http://www.netfilter.org/下載,最新版本的iptables)
kernel-2.6.9-42.EL.src.rpm (可以在Redhat source code dick中尋找)
(注:因為Redhat es4不在包括source code,故/usr/src/下沒有所需的kernel source)
獲得kernel source:
kernel-2.6.9-42.EL.src.rpm放在/home/下;
# rpm -ivh kernel-2.6.9-42.EL.src.rpm
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target=i686 kernel-2.6.9.spec
# cp -a /usr/src/redhat/BUILD/kernel-2.6.9/linux-2.6.9 /usr/src/linux/
初始化Kernel:
# cd /usr/src/linux/
# vi Makefile
(將改EXTRAVERSION = -42.EL)
# make mrproper
# make clean
# make menuconfig
(什麽也不做,直接save跳出來)
為了生成.config文件
IPTABLES:
將iptables下載到/home
# tar -xvjf /home/iptables-VERSION.tar.bz2 /usr/src/
# mv iptables-VERSION iptables
添加ipp2p模塊到Kernel
下載ipp2p到/home下
# tar -xvjf /home/patch-o-matic-ng-20060706.tar.bz2 /usr/src/
# cd patch-o-matic-ng-20060706/
# ./runme ipp2p
當出現KERNEL_DIR=/usr/src/linux 和 IPTABLES_DIR=/usr/src/iptables直接回車就可以了,
添加L7-filter:
下載 netfilter-layer7-VERSION.tar.gz 到/home下
# tar -xvzf /home/netfilter-layer7-VERSION.tar.gz /usr/src/
# mv netfilter-layer7-VERSION netfilter-layer7
# cd /usr/src/linux
# patch -p1 <../netfilter-layer7/for_older_kernels/2.6.9****.patch
# cd /usr/src/iptables
# patch -p1 < ../netfilter-layer7/iptables-layer7-***.patch
# cd /usr/src/iptables/extensions/
# chmod +x .layer7-test
添加Kernel的模塊:
# cd /usr/src/linux
# make menuconfig
Device Drivers->;Networking support->;Networking options->;Network packet filtering (replaces ipchains)->;IP: Netfilter Configuration將IPP2P和Layer7選上;
保存后跳出
安裝模塊:
# cd /usr/src/linux
# make modules
當編譯完HOSTLD scripts/modpost后用ctrl+c中止;
# make modules SUBDIRS=net/ipv4/netfilter
這裡生成了2.6kernel才會有的.o文件
# chmod +x /usr/src/linux/net/ipv4/netfilter/*.ko
# cp /usr/src/linux/net/ipv4/netfilter/*.ko /lib/modules/2.6.9-34.EL/kernel/net/ipv4/netfilter
# depmod -a
編譯iptables:
# vi /usr/src/linux/include/linux/config.h
註釋掉:
//#ifndef __KERNEL__
//#error including kernel header in userspace; use the glibc headers instead!
//#endif
# cd /usr/src/iptables
# make KERNEL_DIR=/usr/src/linux BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man
# make KERNEL_DIR=/usr/src/linux BINDIR=/sbin LIBDIR=/lib MANDIR=/usr/share/man install
將ipp2p、l7-filter加入:
l7-protocols-****.tar.gz下載到/home下
# tar -xvzf l7-protocols-****.tar.gz
# make install
# modprobe ipt_ipp2p
# modprobe ipt_layer7
# lsmode
Module Size Used by
ipt_limit 2816 3
ipt_ipp2p 6912 2
ipt_layer7 10412 4
ipt_LOG 6144 12
ipt_state 2176 12
iptable_nat 21948 1
測試iptables:
# iptables -A FORWARD -p ALL -m layer7 --l7proto bittorrent -j LOG --log-level DEBUG --log-prefix "bittorrent Outgoing Log:"
# iptables -A FORWARD -p ALL -m ipp2p --edk --kazaa --gnu --bit --apple --dc --soul --winmx --ares -j LOG --log-level DEBUG --log-prefix "IPP2P Outgoing Log:"
# iptables -vnL
Wednesday, March 22, 2006
pptpd+radius+mysql (support windows98)
配置如下:
需要以下幾個軟件包:
(運行 #modprobe ppp-compress-18 && echo ok,如果顯示OK,那就不會用到以下兩個RPM包了)
dkms-2.0.6-1.noarch.rpm
kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
(這兩個是compile kernel,讓2.4.*的kernel支持mppe的加密).
pptpd-1.3.0.tar.gz (在pppd撥號的基礎上增加PPTPD的支持)
ppp-2.4.3.tar.gz (ppp撥號服務器)
radius可作為ppp的驗證外掛模块
freeradius-1.1.0.tar.gz
軟件包可以在下邊的連接上拿到
http://www.freeradius.org
用rpm -qa |grep mysql 如果顯示有mysql-devel的話,就不需要安裝下邊的RPM包
mysql-devel-3.23.54a-11.i386.rpm
1. 升级内核支持mppe(運行 #modprobe ppp-compress-18 && echo ok,如果顯示OK,直接跳到下一步)
#rpm -ivh dkms-2.0.6-1.noarch.rpm
#rpm -ivh kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm
如果沒有error
#reboot
現在等機子啓動就可以進行下一步了.
2.安裝ppp
http://www.samba.org/ppp
這裡安裝的是 ppp-2.4.3.tar.gz
#tar -xvzf ppp-2.4.3.tar.gz
#cd ppp-2.4.3
#./configure
#make
#make install
3.安裝pptpd
http://poptop.sourceforge.net/
這裡安裝的是pptpd-1.3.0.tar.gz
#tar -xvzf pptpd-1.3.0.tar.gz
#cd pptpd-1.3.0
#./configure
#make
#make install
4.配置ppp和pptpd
#cp /pathofsource/pptpd-1.3.0/samples/pptpd.conf /etc/
#vi /etc/pptpd.conf
確認以下的配置是否存在:
ppp /usr/local/sbin/pppd (讓pptpd知道pppd所在的位置)
option /etc/ppp/options.pptpd (讓pptpd知道ppp的配置文件)
localip 172.16.2.74 (localip是pptpd服務器的外部ip,也就是用戶需要撥號的ip
remoteip 10.10.110.1-100 (服務器分配的ip範圍)
#vi /etc/ppp/option.pptpd
打開debug和dump功能,該功能可以在測試完成後去掉。
(注意:debug和dump功能會在/var/log/message里寫入關於用戶登入的過程)
這裡要注意一點:
要想支持windows98的用戶,
在配置option.pptpd時要把“require-mppe-128”或者“require-mppe”都去掉
因為windows98是不支持mppe加密壓縮的。
而且不用mppe加密,windows2000以上在建立pptpd vpn連接的時候,
不能使用“不加密斷開連接”這個選項.
5. 添加用戶和測試pptpd
#vi /etc/ppp/chap-secrets
加入一個用戶:
# Secrets for authentication using CHAP
# client server secret IP addresses
ouyangxin pptpd test *
第一個是用戶名, pptpd表示和/etc/ppp/options.pptpd中的name 部分pptpd要匹配,一般不用修改,第三個用戶密碼,*表示任意的ip
運行pptpd
#pptpd
或
#/usr/local/sbin/pptpd
使用windows98指向這個ip建立一個vpn連接。
好這裡完成pptpd的配置
radius部分:
安裝radius前先確認是否安裝了mysql-devel.i386
要是沒有可以安裝mysql-devel-3.23.54a-11.i386.rpm
#rpm -ivh mysql-devel-3.23.54a-11.i386.rpm
1.安裝freeradius
在http://www.freeradius.org
下載freeradius-1.1.0.tar.gz
#tar -xvzf freeradius-1.1.0.tar.gz
#cd freeradius-1.1.0
#./configure --prefix=/usr/local/freeradius-1.1.0
#make
#make install
2.配置ppp支持radius
从ppp的源代碼目錄下複製/etc/radiusclient/
#cp -R ppp-2.4.3/pppd/plugins/radius/etc /etc/radiusclient/
修改pptpd.option
加入 plugin /usr/lib/pppd/2.4.3/radius.so
配置 /etc/radiusclient中的servers和radiusclient.conf
#cd /etc/radiusclient
#vi servers
加入
localhost test
這裡localhost表示你的radiusd就是本機,並且訪問的密碼是 test
#vi radiusclient.conf
確認
authserver localhost:1812
acctserver localhost:1813
确认上面也是本地的,默认就是本地,所以一般不需要修改。
同时确保这个文件中radiusclient相关的路径所有的路径都是 /etc/radiusclient 开头的。
3.配置freeradius
cd /usr/local/freeradius-1.1.0/etc/raddb
raddb这个目录就是所有的freeradius配置文件所在了
3.1 修改clients.conf
这里说明一下,所有的nas都是radiusd的client,nas就是那个pptpd,所以这个文件就是配置pptpd的登陆权限的。
secret = test
shortname = test1234
nastype = other
}
3.2 在users文件的最上面加入一个用户
Service-Type = Framed-User,
Framed-Protocol = PPP,
Framed-IP-Address = 255.255.255.254,
Framed-IP-Netmask = 255.255.255.0
auth-type是验证的类型
第二个ww是密码
Simultaneous-Use是允许这个用户名同时登陆的个数
所有这些都是check属性,要写在第一行
然后第二行开始用tab开头,是服务器返回给radius客户端的(也就是返回给pptpd)时reply属性。
其中ip地址设置为255.255.255.254表示ip地址的分配是由radius客户端决定的,也就是由pptpd决定。
最后一个是子网掩码。
5.3用debug模式运行radiusd
Using deprecated naslist file. Support for this will go away soon.
Module: Loaded exec
rlm_exec: Wait=yes but no output defined. Did you mean output=none?
Module: Instantiated exec (exec)
Module: Loaded expr
Module: Instantiated expr (expr)
Module: Loaded PAP
Module: Instantiated pap (pap)
Module: Loaded CHAP
Module: Instantiated chap (chap)
Module: Loaded MS-CHAP
Module: Instantiated mschap (mschap)
Module: Loaded eap
rlm_eap: Loaded and initialized type md5
rlm_eap: Loaded and initialized type leap
rlm_eap: Loaded and initialized type gtc
rlm_eap: Loaded and initialized type mschapv2
Module: Instantiated eap (eap)
Module: Loaded preprocess
Module: Instantiated preprocess (preprocess)
Module: Loaded files
Module: Instantiated files (files)
Module: Loaded Acct-Unique-Session-Id
Module: Instantiated acct_unique (acct_unique)
Module: Loaded realm
Module: Instantiated realm (suffix)
Module: Loaded detail
Module: Instantiated detail (detail)
Module: Loaded radutmp
Module: Instantiated radutmp (radutmp)
Initializing the thread pool...
Listening on authentication *:1812
Listening on accounting *:1813
Ready to process requests.
建立一个新的vpn连接
用户名ww密码ww
然后拨号
成功的话,会看到。
Service-Type = Framed-User
Framed-Protocol = PPP
User-Name = "ww"
MS-CHAP-Challenge = 0x729e2492953298b498a766e778defe74
MS-CHAP2-Response = 0xfc00475dd294431a52ee1187d13127c3bf49
000000000000000043aad8bb5c
d6f5ece16ddae9d20c63d857836053b2197144
Calling-Station-Id = "192.168.8.53"
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
Sending Access-Accept of id 214 to 127.0.0.1 port 32768
Service-Type = Framed-User
Framed-Protocol = PPP
Framed-IP-Address = 255.255.255.254
Framed-IP-Netmask = 255.255.255.0
MS-CHAP2-Success = 0xfc533d3130363732303745303738424443
313833344130353643433743304437304
6363942414446343039
MS-MPPE-Recv-Key = 0x0211fcb6f599479e8ee0a7d8a16a3252
MS-MPPE-Send-Key = 0x91242cedc84a2dc69355c56951119065
MS-MPPE-Encryption-Policy = 0x00000002
MS-MPPE-Encryption-Types = 0x00000004
rad_recv: Accounting-Request packet from host 127.0.0.1:32768, id=215, length=108
Acct-Session-Id = "43EBFF39048300"
User-Name = "ww"
Acct-Status-Type = Start
Service-Type = Framed-User
Framed-Protocol = PPP
Calling-Station-Id = "192.168.8.53"
Acct-Authentic = RADIUS
NAS-Port-Type = Async
Framed-IP-Address = 10.10.110.1
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
Acct-Delay-Time = 0
Sending Accounting-Response of id 215 to 127.0.0.1 port 32768
用ctrl+c退出radius
配置mysql:
1.需要软件,什么都不需要。
你只要给各mysql的库就好了,库结构在
freeradius源码目录下的/src/modules/rlm_sql/drivers/rlm_sql_mysql/db_mysql.sql
你建立一个数据库就好了,我在我自己的机器上建立了一个名字为radius的数据库
并且导入了这个数据库的结构。
2。配置sql.conf
先回到刚才的freeradius的配置文件目录
修改连接信息
server = "172.16.2.74"
login = "radius"
password = "radius"
# Database table configuration
radius_db = "radius"
打开sql的用户同时连接数测试的语句
simul_count_query = "SELECT COUNT(*) FROM ${acct_table1} WHERE UserName='%{SQL-User-Name}' AND AcctStopTime = 0"
注释掉 authorize {
的files
去掉sql前的注释
注释掉 preacct {
的files
注释掉 accounting {
的radutmp
去掉sql前面的#
注释掉 session{
的radutmp
去掉sql前面的#
去掉 post-auth {
sql前的#
总之就是去掉files模块,开启sql模块
4。在数据库中添加用户
在usergroup中添加一个test用户,组名为vpn
在radgroupcheck中添加一个vpn组,
attribute为Simultaneous-Use
op为:=
value为1
的纪录
在radcheck中添加
username为test
attribute为 User-Password
op为==
value为test
这样就添加了一个用户为test,组为vpn,密码为test
并且所有的组用户的都只能1个用户名登陆一次
5.测试
用debug模式启动radiusd
会看到
Starting - reading configuration files ...
Using deprecated naslist file. Support for this will go away soon.
Module: Loaded exec
rlm_exec: Wait=yes but no output defined. Did you mean output=none?
Module: Instantiated exec (exec)
Module: Loaded expr
Module: Instantiated expr (expr)
Module: Loaded PAP
Module: Instantiated pap (pap)
Module: Loaded CHAP
Module: Instantiated chap (chap)
Module: Loaded MS-CHAP
Module: Instantiated mschap (mschap)
Module: Loaded eap
rlm_eap: Loaded and initialized type md5
rlm_eap: Loaded and initialized type leap
rlm_eap: Loaded and initialized type gtc
rlm_eap: Loaded and initialized type mschapv2
Module: Instantiated eap (eap)
Module: Loaded preprocess
Module: Instantiated preprocess (preprocess)
Module: Loaded SQL
rlm_sql (sql): Driver rlm_sql_mysql (module rlm_sql_mysql) loaded and linked
rlm_sql (sql): Attempting to connect to radius@192.168.8.53:/radius
rlm_sql (sql): starting 0
rlm_sql (sql): Attempting to connect rlm_sql_mysql #0
rlm_sql_mysql: Starting connect to MySQL server for #0
rlm_sql (sql): Connected new DB handle, #0
rlm_sql (sql): starting 1
rlm_sql (sql): Attempting to connect rlm_sql_mysql #1
rlm_sql_mysql: Starting connect to MySQL server for #1
rlm_sql (sql): Connected new DB handle, #1
rlm_sql (sql): starting 2
rlm_sql (sql): Attempting to connect rlm_sql_mysql #2
rlm_sql_mysql: Starting connect to MySQL server for #2
rlm_sql (sql): Connected new DB handle, #2
rlm_sql (sql): starting 3
rlm_sql (sql): Attempting to connect rlm_sql_mysql #3
rlm_sql_mysql: Starting connect to MySQL server for #3
rlm_sql (sql): Connected new DB handle, #3
rlm_sql (sql): starting 4
rlm_sql (sql): Attempting to connect rlm_sql_mysql #4
rlm_sql_mysql: Starting connect to MySQL server for #4
rlm_sql (sql): Connected new DB handle, #4
Module: Instantiated sql (sql)
Module: Loaded Acct-Unique-Session-Id
Module: Instantiated acct_unique (acct_unique)
Module: Loaded realm
Module: Instantiated realm (suffix)
Module: Loaded detail
Module: Instantiated detail (detail)
Initializing the thread pool...
Listening on authentication *:1812
Listening on accounting *:1813
Ready to process requests.
会看到
Service-Type = Framed-User
Framed-Protocol = PPP
User-Name = "test"
MS-CHAP-Challenge = 0xb6a9e94b94c3c386875043efd5144e17
MS-CHAP2-Response = 0x38006d78036bb5e40ddeca0ce96b944619e
000000000000000007b887b8762be38eb
111a94a4b581925b85e07453a38a070f
Calling-Station-Id = "192.168.8.53"
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
rlm_sql (sql): Reserving sql socket id: 4
rlm_sql (sql): Released sql socket id: 4
rlm_sql (sql): Reserving sql socket id: 3
rlm_sql (sql): Released sql socket id: 3
rlm_sql (sql): Processing sql_postauth
rlm_sql (sql): Reserving sql socket id: 2
rlm_sql (sql): Released sql socket id: 2
Sending Access-Accept of id 222 to 127.0.0.1 port 32768
MS-CHAP2-Success = 0x38533d33453434464142394
232444230413143464539453832444536453
534373331383833454238414536
MS-MPPE-Recv-Key = 0x53a3812a0fd5b6f7b1cf4f6f6796f26b
MS-MPPE-Send-Key = 0xb8be60559cbc46fd4da277516d6584f3
MS-MPPE-Encryption-Policy = 0x00000002
MS-MPPE-Encryption-Types = 0x00000004
rad_recv: Accounting-Request packet from host 127.0.0.1:32768, id=223, length=110
Acct-Session-Id = "43EC0822056A00"
User-Name = "test"
Acct-Status-Type = Start
Service-Type = Framed-User
Framed-Protocol = PPP
Calling-Station-Id = "192.168.8.53"
Acct-Authentic = RADIUS
NAS-Port-Type = Async
Framed-IP-Address = 10.10.110.1
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
Acct-Delay-Time = 0
rlm_sql (sql): Reserving sql socket id: 1
rlm_sql (sql): Released sql socket id: 1
Sending Accounting-Response of id 223 to 127.0.0.1 port 32768
会看到
Service-Type = Framed-User
Framed-Protocol = PPP
User-Name = "test"
MS-CHAP-Challenge = 0x2295d4d65913cbc0a7836e986fe4a998
MS-CHAP2-Response = 0x34001739a3331c1a1a938eed99cda89b691f
0000000000000000a8a9e9ae2eadaa6b1acb93e3
68113dc4ed47dac0a20b1ed8
Calling-Station-Id = "192.168.8.53"
NAS-IP-Address = 127.0.0.1
NAS-Port = 0
rlm_sql (sql): Reserving sql socket id: 4
rlm_sql (sql): Released sql socket id: 4
rlm_sql (sql): Reserving sql socket id: 3
rlm_sql (sql): Released sql socket id: 3
rad_recv: Access-Request packet from host 127.0.0.1:32768, id=225, length=146
Sending Access-Reject of id 225 to 127.0.0.1 port 32768
Reply-Message := "\r\nYou are already logged in - access denied\r\n\n"
Tuesday, March 14, 2006
red hat的历史和当前开放源代码的发展趋势
RedHat 1.0 (Mother's Day), 11, 3, 1994
RedHat 1.1 (Mother's Day+0.1), 8, 1, 1995
RedHat 2.0, 9, 20, 1995
RedHat 2.1, 11, 23, 1995
RedHat 3.0.3 (Picasso), 5,1, 1996
RedHat 4.0 (Colgate), 10, 8, 1996
RedHat 4.1 (Vanderbilt), 2, 3, 1997
RedHat 4.2 (Biltmore), 5, 19, 1997
RedHat 5.0 (Hurricane), 12, 1, 1997
RedHat 5.1 (Manhattan), 5, 22, 1998
RedHat 5.2 (Apollo), 11, 2, 1998
RedHat 6.0 (Hedwig), 4, 26, 1999
RedHat 6.1 (Cartman), 10, 4, 1999
RedHat 6.2 (Zoot), 4, 3, 2000
RedHat 7 (Guinness), 9, 25, 2000
RedHat 7.1 (Seawolf), 4, 16, 2001
RedHat 7.2 (Enigma), 10, 22, 2001
RedHat 7.3 (Valhalla), 5, 6, 2002
RedHat Enterprise Edition 2.1 AS (Pensacola), 5, 6 2002
RedHat 8.0 (Psyche), 9, 30, 2002
RedHat 9 (Shrike), 3, 31, 2003
从这一年的9,22日开始原来合并在一起的Fedora和redhat开始分开发行,并行成为两个分支一个是开源免费的Fedora,一个则是商业企业版本的Red Hat Enterprise Edition
RedHat Enterprise Edition 3.0 (Taroon), 10, 22 2003
Fedora Core 1 (Yarrow), 11,5 2003
Fedora Core 1.90 (FC2 Test 1), 2, 4, 2004
Fedora Core 2 (Tettnang), 5, 18, 2004
Fedora Core 3 (heidelberg) 11,8,2004
RedHat Enterprise Edition 4.0 2,15,2005
Fedora Core 4 (stentz) 6,13,2005
Fedora Core 5 目前是测试版还未正式发行
1998年1月,小红帽高级研发实验室成立,同年RedHat 5.0获得了InfoWorld的操作系统奖项。 1998年10月,Intel和Netscape宣布小额投资红帽软件,这被业界视作Linux获得商业认同的信号。 1999年,IBM宣布与Redhat公司建立伙伴关系,以确保Redhat在IBM机器上正确运行。三月,第一届LinuxWorld大会的召开,象征 Linux时代的来临。IBM、Compaq和Novell宣布投资Redhat公司,以前一直对Linux持否定态度的Oracle公司也宣布投资。
linux的发展史
以下参考《Linux简史》 原著:Ragib Hasan Department of Computer Science University of Illinois at Urbana-Champaign 翻译:王晓林
混沌初开
那是在一九九一年,令人痛苦难耐的冷战渐渐走到了尽头。 和平安详的空气开始升起在地平线。在计算科学领域, 随着强大硬件的推出,计算机的极限能力已超出了我们的想象, 一个辉煌的未来似乎已渐露端倪。
但还是缺了点儿什么。在操作系统领域,存在着一大片空白。
一方面,DOS还统治着庞大的个人电脑王国。 比尔盖茨花$50,000从一个西雅图黑客手中买来DOS。之后, 靠着聪明的市场策略,这个简陋的操作系统悄悄渗透到了世界的每一个角落。 PC用户没有其它的选择。苹果机虽好,但它的天价没人能承受得起。 它和大众需求保持着遥不可及的距离。
计算领域的另一个阵营是UNIX世界。但UNIX更是贵不可攀。为了追求高额利润, UNIX销售商把价码抬得足以吓跑随便哪个PC用户。 贝尔实验室曾慷慨地向高校提供UNIX的源代码。但现在, 这些源代码被小心地看管起来,不再对外公开。更令全球PC用户心烦的是, 软件市场的大玩家们没能为这一问题提供个有效的解决方案。
MINIX似乎是个选择。它是在荷兰当教授的美国人Andrew S. Tanenbaum 从零开始编写出来的。 MINIX的初衷是为了向学生讲授操作系统的内部工作原理。 MINIX的设计是面向当时最为流行的Intel 8086微处理器。
作为一个操作系统,MINIX算不上一流。但它的好处是你能得到它的源代码。 只要你有Tanenbaum写的《操作系统:设计与实现》这本书, 你就能得到那12,000行用C和汇编写的源码。头一次, 程序员或黑客可以有机会读一读操作系统的源码--- 这种被软件商严加看管的东西。 Tanenbaum用详尽简洁的笔触探讨了编写操作系统的艺术。 他是个一流的作者,迷住了一批当时计算机领域最聪明的大脑。 全世界学计算机的学生都在钻研这本书, 通过读它的源码来了解他们电脑里运行的MINIX操作系统。
Linus Torvalds就是这些学生中的一个。
呱呱坠地
在1991年,Linus Benedict Torvalds还是个芬兰学生,在赫尔辛基大学念计算机专业二年级。 同时他也是个自学成才的黑客。这个长着沙滩黄头发、 说话软绵绵的二十一岁芬兰帅哥喜欢折腾他的电脑,把它不断推向能力的极限。 但他缺少一个合适的操作系统来满足他如此专业的需求。MINIX不错, 可它只适合学生,是个教学工具,而不是一个强大的实战系统。 当时,全世界的程序虫们都很看好Richard Stallman的GNU项目 ---一个致力于推出自由、高质量软件的运动。在计算科学的王国里, Stallman是个倍受尊崇的神话式英雄。 他令人景仰的职业生涯是从大名鼎鼎的MIT人工智能实验室开始的。 七十年代中后期,在那里他开发出了著名的Emacs编辑器。 八十年代早期,商业软件公司从人工智能实验室吸引走了绝大多数优秀的程序员, 并和他们签署了严格的保密合同。Stallman为此大大不爽。他认为软件和其它产品不同, 在复制和修改方面,它不该受到任何限制。只有这样,才可能开发出更好更强的 软件。1983年,他在著名的《GNU宣言》中,向世人宣告了GNU项目的启动, 开始了贯彻其哲学的自由软件运动(注:GNU一词是‘GNU's Not Unix’的递归缩写)。 为了最终实现开发出一个自由操作系统的梦想,他得先制造些工具。 于是,在1984年初,Stallman开始创作一个令商业企业程序员叹服的作品--- GNU C编译器(gcc)。他出神入化的技术天才,令所有商业软件程序员自愧不如。 gcc被公认为世界上最高效最强健的编译器之一。
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://cisd-ftp.swfc.edu.cn/~wx672/course_materials/unix-linux/linux_history/figs/stallman.jpg');}" onmousewheel="return imgzoom(this);" border="0">Richard Stallman,GNU项目的创始人
到1991年,GNU项目已经开发出了众多的工具软件。 大家期待已久的GNU C编译器也问世了。但自由操作系统还没有出现。 MINIX也受制于版权(后来,在2000年4月, Tanenbaum在BSD许可证下发布了自由的MINIX)。 GNU操作系统内核---HURD---还在开发之中,几年之内还不可能面世。
拖了这么久,终于该说说Linus了。
1991年8月25号,Linus在MINIX新闻组发出了历史性的一贴...
From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Message-ID: <1991Aug25.205708.9541@klaava.Helsinki.FI>
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki
Hello,各位使用minix的朋友,
我正在写一个基于386(486)AT机器的(自由)操作系统 (只是出于爱好,不会做得象gnu那么大、那么专业)。 我从四月份开始酝酿,现在已经做得差不多了。 我现在想知道一些你们对minix的看法,它哪点好?哪点不好? 因为我这个操作系统和minix多少有点儿类似 (文件系统采用同样的物理布局[因现实原因],其它方面也有类似的地方)。 我已经把bash(1.08)和gcc(1.40)移植过来了,而且它们运转正常。 这意味着在下面几个月里,我将给它加上更多实际的功能。 所以我想知道大家都希望它有哪些功能。欢迎多提建议, 但我不敢保证能实现你的建议
Linus (torvalds@kruuna.helsinki.fi)
附:没错,它不包含任何minix的代码, 而且它有一个多线程文件系统。 它现在不能在其它硬件上转(因为用了386任务切换机制,等等), 而且除了AT硬盘,它基本上不支持任何其它硬件。 这就是全部了
从这个帖子不难看出, Linus自己并没预料到他的小创造将会改变整个计算科学领域。 1991年9月中旬,Linux 0.01版问世了,并且被放到了网上。 它立即引起了人们的注意。源代码被下载、测试、修改, 最终被反馈给Linus。10月5号, 0.02版出来了,同时伴随着Linus著名的声明:
From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: Free minix-like kernel sources for 386-AT
Message-ID: <1991Oct5.054106.4647@klaava.Helsinki.FI>
Date: 5 Oct 91 05:41:06 GMT
Organization: University of Helsinki
你在怀念minix-1.1时代的美好时光吗? 那时你自己写着驱动,充满了成就感。 现在没什么好项目可做了,是吗? 你在拚命啃一个操作系统,修改它以满足你自己的需要,是吗? 现在minix已经没什么需要你去改进的了,你为此怅然若失,是吗? 没机会再熬通宵去改进一个小程序了,是吗? 如果是这样的话,那这个帖子就是给你的
一个月(?)前我曾经提到过,我正在一个AT-386 机器上开发一个自由版本的、类似minix的操作系统。 现在它终于出来了(尽管未必能满足你的期待)。 我乐意把源代码公开出来,让它传播得更广。 它现在仅仅是0.02版(外加一个(很小的)补丁)。 但是我已经成功地在它上面跑了 bash/gcc/gnu-make/gnu-sed/compress等程序。 我这个小宝贝儿的源程序在nic.funet.fi(128.214.6.100) 下面的 /pub/OS/Linux 目录中可以找到。 该目录中还有些 README 文件, 还有几个在linux下能工作的可执行文件 (bash,update和gcc,你还要求些什么呢
几周以后,Linux 0.03版发布了。12月份,0.10版发布了。 这时的Linux还显得很简陋。它只能支持AT硬盘,而且不用登录(启动就进bash)。 0.11版有了不少改进,可以支持多国语言键盘、软驱、VGA、EGA、Hercules等等。 Linux的版本号从0.12直接上升到了0.95、0.96......不久, Linux的源代码就通过在芬兰和其它一些地方的FTP站点传遍了全世界。
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://cisd-ftp.swfc.edu.cn/~wx672/course_materials/unix-linux/linux_history/figs/linusnow2.jpg');}" onmousewheel="return imgzoom(this);" border="0">今天锋芒毕露的Linus
谁与争锋
不久,Linus开始面对挑战。他面对的不是别人,正是Andrew Tanenbaum, 那个开发出MINIX的伟大教师。在给Linus的一个回贴中,Tanenbaum写到:
“我还是坚持我的观点, 在1991年还设计这样一个整体架构的内核是个根本性的错误。 你该庆幸不是我的学生。这么个设计,在我这儿你得不了高分
(Andrew Tanenbaum to Linus Torvalds)
Linus后来承认说,这是关于开发Linux他所得到的最坏评价。 Tanenbaum是当时的知名教授,他说的话自然很有份量。 但这次面对Linux,他的话没能奏效,因为Linus不是个轻易服输的人。
Tanenbaum还宣称:
“Linux过时了。”
现在轮到新的Linux一代开始反击了。以强大的Linux社区为后盾, Linus给了Tanenbaum一个恰如其分的回复:
你的工作是教授、研究员。这对于minix的大脑损伤是个绝妙的解释。
(Linus Torvalds to Andrew Tanenbaum)
Linux的开发在继续。不久,加入开发的人数就超过了一百,然后是数千, 然后是数十万。Linux不再只是个黑客的玩具,配合上GNU项目开发出的众多软件, Linux已经可以走向市场了。它最终在GNU公共许可证下发布, 这保证任何人都可以自由获得它的源代码,可以自由复制、学习和修改它。 学生和程序员们都没错过这个机会。
不久,软件商们也来了。Linux是自由的操作系统。 软件商们需要做的只是把各种各样的软件在Linux平台上编译, 然后把它们组织成一种可以推向市场的形式。 这和其它操作系统在运作模式上没什么区别,只是Linux是自由的。 Redhat、Caldera、 和其它一些公司都获得了相当大的市场,获得了来自世界各地的用户。 除了这些商业公司,非商业的编程专家们也志愿地组织了起来, 推出了他们自己的品牌---享誉全球的Debian。 配上崭新的图形界面(比如X Window System、KDE、 GNOME), Linux的各个品牌都倍受欢迎。
好戏连台,惊喜不断。除了PC机,Linux又被移植到了许多其它平台上 (PowerPC、Sun Sparc、ARM、Alpha...Debian就支持十几种CPU)。 它还被人安装到了3com的手掌计算机上。另外,利用集群技术, 许多Linux单机可以被组织成一个整体,用于并行计算。1996年4月, Los Alamos国家实验室的研究人员利用 68台Linux单机搭建了一个并行计算系统,用它来模拟原子弹爆炸的冲击波。 与其它超级计算机不同的是,用Linux搭建的集群计算机非常便宜。 这种DIY出来的超级计算机只花费$152,000,连人工(连接68台PC的线缆) 都包括了。这价格只是同级别商业机的十分之一。 它的峰值计算速度可达每秒19万亿(billion)次。 在世界超级计算机排行榜中它排在第315位。 它运行稳定可靠。三个月后,还不必重启动
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://cisd-ftp.swfc.edu.cn/~wx672/course_materials/unix-linux/linux_history/figs/laptop.jpg');}" onmousewheel="return imgzoom(this);" border="0">Linus在展示一台Linux笔记本电脑
今天,Linux最大的优势就是推动它前进的巨大开发热情。一旦有新硬件问世, Linux内核就能快速被改进以适应它。比如, Intel Xeon微处理器才问世几个星期,Linux新内核就跟上来了。 它还被用在了Alpha、MAC、PowerPC上。 甚至在手掌机这一少人问津的领域都可以运行Linux。 正如它在1991年诞生时那样,Linux正以同样的热情阔步走向新世纪。
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://cisd-ftp.swfc.edu.cn/~wx672/course_materials/unix-linux/linux_history/figs/Linus_Torvalds.jpg');}" onmousewheel="return imgzoom(this);" border="0">Linus,2002
至于Linus本人,他保持着简单的生活。不象比尔盖茨,Linus不是亿万富翁。 完成学业之后,他移居美国,在Transmeta公司找了个工作。 Transmeta公司在指导完成了一个绝密项目的研发之后, 推出了自己的Crusoe处理器。Linus是这个研发小组中活跃的一员。 最近,他和Tove结了婚,生了个女儿,取名Patricia Miranda Torvalds。 世界范围内的计算机社区都对Linus推崇备至,到目前为止, 他是我们这个星球上最受欢迎的程序员。
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://cisd-ftp.swfc.edu.cn/~wx672/course_materials/unix-linux/linux_history/figs/family.jpg');}" onmousewheel="return imgzoom(this);" border="0">全家福
风雨十年
Linux的开发已经走过了十个年头。 它用十年的蓬勃发展否定了所有持怀疑态度的警告和预言。 今天,Linux是有史以来发展速度最快的操作系统之一。 从91、92年的几个技术狂热者发展到今天数以百万计的普通用户, 这绝对是个不平凡的历程。大商业公司们“发现”了Linux, 将数以百万计的美元倾入到开发中来,这一事实无情地驳斥了 “开源运动反商业”的谬论。IBM曾经视开源社区为洪水猛兽。 而现在,它已经将大量的资金转移到以Linux为平台的开源解决方案中来。
但真正让人感到惊喜的是,Linux开发团队持续不断地壮大, 并在世界范围内扩散开来。 这些开发者以旺盛的精力和高涨的热情不断改进着Linux的功能和性能。 Linux的开发工作并没有象“代码封闭论者”所妄言的那样 “最终消失在一片混乱之中”。正相反,Linux的开发是有组织有秩序的, 它采用的是一种精心设计并被细心维护的开发模式。在这一高效开发模式下, 数以千计的开发者们把各种各样的应用软件注入到Linux平台中来。
商业企业不再对Linux心怀戒惧, 因而大量的软件商开始提供Linux平台上的产品支持。 软件质量有了更可靠的保障,在办公室里使用Linux不必再有“风险自负” 的担心了。说到可靠性,Linux在1999年CIH病毒肆虐和一年后的 ‘爱虫’病毒流行时,证明了自己的强健。 这些相当简单的小病毒把世界搞得一团糟,而所有的Linux机器却丝毫不受影响。 这充分显示了它出色的免疫力。当Redhat这样的Linux排头兵走向市场的时候, 它们受到了热烈的欢迎。甚至在近几年dot-com网络泡沫破灭之后, 它们还在持续蓬勃地发展壮大。这也大大增强了人们对Linux的信心。 许多大大小小的商业公司开始采用Linux作服务器和工作站平台, 把Linux作为办公室系统的可靠支撑。
至于说道linux的未来发展方向这个实在难写。因为linux的开放性决定了 linux发展的多样性,从航空航天到机器人,从个人电脑到服务器,从大型实验室设备到简单的酒精浓度测量,linux几乎无所不在。也许我们的子孙也会 用linux来探索飞马星系,谁又能知道呢,不过有一点是肯定的,只要有网络存在linux就将以其强大的生命力而无所不在!如果马克思活着他也会为 linux欢呼的吧!:)
Saturday, March 11, 2006
经过数十日的配置,终于把openvpn+CA弄好了。
现在把openvpn的安装和配置方法写下来:
首先检测一下服务器上是否有LZO这个软件(LZO : real-time compression library, required for link compression):
#rpm -qa|grep lzo
要是显示有这个软件,那就可以直接跳到安装openvpn
配置LZO:
#./configure --with-lzo-headers="/usr/local/include" --with-lzo-lib= "/usr/local/lib"
#make
#make check
#make test (run a full test)
# make install (when logged in as root)
要没出现error那就表示已经安装好了,要出现了error可以等入http://www.oberhumer.com/opensource/lzo/
看一下howto
然后开始安装Openvpn:
$tar -zxvfopenvpn-2.0.5.tar.gz
$cd openvpn-2.0.5
$./configure
$make
$su
#make install
按照INSTALL文件中的说明,做如下操作:
#mknod /dev/net/tun c 10 200 #创建一个tun设备
#echo "alias char-major-10-200 tun" >;>; /etc/modprobe.conf
#echo 1 >; /proc/sys/net/ipv4/ip_forward #打开系统的转发功能
接下来就生成服务器客户端需要使用的keys了,为了方便,我们使用OpenVPN包自带的脚本生成。
#mkdir /etc/openvpn
#cp -r easy-rsa /etc/openvpn #切换到OpenVPN源代码目录执行
修改vars 文件
-------------CUT Here-------------
# easy-rsa parameter settings
# NOTE: If you installed from an RPM,
# don't edit this file in place in
# /usr/share/openvpn/easy-rsa --
# instead, you should copy the whole
# easy-rsa directory to another location
# (such as /etc/openvpn) so that your
# edits will not be wiped out by a future
# OpenVPN package upgrade.
# This variable should point to
# the top level of the easy-rsa
# tree.
export D=`pwd`
# This variable should point to
# the openssl.cnf file included
# with easy-rsa.
export KEY_CONFIG=$D/openssl.cnf
# Edit this variable to point to
# your soon-to-be-created key
# directory.
#
# WARNING: clean-all will do
# a rm -rf on this directory
# so make sure you define
# it correctly!
export KEY_DIR=$D/keys
# Issue rm -rf warning
echo NOTE: when you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
# Increase this to 2048 if you
# are paranoid. This will slow
# down TLS negotiation performance
# as well as the one-time DH parms
# generation process.
export KEY_SIZE=1024
# These are the default values for fields
# which will be placed in the certificate.
# Don't leave any of these fields blank.
# 定义你所在的国家,2个字符
export KEY_COUNTRY=CN
# 你所在的省份
export KEY_PROVINCE=Liaoning
# 你所在的城市
export KEY_CITY=Shenyang
# 你所在的组织
export KEY_ORG="ELM OpenVPN ORG"
# 你的单位
export KEY_OU="OpenVPN Service"
# 你的邮件地址
export KEY_EMAIL="elm@elm.freetcp.com"
-------------CUT Here-----------------
修改后保存,下面我们开始什成keys,以下为shell命令 "#" 为提示符
#. vars #使修改的变量生效
NOTE: when you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys
#./clean-all #初始化keys目录,创建所需要的文件和目录
#./build-ca #什成Root CA证书,用于签发Server和Client证书,请保护好keys/ca.key文件。
Generating a 1024 bit RSA private key
........................++++++
.............++++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]: #如果无需修改,直接回车
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [ELM OpenVPN ORG]:
Organizational Unit Name (eg, section) [OpenVPN Service]:
Common Name (eg, your name or your server's hostname) []:OpenVPN Root CA
Email Address [elm@elm.freetcp.com]:
# ls keys
ca.crt ca.key index.txt serial
我们可以看到ca.crt ca.key文件已经什成了。
下面我们为服务器生成 Diffie-Hellman 文件
# ./build-dh #TLS server 需要使用的一个文件
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..+..............................................................+.............
.......................................................+....+........+........
.+....................................................+.+.....................
...................................................................................
..........................................................+.......................
................+.................................+.............+..............
...................................................................+...............
........................................+.............................++*++*++*
创建并签发VPN Server使用的CA
# ./build-key-server server # server 为创建后的文件名,分别为server.crt server.key
Generating a 1024 bit RSA private key
......................++++++
...............++++++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [ELM OpenVPN ORG]:
Organizational Unit Name (eg, section) [OpenVPN Service]:
Common Name (eg, your name or your server's hostname) []:Server No.1
Email Address [elm@elm.freetcp.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName RINTABLE:'CN'
stateOrProvinceName RINTABLE:'Liaoning'
localityName RINTABLE:'Shenyang'
organizationName RINTABLE:'ELM OpenVPN ORG'
organizationalUnitNameRINTABLE:'OpenVPN Service'
commonName RINTABLE:'Server No.1'
emailAddress :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Feb 26 14:43:44 2015 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
接下来为VPN Client颁发CA证书,如果以后要为其他Client颁发证书,直接使用build-key命令签发新证书。
# ./build-key elm
Generating a 1024 bit RSA private key
........++++++
....................++++++
writing new private key to 'elm.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [ELM OpenVPN ORG]:
Organizational Unit Name (eg, section) [OpenVPN Service]:
Common Name (eg, your name or your server's hostname) []:ELM #注意Common Name最好不要相同,如果相同[server要加duplicate-cn选项],那么Email地址也不能相同
Email Address [elm@elm.freetcp.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName RINTABLE:'CN'
stateOrProvinceName RINTABLE:'Liaoning'
localityName RINTABLE:'Shenyang'
organizationName RINTABLE:'ELM OpenVPN ORG'
organizationalUnitName:PRINTABLE:'OpenVPN Service'
commonName :PRINTABLE:'ELM'
emailAddress :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Feb 26 14:45:36 2015 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
为防止恶意攻击(如DOS、UDP port flooding),我们生成一个"HMAC firewall"
#openvpn --genkey --secret keys/ta.key
生成证书吊销链文件,防止日后有人丢失证书,被非法用户接入VPN
#./make-crl vpncrl.pem
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
到现在为止,一切准备就绪,下面开始写配置文件,为了缩小篇幅,把原有注释都去掉了。
Server使用的配置文件server.conf
----------------CUT Here-------------
#申明本机使用的IP地址,也可以不说明
local 210.*.*.*
#申明使用的端口,默认1194
port 1194
#申明使用的协议,默认使用UDP,如果使用HTTP proxy,必须使用TCP协议
proto tcp
;proto udp
#申明使用的设备可选tap和tun,tap是二层设备,支持链路层协议。
#tun是ip层的点对点协议,限制稍微多一些。
#tun可以运行路由功能,tap只可以用作桥接功能,使用tun可以对登入vpn的用户设定策略性限制
;dev tap
dev tun
#OpenVPN使用的ROOT CA,使用build-ca生成的,用于验证客户是证书是否合法
ca ca.crt
#Server使用的证书文件
cert server.crt
#Server使用的证书对应的key,注意文件的权限,防止被盗
key server.key # This file should be kept secret
#CRL文件的申明,被吊销的证书链,这些证书将无法登录
crl-verify vpncrl.pem
#上面提到的生成的Diffie-Hellman文件
dh dh1024.pem
#这是一条命令的合集,如果你是OpenVPN的老用户,就知道这条命令的来由
#这条命令等效于:
# mode server #OpenVPN工作在Server模式,可以支持多client同时动态接入
# tls-server #使用TLS加密传输,本端为Server,Client端为tls-client
#
# if dev tun: #如果使用tun设备,等效于以下配置
# ifconfig 10.8.0.1 10.8.0.2 #设置本地tun设备的地址
# ifconfig-pool 10.8.0.4 10.8.0.251 #说明OpenVPN使用的地址池(用于分配给客户),分别是起始地址、结束地址
# route 10.8.0.0 255.255.255.0 #增加一条静态路由,省略下一跳地址,下一跳为对端地址,这里是: 10.8.0.2
# if client-to-client: #如果使用client-to-client这个选项
# push "route 10.8.0.0 255.255.255.0" #把这条路由发送给客户端,客户连接成功后自动加入路由表,省略了下一跳地址: 10.8.0.1
# else
# push "route 10.8.0.1" #否则发送本条路由,这是一个主机路由,省略了子网掩码和下一跳地址,分别为: 255.255.255.255 10.8.0.1
#
# if dev tap: #如果使用tap设备,则等效于以下命令
# ifconfig 10.8.0.1 255.255.255.0 #配置tap设备的地址
# ifconfig-pool 10.8.0.2 10.8.0.254 255.255.255.0 #客户端使用的地址池,分别是起始地址、结束地址、子网掩码
# push "route-gateway 10.8.0.1" #把环境变量route-gateway传递给客户机
#
server 10.8.0.0 255.255.255.0 #等效于以上命令
#用于记录某个Client获得的IP地址,类似于dhcpd.lease文件,
#防止openvpn重新启动后“忘记”Client曾经使用过的IP地址
ifconfig-pool-persist ipp.txt
#Bridge状态下类似DHCPD的配置,为客户分配地址,由于这里工作在路由模式,所以不使用
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
#通过VPN Server往Client push路由,client通过pull指令获得Server push的所有选项并应用
;push "route 192.168.10.0 255.255.255.0"
push "route 172.16.0.0 255.255.252.0" (改路由使得等入vpn的用户通过vpn服务进入到vpn服务器)
#VPN启动后,在VPN Server上增加的路由,VPN停止后自动删除
;route 10.9.0.0 255.255.255.252
#Run script or shell command cmd to validate client
#virtual addresses or routes. 具体查看manual
;learn-address ./script
#其他的一些需要PUSH给Client的选项
#
#使Client的默认网关指向VPN,让Client的所有Traffic都通过VPN走
;push "redirect-gateway"
#DHCP的一些选项,具体查看Manual
;push "dhcp-option DNS 10.8.0.1"
;push "dhcp-option WINS 10.8.0.1"
#如果可以让VPN Client之间相互访问直接通过openvpn程序转发,
#不用发送到tun或者tap设备后重新转发,优化Client to Client的访问效率
client-to-client
#如果Client使用的CA的Common Name有重复了,或者说客户都使用相同的CA
#和keys连接VPN,一定要打开这个选项,否则只允许一个人连接VPN
;duplicate-cn
#NAT后面使用VPN,如果VPN长时间不通信,NAT Session可能会失效,
#导致VPN连接丢失,为防止之类事情的发生,keepalive提供一个类似于ping的机制,
#下面表示每10秒通过VPN的Control通道ping对方,如果连续120秒无法ping通,
#认为连接丢失,并重新启动VPN,重新连接
#(对于mode server模式下的openvpn不会重新连接)。
keepalive 10 120
#上面提到的HMAC防火墙,防止DOS攻击,对于所有的控制信息,都使用HMAC signature,
#没有HMAC signature的控制信息不予处理,注意server端后面的数字肯定使用0,client使用1
tls-auth ta.key 0 # This file is secret
#对数据进行压缩,注意Server和Client一致
comp-lzo
#定义最大连接数
;max-clients 100
#定义运行openvpn的用户
user nobody
group nobody
#通过keepalive检测超时后,重新启动VPN,不重新读取keys,保留第一次使用的keys
persist-key
#通过keepalive检测超时后,重新启动VPN,一直保持tun或者tap设备是linkup的,
#否则网络连接会先linkdown然后linkup
persist-tun
#定期把openvpn的一些状态信息写到文件中,以便自己写程序计费或者进行其他操作
status openvpn-status.log
#记录日志,每次重新启动openvpn后删除原有的log信息
log /var/log/openvpn.log
#和log一致,每次重新启动openvpn后保留原有的log信息,新信息追加到文件最后
;log-append openvpn.log
#相当于debug level,具体查看manual
verb 3
--------------Cut Here-----------------
把server.conf文件保存到/etc/opennvpn目录中,并把使用easy-rsa下的脚本什成的key都复制到/etc/openvpn目录下,命令如下:
#cd /etc/openvpn
#cp easy-rsa/keys/ca.crt .
#cp easy-rsa/keys/server.crt .
#cp easy-rsa/keys/server.key .
#cp easy-rsa/keys/dh1024.pem .
#cp easy-rsa/keys/ta.key .
#cp easy-rsa/keys/vpncrl.pem .
创建OpenVPN启动脚本,可以在源代码目录中找到,在sample-scripts目录下的openvpn.init文件,将其复制到/etc/init.d/目录中,改名为openvpn
然后运行:
#chkconfig --add openvpn
#chkconfig openvpn on
立即启动openenvpn
#/etc/init.d/openvpn start
接下来配置客户端的配置文件client.conf:
Linux或Unix下使用扩展名为.conf Windows下使用的是.ovpn,并把需要使用的keys复制到配置文件所在目录ca.crt elm.crt elm.key ta.key
-------------Cut Here---------------------
# 申明我们是一个client,配置从server端pull过来,如IP地址,路由信息之类“Server使用push指令push过来的”
client
#指定接口的类型,严格和Server端一致
dev tun
;dev tap
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap
# 使用的协议,与Server严格一致
proto tcp
;proto udp
#设置Server的IP地址和端口,如果有多台机器做负载均衡,可以多次出现remote关键字
remote 210.*.*.* 1194
;remote my-server-2 1194
# 随机选择一个Server连接,否则按照顺序从上到下依次连接
;remote-random
# 始终重新解析Server的IP地址(如果remote后面跟的是域名),
# 保证Server IP地址是动态的使用DDNS动态更新DNS后,Client在自动重新连接时重新解析Server的IP地址
# 这样无需人为重新启动,即可重新接入VPN
resolv-retry infinite
# 在本机不邦定任何端口监听incoming数据,Client无需此操作,除非一对一的VPN有必要
nobind
# 和Server配置上的功能一样 如果使用了chroot或者su功能,最好打开下面2个选项,防止重新启动后找不到keys文件,或者nobody用户没有权限启动tun设备
persist-key
persist-tun
# 如果你使用HTTP代理连接VPN Server,把Proxy的IP地址和端口写到下面
# 如果代理需要验证,使用http-proxy server port [authfile] [auth-method]
# 其中authfile是一个2行的文本文件,用户名和密码各占一行,auth-method可以省略,详细信息查看Manual
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# 对于无线设备使用VPN的配置,看看就明白了
# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
# Root CA 文件的文件名,用于验证Server CA证书合法性,通过easy-rsa/build-ca生成的ca.crt,和Server配置里的ca.crt是同一个文件
ca ca.crt
# easy-rsa/build-key生成的key pair文件,上面生成key部分中有提到,不同客户使用不同的keys修改以下两行配置并使用他们的keys即可。
cert (用戶名).crt
key (用戶名).key
# Server使用build-key-server脚本什成的,在x509 v3扩展中加入了ns-cert-type选项
# 防止VPN client使用他们的keys + DNS hack欺骗vpn client连接他们假冒的VPN Server
# 因为他们的CA里没有这个扩展
ns-cert-type server
# 和Server配置里一致,ta.key也一致,注意最后参数使用的是1
tls-auth ta.key 1
# 压缩选项,和Server严格一致
comp-lzo
# Set log file verbosity.
verb 4
--------------Cut Here---------------------
如果想要vpn用戶可以訪問服務器後的内網就要在iptables上設置:
OPENVPN_IFACE="tun+"(VPN DEVICE)
OPENVPN_IP_RANGE ="10.8.0.0/24"
LAN_IP="172.16.*.*"(内網IP)
LAN_IFACE="eth1"
iptables -A INPUT -i $OPENVPN_IFACE -j ACCEPT(因為服務器要做内網的DNS SERVER所以INPUT也要accept)
iptables -A FORWARD -i $OPENVPN_IFACE -j ACCEPT(讓所有經過路由判斷後從openvpn interface進來的數據都可以進入内網)
iptables -t nat -A POSTROUTING -s $OPENVPN_IP_RANGE -o $ LAN_IFACE -j SNAT --to $LAN_IP
(要是對iptables有足夠的認識,可以在FORWARD CHAIN對進入内網的數據包做過濾,可以做到限制VPN用戶的訪問權限。)
以上的設置再加上在server.conf裏邊的一句“push "route 172.16.0.0 255.255.252.0" ”,就可以讓vpn用戶訪問server 的内網。
建立用戶的登入KEYS:
$cd /etc/openvpn/ easy-rsa/
$. vars
$./build-key (用戶名)
做到這裡已經openvpn已經算是完成了我需要的功能了。
參考:
FREEBSD VPN:
http://www.myitc.net/index.php?option=com_content&task=category§ionid=6&id=22&Itemid=47
CHINAUNIX.NET:
http://bbs.chinaunix.net/viewthread.php?tid=503434&extra=page%3D1%26filter%3Ddigest&page=1
Tuesday, March 07, 2006
超级详细Tcpdump 的用法 --轉載
第二种是确定传输方向的关键字,主要包括src , dst ,dst or src, dst and src ,这些关键字指明了传输的方向。举例说明,src 210.27.48.2 ,指明ip包中源地址是210.27.48.2 , dst net 202.0.0.0 指明目的网络地址是202.0.0.0 。如果没有指明方向关键字,则缺省是src or dst关键字。
第三种是协议的关键字,主要包括fddi,ip,arp,rarp,tcp,udp等类型。Fddi指明是在FDDI(分布式光纤数据接口网络)上的特定 的网络协议,实际上它是"ether"的别名,fddi和ether具有类似的源地址和目的地址,所以可以将fddi协议包当作ether的包进行处理和 分析。其他的几个关键字就是指明了监听的包的协议内容。如果没有指定任何协议,则tcpdump将会监听所有协议的信息包。
除了这三种类型的关键字之外,其他重要的关键字如下:gateway, broadcast,less,greater,还有三种逻辑运算,取非运算是 'not ' '! ', 与运算是'and','&&';或运算 是'or' ,'││';这些关键字可以组合起来构成强大的组合条件来满足人们的需要,下面举几个例子来说明。
普通情况下,直接启动tcpdump将监视第一个网络界面上所有流过的数据包。
# tcpdump
tcpdump: listening on fxp0
11:58:47.873028 202.102.245.40.netbios-ns > 202.102.245.127.netbios-ns: udp 50
11:58:47.974331 0:10:7b:8:3a:56 > 1:80:c2:0:0:0 802.1d ui/C len=43
0000 0000 0080 0000 1007 cf08 0900 0000
0e80 0000 902b 4695 0980 8701 0014 0002
000f 0000 902b 4695 0008 00
11:58:48.373134 0:0:e8:5b:6d:85 > Broadcast sap e0 ui/C len=97
ffff 0060 0004 ffff ffff ffff ffff ffff
0452 ffff ffff 0000 e85b 6d85 4008 0002
0640 4d41 5354 4552 5f57 4542 0000 0000
0000 00
使用-i参数指定tcpdump监听的网络界面,这在计算机具有多个网络界面时非常有用,
使用-c参数指定要监听的数据包数量,
使用-w参数指定将监听到的数据包写入文件中保存
A想要截获所有210.27.48.1 的主机收到的和发出的所有的数据包:
#tcpdump host 210.27.48.1
B想要截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信,使用命令:(在命令行中适用 括号时,一定要
#tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)
C如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令:
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2
D如果想要获取主机210.27.48.1接收或发出的telnet包,使用如下命令:
#tcpdump tcp port 23 host 210.27.48.1
E 对本机的udp 123 端口进行监视 123 为ntp的服务端口
# tcpdump udp port 123
F 系统将只对名为hostname的主机的通信数据包进行监视。主机名可以是本地主机,也可以是网络上的任何一台计算机。下面的命令可以读取主机hostname发送的所有数据:
#tcpdump -i eth0 src host hostname
G 下面的命令可以监视所有送到主机hostname的数据包:
#tcpdump -i eth0 dst host hostname
H 我们还可以监视通过指定网关的数据包:
#tcpdump -i eth0 gateway Gatewayname
I 如果你还想监视编址到指定端口的TCP或UDP数据包,那么执行以下命令:
#tcpdump -i eth0 host hostname and port 80
J 如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包
,使用命令:
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2
K 想要截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信,使用命令
:(在命令行中适用 括号时,一定要
#tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)
L 如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令:
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2
M 如果想要获取主机210.27.48.1接收或发出的telnet包,使用如下命令:
#tcpdump tcp port 23 host 210.27.48.1
第三种是协议的关键字,主要包括fddi,ip ,arp,rarp,tcp,udp等类型
除了这三种类型的关键字之外,其他重要的关键字如下:gateway, broadcast,less,
greater,还有三种逻辑运算,取非运算是 'not ' '! ', 与运算是'and','&&';或运算 是'o
r' ,'||';
第二种是确定传输方向的关键字,主要包括src , dst ,dst or src, dst and src ,
如果我们只需要列出送到80端口的数据包,用dst port;如果我们只希望看到返回80端口的数据包,用src port。
#tcpdump –i eth0 host hostname and dst port 80 目的端口是80
或者
#tcpdump –i eth0 host hostname and src port 80 源端口是80 一般是提供http的服务的主机
如果条件很多的话 要在条件之前加and 或 or 或 not
#tcpdump -i eth0 host ! 211.161.223.70 and ! 211.161.223.71 and dst port 80
如果在ethernet 使用混杂模式 系统的日志将会记录
May 7 20:03:46 localhost kernel: eth0: Promiscuous mode enabled.
May 7 20:03:46 localhost kernel: device eth0 entered promiscuous mode
May 7 20:03:57 localhost kernel: device eth0 left promiscuous mode
tcpdump对截获的数据并没有进行彻底解码,数据包内的大部分内容是使用十六进制的形式直接打印输出的。显然这不利于分析网络故障,通常的解决办法是 先使用带-w参数的tcpdump 截获数据并保存到文件中,然后再使用其他程序进行解码分析。当然也应该定义过滤规则,以避免捕获的数据包填满整个硬盘。