在ubuntu 16.04安裝freeradius (with mysql)

STEP 1. 安裝相關的套件

sudo apt-get install libauthen-radius-perl libauthen-simple-radius-perl libgcrypt11-dev wget build-essential

STEP 2. 安裝freeradius

sudo apt-get install freeradius freeradius-mysql

STEP 3. 安裝mysql server

sudo apt-get install mysql-server -y
#這裡要設定mysql的密碼

STEP 4. 在mysql中新增freeradius database

#登入mysql
sudo mysql -u root -p
Enter password:

#創立一個radius資料庫
mysql> create database radius;
Query OK, 1 row affected (0.00 sec)

#創立一個讓freeradius登入的帳戶(帳號:radius / 密碼:radiuspwd)
mysql> grant all on radius.* to radius@localhost identified by "radiuspwd";
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye

#在mysql中匯入freeradius database
sudo su

mysql -u root -p radius < /etc/freeradius/sql/mysql/schema.sql
Enter password: 

mysql -u root -p radius < /etc/freeradius/sql/mysql/nas.sql
Enter password:
 
#在freeradius中創建一個測試用戶
sudo mysql -u root -p

mysql> use radius;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> INSERT INTO radcheck (UserName, Attribute, Value) VALUES ('sqltest', 'Password', 'testpwd');
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye

STEP 5. 修改freeradius的設定

sudo vim /etc/freeradius/sql.conf

#修改mysql的登入資訊
database = "mysql"
login = "radius"
password = "radiuspwd"

#拿掉這行的註解
readclients = yes 

wq!存檔

sudo vim /etc/freeradius/sites-enabled/default

#把authorize、accounting、session、post-auth和post-auth裡面的Post-Auth-Type REJECT中的sql前面的註解都拿掉,如下:
 #  See "Accounting queries" in sql.conf
 sql

wq!存檔

sudo vi /etc/freeradius/radiusd.conf
#拿掉這行的註解
$INCLUDE sql.conf

STEP 6. 測試freeradius

#重啟freeradius服務
sudo /etc/init.d/freeradius stop
sudo /etc/init.d/freeradius start

#Debug mode
sudo freeradius -X
sudo freeradius -xx
sudo freeradius -Xxx

#測試
sudo radtest sqltest testpwd localhost 18128 testing123

如果出現Access-Accept就是成功了
Sending Access-Request of id 121 to 127.0.0.1 port 1812
 User-Name = "sqltest"
 User-Password = "testpwd"
 NAS-IP-Address = 127.0.1.1
 NAS-Port = 18128
 Message-Authenticator = 0x00000000000000000000000000000000
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=121, length=20

PS. 如果一直裝不成功,可以考慮把整個freeradius相關的packages跟files全部刪除,再跑一次上面的安裝流程

#Use apt to uninstall and remove all freeradius packages
sudo apt-get remove --purge freeradius freeradius-mysql -y
sudo apt-get autoremove -y
sudo apt-get autoclean

#Remove the freeradius folder
rm -rf /etc/freeradius

#Delete all freeradius files
sudo find / -iname 'freeradius*' -exec rm -rf {} \;



參考資料:

留言

熱門文章

主力如何控盤&台股處置制度解析

公司可以用什麼方式回饋股東

Openstack (1) : 簡介

[美股]初入美股市場半年投資心路歷程&績效