这个安装并调试比较简单,先安装后进行本地认证测试,如果成功的话证明各个组件都是没有问题,然后再调试连接mysql,网上的教程都是从安装mysql开始的,其实没有这个必要,完全可以从现有的mysql数据库进行连接,省去安装mysql的步骤。在你现有的数据库建立radius数据库,然后运行如下sql指令,复制文本保存为sql文件并执行
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- Table structure for nas
DROP TABLE IF EXISTS nas
;
CREATE TABLE nas
(
id
int(10) NOT NULL AUTO_INCREMENT,
nasname
varchar(128) NOT NULL,
shortname
varchar(32) DEFAULT NULL,
type
varchar(30) DEFAULT 'other',
ports
int(5) DEFAULT NULL,
secret
varchar(60) NOT NULL DEFAULT 'secret',
server
varchar(64) DEFAULT NULL,
community
varchar(50) DEFAULT NULL,
description
varchar(200) DEFAULT 'RADIUS Client',
PRIMARY KEY (id
),
KEY nasname
(nasname
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of nas
BEGIN;
COMMIT;
-- Table structure for radacct
DROP TABLE IF EXISTS radacct
;
CREATE TABLE radacct
(
radacctid
bigint(21) NOT NULL AUTO_INCREMENT,
acctsessionid
varchar(64) NOT NULL DEFAULT '',
acctuniqueid
varchar(32) NOT NULL DEFAULT '',
username
varchar(64) NOT NULL DEFAULT '',
realm
varchar(64) DEFAULT '',
nasipaddress
varchar(15) NOT NULL DEFAULT '',
nasportid
varchar(15) DEFAULT NULL,
nasporttype
varchar(32) DEFAULT NULL,
acctstarttime
datetime DEFAULT NULL,
acctupdatetime
datetime DEFAULT NULL,
acctstoptime
datetime DEFAULT NULL,
acctinterval
int(12) DEFAULT NULL,
acctsessiontime
int(12) unsigned DEFAULT NULL,
acctauthentic
varchar(32) DEFAULT NULL,
connectinfo_start
varchar(50) DEFAULT NULL,
connectinfo_stop
varchar(50) DEFAULT NULL,
acctinputoctets
bigint(20) DEFAULT NULL,
acctoutputoctets
bigint(20) DEFAULT NULL,
calledstationid
varchar(50) NOT NULL DEFAULT '',
callingstationid
varchar(50) NOT NULL DEFAULT '',
acctterminatecause
varchar(32) NOT NULL DEFAULT '',
servicetype
varchar(32) DEFAULT NULL,
framedprotocol
varchar(32) DEFAULT NULL,
framedipaddress
varchar(15) NOT NULL DEFAULT '',
PRIMARY KEY (radacctid
),
UNIQUE KEY acctuniqueid
(acctuniqueid
),
KEY username
(username
),
KEY framedipaddress
(framedipaddress
),
KEY acctsessionid
(acctsessionid
),
KEY acctsessiontime
(acctsessiontime
),
KEY acctstarttime
(acctstarttime
),
KEY acctinterval
(acctinterval
),
KEY acctstoptime
(acctstoptime
),
KEY nasipaddress
(nasipaddress
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of radacct
BEGIN;
COMMIT;
-- Table structure for radcheck
DROP TABLE IF EXISTS radcheck
;
CREATE TABLE radcheck
(
id
int(11) unsigned NOT NULL AUTO_INCREMENT,
username
varchar(64) NOT NULL DEFAULT '',
attribute
varchar(64) NOT NULL DEFAULT '',
op
char(2) NOT NULL DEFAULT '==',
value
varchar(253) NOT NULL DEFAULT '',
PRIMARY KEY (id
),
KEY username
(username
(32))
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
-- Records of radcheck
BEGIN;
INSERT INTO radcheck
VALUES (1, 'test', 'Cleartext-Password', ':=', '123123123');
COMMIT;
-- Table structure for radgroupcheck
DROP TABLE IF EXISTS radgroupcheck
;
CREATE TABLE radgroupcheck
(
id
int(11) unsigned NOT NULL AUTO_INCREMENT,
groupname
varchar(64) NOT NULL DEFAULT '',
attribute
varchar(64) NOT NULL DEFAULT '',
op
char(2) NOT NULL DEFAULT '==',
value
varchar(253) NOT NULL DEFAULT '',
PRIMARY KEY (id
),
KEY groupname
(groupname
(32))
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of radgroupcheck
BEGIN;
COMMIT;
-- Table structure for radgroupreply
DROP TABLE IF EXISTS radgroupreply
;
CREATE TABLE radgroupreply
(
id
int(11) unsigned NOT NULL AUTO_INCREMENT,
groupname
varchar(64) NOT NULL DEFAULT '',
attribute
varchar(64) NOT NULL DEFAULT '',
op
char(2) NOT NULL DEFAULT '=',
value
varchar(253) NOT NULL DEFAULT '',
PRIMARY KEY (id
),
KEY groupname
(groupname
(32))
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of radgroupreply
BEGIN;
COMMIT;
-- Table structure for radpostauth
DROP TABLE IF EXISTS radpostauth
;
CREATE TABLE radpostauth
(
id
int(11) NOT NULL AUTO_INCREMENT,
username
varchar(64) NOT NULL DEFAULT '',
pass
varchar(64) NOT NULL DEFAULT '',
reply
varchar(32) NOT NULL DEFAULT '',
authdate
timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of radpostauth
BEGIN;
COMMIT;
-- Table structure for radreply
DROP TABLE IF EXISTS radreply
;
CREATE TABLE radreply
(
id
int(11) unsigned NOT NULL AUTO_INCREMENT,
username
varchar(64) NOT NULL DEFAULT '',
attribute
varchar(64) NOT NULL DEFAULT '',
op
char(2) NOT NULL DEFAULT '=',
value
varchar(253) NOT NULL DEFAULT '',
PRIMARY KEY (id
),
KEY username
(username
(32))
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of radreply
BEGIN;
COMMIT;
-- Table structure for radusergroup
DROP TABLE IF EXISTS radusergroup
;
CREATE TABLE radusergroup
(
username
varchar(64) NOT NULL DEFAULT '',
groupname
varchar(64) NOT NULL DEFAULT '',
priority
int(11) NOT NULL DEFAULT '1',
KEY username
(username
(32))
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Records of radusergroup
BEGIN;
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;
以上!
这里就完成了freeradius所需的mysql准备,下面安装freeradius
1、安装
apt-get update
apt-get install freeradius freeradius-mysql freeradius-utils -y
2、设置连接到mysql
cd /etc/freeradius/3.0/mods-enabled
ln -s ../mods-available/sql sql
3、修改sql配置文件
cd /etc/freeradius/3.0/mods-available
nano sql
需修改内容如下:
driver = "rlm_sql_mysql"
dialect = "mysql"
server = "你的mysql地址"
port = 3306
login = "你的mysql用户名"
password = "你的mysql密码"
radius_db = "radius"
read_clients = yes
4、配置freeradius文件
cd /etc/freeradius/3.0/sites-available/
nano default
删除file的选项并核实sql选项
authorize {
.....
sql
....
}
accounting {
......
sql
....
}
post-auth {
......
sql
....
}
session{
......
sql
.....}
以上,安装配置完成,使用
freeradius -X
进入debug模式查看整个认证的过程。
在数据库的radcheck添加一条记录
insert into radcheck VALUES('2','te1st','Cleartext-Password',':=','123123')
id注意不要重复了
这个时候另外连接一个服务器的CLI,使用如下命令进行测试
radtest test 123123 localhost 1812 testing123
如果返回 Access-Accept got Access-Reject说明认证失败,检查配置
如果返回Received Access-Accept说明认证成功。
下面就可以对VPN服务器进行配置连接到freeradius进行认证了。详情看下篇文章。