2008/07/23

在 mysql 建立 radius 所需的資料庫

在完成 freeradius 跟 mysql 的安裝之後,當然要建立給 radius 使用的資料庫。使用 freeradius 裡面的範例結構來建立就行了。檔案會在 /usr/src/freeradius/freeradius-1.1.3/doc/examples/mysql.sql

1. 建立 radius 資料庫
debianj:/# mysql -uroot -p**********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.32-Debian_7etch5-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database radius;
Query OK, 1 row affected (0.24 sec)

mysql> exit
Bye

2. 建立範例提供的資料表 (請注意那個只有一行)
debianj:/# mysql -uroot -p********** radius < /usr/src/freeradius/freeradius-1.1.3/doc/examples/mysql.sql
基本上他會建立
nas (對應 client.conf 設定 nas 的相關資料)
radacct
radcheck (對應 users 的使用者資料)
radgroupcheck
radgroupreply (對應 users 的群組資料)
radpostauth
radreply
usergroup
這八個資料表,至於各個資料表的功能,先不管,以後再看吧!

3. 建立群組資料
insert into radgroupreply (groupname,attribute,op,value) values ('taichung','Auth-Type',':=','Local');
insert into radgroupreply (groupname,attribute,op,value) values ('taichung','Service-Type',':=','Framed-User');
insert into radgroupreply (groupname,attribute,op,value) values ('taichung','Framed-IP-Address',':=','255.255.255.254');
insert into radgroupreply (groupname,attribute,op,value) values ('taichung','Framed-IP-Netmask',':=','255.255.255.0');

4. 建立使用者
insert into radcheck (username,attribute,op,value) values ('aimwang','User-Password',':=','superman');

5. 幫使用者跟群組建立關係
insert into usergroup (username,groupname) values ('aimwang','taichung');

6. 建立 nas 資料
insert into nas (nasname, shortname, secret) values ('192.168.10.1/24', 'RubytechTC', 'rubytech');

7. 把 radiusd.conf 的
authorize {sql}
accounting {sql}
session {sql}
post-auth {sql}
# 解開

8. 修改 sql.conf 裡面的 login 資訊
# Connect info
server = "localhost"
login = "radius"
password = "**************"

#
# Set to 'yes' to read radius clients from the database ('nas' table)
readclients = yes
server 如果在別台,請改掉
login 帳號,建議就增加一個給 radius 用吧
password 當然就是密碼啦
readclients 如果要從在資料庫管理 clients 的話,把他前面的 # 拿掉

2008/07/09

Debian 安裝 MySQL

為了提供 AAA 環境暖身,準備使用 freeradius + MySQL 來完成,所以要先安裝 MySQL。
沒有比安裝 MySQL 更簡單的了。

#apt-get install mysql-server


目前的版本為 5.0.32-7etch5

安裝完成之後,第一個工作自然是更改至高無上的 root 的密碼(MySQL 的不是系統的)。其中 ooxxoo 就是指定的新密碼

#mysqladmin -h localhost -u root password ooxxoo


使用文字模式管理 MySQL 實在很惱人,安裝 mysql gui tools

第一次使用,恐怕無法從遠端登錄成功。要更改 debian 的 ssh 設定,修改 /etc/ssh/ssh_config 新增下面內容

Host remotesql
Hostname *
User root
LocalForward *:13306 localhost:3306


然後執行

ssh -f -N remotesql


詢問密碼的時候,就輸入系統的 root 密碼
這段我也還有疑問,因為我不是設定成 root,但是 mysqladmin 卻可以用 root 登錄。先不管他,目前能用就好。GUI tools 的 Port 要記得改成 13306。