FreeRADIUS 、DaloRADIUS 搭建記錄
一. 安裝環境
系統環境:centos6.5 IP:192.168.30.242 hostname:vpn.org
軟件:PPTP、LAMP均已安裝。(請確保這些正常安裝,並能使用)。
二. 軟件包
ppp-2.4.5.tar.gz、daloradius-0.9-8.tar.gz、go-pear.phar。這些只是需要單獨下載文件,可以在官網去下載wget,也可去網盤下載:百度鏈接地址,密碼:rjs8
三. 開始正式的安裝
- 利用yum 安裝以下freeradius軟件包,並進行配置。
-
[[email protected] ~]# yum -y install freeradius freeradius-mysql freeradius-utils
安裝完成後,去修改配置文件/etc/raddb/users(修改文件前記得備份一下原文件),在此文件的最後添加下面一行內容:
testing Cleartext-Password := “password”
這句話的大概含義是 testing是一個用戶名,這個是安裝後系統默認的一個測試帳號,密碼是明文加密的password,無需任何改動,修改後保存。
執行 radiusd -X 命令,這是進入測試模式(運行此命令,會輸出很多信息,最後會停在
Listening on proxy address * port 1814
Ready to process requests.
這兩行內容後,一直等待登陸測試。還有個需要註意的,在進入測試模式時,radius服務必須是停止狀態,不然會報錯)。然後在打開一個新的終端。
在新的命令行裏輸入
[[email protected] ~]# radtest testing password 127.0.0.1 0 testing123 Sending Access-Request of id 249 to 127.0.0.1 port 1812 User-Name = "testing" User-Password = "password" NAS-IP-Address = 192.168.30.242 NAS-Port = 0 Message-Authenticator = 0x00000000000000000000000000000000 rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=249, length=20
根據最後一行的提示:Access-Accept 表明,表示成功啦。然後我們把上一步添加的一行內容註釋掉。
- 這一步去下載ppp的源碼包。
附上鏈接:http://download.chinaunix.net/download.php?id=35207&ResourceID=8334
下載完成後,解壓,copy文件。
[[email protected] ~]# tar zxvf ppp-2.4.5.tar.gz [[email protected] ~]# cp -R /root/ppp-2.4.5/pppd/plugins/radius/etc/ /usr/local/etc/radiusclient
- 現在去編輯/usr/local/etc/radiusclient/servers,加上一組服務器和密鑰。我添加的是localhost yxzcVPN。
[[email protected] ~]# vi /usr/local/etc/radiusclient/servers #Server Name or Client/Server pair Key #---------------- --------------- #portmaster.elemental.net hardlyasecret #portmaster2.elemental.net donttellanyone localhost yxzcVPN
編輯/usr/local/etc/radiusclient/dictionary,在文件最後添加內容
[[email protected] ~]# vim /usr/local/etc/radiusclient/dictionary #INCLUDE /etc/radiusclient/dictionary.microsoft (此處是默認的,手動註釋後,添加下面兩行內容) INCLUDE /usr/local/etc/radiusclient/dictionary.microsoft INCLUDE /usr/local/etc/radiusclient/dictionary.merit
編輯/etc/raddb/clients.conf,將client localhost段落下的secret改成剛才指定的密鑰yxzcVPN
[[email protected] ~]# vim /etc/raddb/clients.conf
secret = testing123 修改成下面
secret = yxzcVPN編輯/etc/raddb/radiusd.conf,找到$INCLUDE sql.conf,去掉前面的#;找到$INCLUDE sql/mysql/counter.conf,去掉前面的#註釋。
[[email protected] ~]# vim /etc/raddb/radiusd.conf $INCLUDE sql.conf $INCLUDE sql/mysql/counter.conf
- 進入mysql,創建raduys數據庫
[[email protected] ~]# mysql mysql> create database radius; Query OK, 1 row affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit
- 編輯/etc/raddb/sql.conf,配置login(用戶名),password(密碼),radius_db(數據庫名)等字段
[[email protected] ~]# vim /etc/raddb/sql.conf sql { # # Set the database to one of: # # mysql, mssql, oracle, postgresql # database = "mysql" # # Which FreeRADIUS driver to use. # driver = "rlm_sql_${database}" # Connection info: server = "localhost" #port = 3306
login = "root" password = "" # Database table configuration for everything except Oracle radius_db = "radius" readclients = yes 並找到這行,設為yes並去掉註釋符號#編輯/etc/raddb/sites-enabled/default
[[email protected] ~]# vim /etc/raddb/sites-enabled/default authorize段,關掉files,打開sql preacct段,關掉files accounting段,打開sql session段,打開sql post-auth段,打開sql pre-proxy段,關掉files
2.配置DaloRADIUS
- 先去下載daloradius軟件包,再下載一個pear包(需要安裝php-db)。
[[email protected] ~]# wget wget http://sourceforge.net/projects/daloradius/files/daloradius/daloradius-0.9-8/daloradius-0.9-8.tar.gz
[[email protected] ~]# wget http://pear.php.net/go-pear.phar [[email protected] ~]# php go-pear.phar [[email protected] ~]# pear install DB
創建目錄並解壓
[[email protected] ~]# mkdir /usr/share/daloRadius [[email protected] ~]# tar zxvf daloradius-0.9-8.tar.gz [[email protected] ~]# mv daloradius-0.9-8/* /usr/share/daloRadius/ [[email protected] ~]# rm -rf daloradius-0.9-8
- 下面是數據庫的導入
[[email protected] ~]# mysql -uroot -p radius < /usr/share/daloRadius/contrib/db/fr2-mysql-daloradius-and-freeradius.sql
編輯/usr/share/daloRadius/library/daloradius.conf.php,修改daloRADIUS的配置文件。如下所示,修改成這樣
[[email protected] ~]# vim /usr/share/daloRadius/library/daloradius.conf.php $configValues[‘CONFIG_DB_HOST‘] = ‘localhost‘; $configValues[‘CONFIG_DB_USER‘] = ‘root‘; $configValues[‘CONFIG_DB_PASS‘] = ‘‘; $configValues[‘CONFIG_DB_NAME‘] = ‘radius‘; $configValues[‘CONFIG_DB_TBL_RADUSERGROUP‘] = ‘radusergroup‘; $configValues[‘CONFIG_PATH_DALO_VARIABLE_DATA‘] = ‘/usr/share/daloRadius/var‘;
修改網站目錄鏈接
[[email protected] ~]# cd /var/www/html/ [[email protected] ~]# ln -s /usr/share/daloRadius/ admin
在本環境中,daloRADIUS管理頁面地址就是 http://192.168.30.242/admin,默認用戶administrator,密碼radius來登錄。
- 重啟httpd,mysqld,並設為自啟動
[[email protected] ~]# service mysqld restart [[email protected] ~]# service httpd restart [[email protected] ~]# chkconfig httpd on [[email protected] ~]# chkconfig mysqld on
3.配置PPPD
編輯/etc/ppp/options.pptpd[[email protected] ~]# vim /etc/ppp/options.pptpd (保證有以下5行內容並設置一致) refuse-pap refuse-chap refuse-mschap require-mppe-128 require-mschap-v2 (添加下面3行內容) plugin radius.so plugin radattr.so radius-config-file /usr/local/etc/radiusclient/radiusclient.conf
-
流量控制,進入mysql,插入語句
[[email protected] ~]# mysql mysql> use radius; mysql> INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Auth-Type‘,‘:=‘,‘Local‘); mysql> INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Service-Type‘,‘:=‘,‘Framed-User‘); mysql> INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Framed-IP-Address‘,‘:=‘,‘255.255.255.255‘); mysql> INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Framed-IP-Netmask‘,‘:=‘,‘255.255.255.0‘); mysql> INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Acct-Interim-Interval‘,‘:=‘,‘600‘); mysql> INSERT INTO radgroupreply (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Max-Monthly-Traffic‘,‘:=‘,‘5368709120‘); mysql> INSERT INTO radgroupcheck (groupname,attribute,op,VALUE) VALUES (‘user‘,‘Simultaneous-Use‘,‘:=‘,‘1‘);
-
現在我們訪問daloRADIUS,在Management中添加一個新用戶,註意密碼類型選擇Cleartext-Password。創建完會彈出窗口提示,如下圖
-
-
現在進行測試一下,開啟測試模式 radiusd -X (開啟測試模式,先把radiusd服務停止了。) ,另外開一個窗口,進行登錄測試
[[email protected] ~]# radtest xiaoming xiaoming localhost 0 yxzcVPN Sending Access-Request of id 227 to 127.0.0.1 port 1812 User-Name = "xiaoming" User-Password = "xiaoming" NAS-IP-Address = 192.168.30.242 NAS-Port = 0 Message-Authenticator = 0x00000000000000000000000000000000 rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=227, length=20
測試成功。測試完成後,啟動 radiusd 服務!
- 在上一步有個需要註意的情況,如果你在開啟測試模式時,報以下錯誤
/etc/raddb/sql.conf[22]:Instantiation failed for module “sql” /etc/raddb/sites-enabled/default[177]: Failed to load module “sql”. /etc/raddb/sites-enabled/default[69]: Errors parsing authorize section.
- 解決方法:進入數據庫
[[email protected] ~]# mysql mysql> use radius; mysql> ALTER TABLE `radius`.`nas` ADD COLUMN `server` VARCHAR(45) NOT NULL AFTER `secret` ;
- 測試成功的話添加在認證時檢測流量的語句,打開/etc/raddb/sites-enabled/default,在authorize一段插入:
[[email protected] ~]# vi /etc/raddb/sites-enabled/default update request { Group-Name := "%{sql:SELECT groupname FROM radusergroup WHERE username=‘%{User-Name}‘ ORDER BY priority}" } if ("%{sql: SELECT SUM(acctinputoctets+acctoutputoctets) FROM radacct WHERE username=‘%{User-Name}‘ AND date_format(acctstarttime, ‘%Y-%m-%d‘) >= date_format(now(),‘%Y-%m-01‘) AND date_format(acctstoptime, ‘%Y-%m-%d‘) <= last_day(now());}" >= "%{sql: SELECT value FROM radgroupreply WHERE groupname=‘%{Group-Name}‘ AND attribute=‘Max-Monthly-Traffic‘;}") { reject }
- 最後,重啟服務:
[[email protected] ~]# service radiusd restart [[email protected] ~]# service pptpd restart [[email protected] ~]# chkconfig pptpd on [[email protected] ~]# chkconfig radiusd on
本次實驗記錄結束,如果有錯誤之處,還請及時指出,我會完善的哈。
FreeRADIUS 、DaloRADIUS 搭建記錄