前置条件
首先要保证使用chap-secrets验证的PPTP服务能够正常使用。关于配置简单PPTP VPN的方法不在本文的范围之内,请参考这篇文章或其他相关教程。
其次,你需要在服务器上安装好HTTP+PHP+MySQL环境,本例中使用Nginx作为HTTP服务器。此外PHP需要安装PEAR。
pear的安装
命令行: wget http://pear.php.net/go-pear.phar | php
命令行:php go-pear.phar
安装配置流程
配置FreeRADIUS
1. 登入终端后,首先安装FreeRAIUS,一般源里两个版本,其中FreeRADIUS 1.x已经不被支持了,我们安装的是freeradius2。
yum
install
freeradius2 freeradius2-mysql freeradius2-utils
|
2. 安装完后,我们编辑/etc/raddb/users,在文件开头加上:testing Cleartext-Password := "password"。
Tips:你需要了解如何使用SSH终端,和终端里文本编辑的方法,例如Vim的使用。
3. 启动radiusd,第一次启动会生成密钥,稍等片刻即可。使用-X参数可以让调试信息直接输出屏幕:
radiusd -X
|
4. 新打开一个SSH终端,测试服务器是否连通:
radtest testing password 127.0.0.1 0 testing123
|
如果看到Access-Accept就说明连接成功了。如果看到类似“Ignoring request to authentication address * port 1812 from unknownclient”的文字,可能需要去修改/etc/raddb/clients.conf,将client localhost段下的ipaddr改为服务器的IP,而不是127.0.0.1。
测试连接成功后,我们可以把users里临时加上去的第一行删除。
5. 下载ppp源码,因为要用到其中的配置文件:
wget ftp://ftp.samba.org/pub/ppp/ppp-2.4.5.tar.gz
tar zxvf ppp-2.4.5.tar.gz
cp -R /root/ppp-2.4.5/pppd/plugins/radius/etc/ /usr/local/etc/radiusclient
6. 编辑/usr/local/etc/radiusclient/servers,加上一组服务器和密钥,本例中为“MyVPN”:
|
|
localhost radius
|
7. 编辑/usr/local/etc/radiusclient/dictionary,将最后一行改为:INCLUDE /usr/local/etc/radiusclient/dictionary.microsoft
可以再添加一行:INCLUDE /usr/local/etc/radiusclient/dictionary.merit
8. 编辑/etc/raddb/clients.conf,把client localhost段下的secret改成刚才指定的密钥。
9. 编辑/etc/raddb/radiusd.conf,找到$INCLUDE sql.conf,去掉前面的#;找到$INCLUDE sql/mysql/counter.conf,去掉前面的#。
10. 添加MySQL用户及数据库,你可以使用现成的phpMyAdmin等工具,也可以在终端下操作。本例中,创建了radius的用户和同名的数据库:
|
1
2
3
|
CREATE
USER
'radius'
@
'localhost'
IDENTIFIED
BY
'***'
;
CREATE
DATABASE
IF
NOT
EXISTS `radius` ;
GRANT
ALL
PRIVILEGES
ON
`radius` . *
TO
'radius'
@
'localhost'
;
|
11. 编辑/etc/raddb/sql.conf,配置login(用户名),password(密码),radius_db(数据库名)等字段,并找到readclients一行,设为yes并去掉注释符号#。
12. 编辑/etc/raddb/sites-enabled/default,根据下面的说明注释或取消注释相应的行:
authorize段,关掉files,打开sql,也可以把unix关掉preacct段,关掉filesaccounting段,打开sql,也可以把unix关掉session段,打开sqlpost-auth段,打开sqlpre-proxy段,关掉files
到这一步,我们的FreeRADIUS就算配置好了,用户信息都将保存在MySQL数据库中。至于数据库中的表,我们在后面统一导入。
配置DaloRADIUS
13. 首先下载并安装daloRADIUS,其中需要安装一个Pear-DB的包:
|
1
2
3
4
5
6
|
wget http:
//sourceforge
.net
/projects/daloradius/files/daloradius/daloradius-0
.9-8
/daloradius-0
.9-8.
tar
.gz
pear
install
DB
mkdir
/usr/share/daloRadius
tar
zxvf daloradius-0.9-8.
tar
.gz
mv
daloradius-0.9-8/*
/usr/share/daloRadius/
rm
-r daloradius-0.9-8
|
14. 这时我们将daloRADIUS中附带的sql文件导入MySQL数据库,别忘了输入密码:
mysql -uroot -p radius <
/usr/share/daloRadius/contrib/db/fr2-mysql-daloradius-and-freeradius
.sql
|
15. 编辑/usr/share/daloRadius/library/daloradius.conf.php,这是daloRADIUS的配置文件。首先是MySQL登录信息:
|
1
2
3
4
|
$configValues
[
'CONFIG_DB_HOST'
] =
'localhost'
;
$configValues
[
'CONFIG_DB_USER'
] =
'radius'
;
$configValues
[
'CONFIG_DB_PASS'
] =
'***'
;
// 设为自己的密码
$configValues
[
'CONFIG_DB_NAME'
] =
'radius'
;
|
下面有一个daloRADIUS的bug,默认配置中有一个表名和我们导入的不一样,把它改过来:
$configValues
[
'CONFIG_DB_TBL_RADUSERGROUP'
] =
'radusergroup'
;
|
然后修改daloRADIUS的路径:
$configValues
[
'CONFIG_PATH_DALO_VARIABLE_DATA'
] =
'/usr/share/daloRadius/var'
;
|
16. 添加Apache虚拟主机,如果有Web控制面板什么的自然就方便多了,不然就编辑/etc/httpd/conf/httpd.conf,加入:
|
1
2
3
|
Alias /vpn "/usr/share/daloRadius/"
<Directory "/usr/share/daloRADIUS">
</Directory>
|
17. 重启重启Apache和MySQL:
|
1
2
|
service httpd restart
service mysqld restart
|
18. 打开浏览器,进入daloRADIUS的管理页面(本例中为http://your.domain/vpn),使用默认用户名administrator和密码radius登录。
daloRADIUS似乎写的不怎么样,最新稳定版已经是三年之前的了,不过作者直到现在还在更新SVN,下次有机会可以用最新的SVN版本试试看。在Management中添加一个新用户,注意密码类型选择Cleartext-Password。
19. 在终端里再次启动radius -X,同时在另一个终端中用radtest username password localhost 0 MyVPN测试一下,看看现在是不是还能正常接通,如果没问题就OK,让我们把这套系统接驳到PPP上。
配置Pppd
20. 编辑/etc/ppp/options.pptpd,里面已经有许多配置选项了,我们要保证有下面的几行,如果没有就添加上去,为了保障用户登录的安全我们限制只使用MS-CHAPv2:
|
1
2
3
4
5
|
refuse-pap
refuse-chap
refuse-mschap
require-mppe-128
require-mschap-v2
|
在配置文件最后加上3行:
|
1
2
3
|
plugin radius.so
plugin radattr.so
radius-config-file /usr/local/etc/radiusclient/radiusclient.conf
|
启动服务
21. 一切完成后我们不需要使用debug模式启动radiusd了:
service radiusd start
|
22. 当然,我们可以把radiusd和pptpd设为开机启动服务:
|
1
2
|
chkconfig radiusd on
chkconfig pptpd on
|
至此,PPTP+FreeRADIUS+MySQL+daloRADIUS全部配置完毕,我们在本机上使用添加的用户名和密码拨入VPN,可以正常使用。在daloRADIUS中,还可以看到各个用户每次连接的时长,上传和下载的数据量统计等。daloRADIUS其他的使用方法,本文不再叙述。
来源:oschina
链接:https://my.oschina.net/u/216139/blog/49975