针对您200人左右的单位规模,我们将部署FreeRADIUS结合daloRADIUS的完整解决方案,以实现高效的VPN账户管理。
第一部分:系统准备
步骤1:更新系统并安装基础软件包
bash
Apply to docker-compo...
Run
# 更新系统
apt update
apt upgrade -y
# 安装必要工具
apt install -y curl wget net-tools gnupg lsb-release software-properties-common
步骤2:设置正确的时区
bash
Apply to docker-compo...
Run
# 设置时区
timedatectl set-timezone Asia/Shanghai
# 安装NTP确保时间同步
apt install -y ntp
systemctl enable ntp
systemctl start ntp
第二部分:安装数据库
步骤3:安装和配置MariaDB
bash
Apply to docker-compo...
Run
# 安装MariaDB
apt install -y mariadb-server mariadb-client
# 启动并设置为开机自启
systemctl enable mariadb
systemctl start mariadb
# 运行安全配置脚本(根据提示设置root密码及其他安全选项)
mysql_secure_installation
步骤4:创建RADIUS数据库和用户
登录到MySQL:
bash
Apply to docker-compo...
Run
mysql -u root -p
在MySQL提示符下执行以下命令:
sql
Apply to docker-compo...
CREATE DATABASE radius;
GRANT ALL PRIVILEGES ON radius.* TO 'radiususer'@'localhost' IDENTIFIED BY 'StrongPassword123';
FLUSH PRIVILEGES;
EXIT;
第三部分:安装和配置FreeRADIUS
步骤5:安装FreeRADIUS和SQL模块
bash
Apply to docker-compo...
Run
# 安装FreeRADIUS和SQL支持
apt install -y freeradius freeradius-mysql freeradius-utils
步骤6:配置FreeRADIUS使用SQL
bash
Apply to docker-compo...
Run
# 停止FreeRADIUS服务
systemctl stop freeradius
# 导入数据库模式
cd /etc/freeradius/3.0/mods-config/sql/main/mysql
mysql -u radiususer -p'StrongPassword123' radius < schema.sql
# 配置SQL模块
cd /etc/freeradius/3.0/mods-available
cp sql sql.orig
编辑SQL模块配置:
bash
Apply to docker-compo...
Run
nano /etc/freeradius/3.0/mods-available/sql
修改以下部分:
text
Apply to docker-compo...
sql {
driver = "rlm_sql_mysql"
dialect = "mysql"
# 修改连接信息
server = "localhost"
port = 3306
login = "radiususer"
password = "StrongPassword123"
radius_db = "radius"
# 确保以下选项设置正确
read_clients = yes
client_table = "nas"
# 打开这些行
authorize_check_query = "SELECT id, username, attribute, value, op FROM ${authcheck_table} WHERE username = LOWER('%{SQL-User-Name}') ORDER BY id"
authorize_reply_query = "SELECT id, username, attribute, value, op FROM ${authreply_table} WHERE username = LOWER('%{SQL-User-Name}') ORDER BY id"
# 确保日志查询配置正确
accounting_log_query = "INSERT INTO ${....acct_table1} (username, realm, acctsessionid, acctuniqueid, acctgroupid, acctunique, calledstationid, callingstationid, acctstarttime, acctupdatetime, acctstoptime, acctinterval, acctsessiontime, acctauthentic, connectinfo_start, connectinfo_stop, acctinputoctets, acctoutputoctets, calledstationid, callingstationid, acctterminatecause, servicetype, framedprotocol, framedipaddress) VALUES('%{SQL-User-Name}', '%{Realm}', '%{Acct-Session-Id}', '%{Acct-Unique-Session-Id}', '%{Acct-Group-Id}', '%{Acct-Unique-Session-Id}', '%{Called-Station-Id}', '%{Calling-Station-Id}', FROM_UNIXTIME(%{integer:Event-Timestamp}), FROM_UNIXTIME(%{integer:Event-Timestamp}), FROM_UNIXTIME(%{integer:Event-Timestamp}), '0', '0', '%{Acct-Authentic}', '%{Connect-Info}', '', '0', '0', '%{Called-Station-Id}', '%{Calling-Station-Id}', '', '%{Service-Type}', '%{Framed-Protocol}', '%{Framed-IP-Address}')"
}
步骤7:启用SQL模块
bash
Apply to docker-compo...
Run
# 启用SQL模块
cd /etc/freeradius/3.0/mods-enabled
ln -s ../mods-available/sql .
# 修改权限
chgrp -h freerad /etc/freeradius/3.0/mods-available/sql
chown -R freerad:freerad /etc/freeradius/3.0/mods-config/sql/
步骤8:配置RADIUS使用PAP认证
编辑默认站点配置:
bash
Apply to docker-compo...
Run
nano /etc/freeradius/3.0/sites-available/default
在authorize部分,确保有以下条目并取消注释:
text
Apply to docker-compo...
authorize {
# ...其他条目...
pap
sql
# ...其他条目...
}
在authenticate部分,确保有以下条目并取消注释:
text
Apply to docker-compo...
authenticate {
# ...其他条目...
Auth-Type PAP {
pap
}
# ...其他条目...
}
第四部分:安装和配置Web服务器
步骤9:安装Apache和PHP
bash
Apply to docker-compo...
Run
# 安装Apache和PHP
apt install -y apache2 libapache2-mod-php php php-common php-gd php-curl php-mysql php-mbstring php-xml php-zip
# 启动Apache并设置为开机自启
systemctl enable apache2
systemctl start apache2
步骤10:安装daloRADIUS
bash
Apply to docker-compo...
Run
# 安装Git
apt install -y git
# 下载daloRADIUS
cd /var/www/html
git clone https://github.com/lirantal/daloradius.git
# 设置权限
chown -R www-data:www-data /var/www/html/daloradius
步骤11:配置daloRADIUS数据库
bash
Apply to docker-compo...
Run
# 导入daloRADIUS数据库架构
cd /var/www/html/daloradius
mysql -u radiususer -p'StrongPassword123' radius < contrib/db/fr2-mysql-daloradius-and-freeradius.sql
mysql -u radiususer -p'StrongPassword123' radius < contrib/db/mysql-daloradius.sql
步骤12:配置daloRADIUS
bash
Apply to docker-compo...
Run
# 创建配置文件
cp /var/www/html/daloradius/library/daloradius.conf.php.sample /var/www/html/daloradius/library/daloradius.conf.php
编辑配置文件:
bash
Apply to docker-compo...
Run
nano /var/www/html/daloradius/library/daloradius.conf.php
修改以下内容:
php
Apply to docker-compo...
$configValues['DALORADIUS_VERSION'] = '1.0';
$configValues['FREERADIUS_VERSION'] = '3';
$configValues['CONFIG_DB_ENGINE'] = 'mysqli';
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_PORT'] = '3306';
$configValues['CONFIG_DB_USER'] = 'radiususer';
$configValues['CONFIG_DB_PASS'] = 'StrongPassword123';
$configValues['CONFIG_DB_NAME'] = 'radius';
步骤13:创建Apache虚拟主机配置
bash
Apply to docker-compo...
Run
nano /etc/apache2/sites-available/daloradius.conf
添加以下内容:
text
Apply to docker-compo...
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/daloradius
ServerName radius.yourdomain.com
<Directory /var/www/html/daloradius>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/daloradius-error.log
CustomLog ${APACHE_LOG_DIR}/daloradius-access.log combined
</VirtualHost>
启用站点:
bash
Apply to docker-compo...
Run
a2ensite daloradius.conf
systemctl reload apache2
第五部分:配置VPN服务器使用RADIUS
步骤14:安装L2TP/IPsec或IKEv2
在这里,我们将配置基于IPsec的L2TP VPN:
bash
Apply to docker-compo...
Run
# 安装L2TP和IPsec
apt install -y strongswan strongswan-pki libcharon-extra-plugins libcharon-extauth-plugins libstrongswan-extra-plugins xl2tpd
步骤15:配置VPN使用RADIUS认证
创建RADIUS客户端配置文件:
bash
Apply to docker-compo...
Run
nano /etc/freeradius/3.0/clients.conf
添加以下内容:
text
Apply to docker-compo...
client localhost {
ipaddr = 127.0.0.1
secret = radiussecret
require_message_authenticator = no
nastype = other
}
配置XL2TPD使用RADIUS:
bash
Apply to docker-compo...
Run
apt install -y radiusclient1
# 配置radiusclient
nano /etc/radiusclient/radiusclient.conf
修改以下行:
text
Apply to docker-compo...
authserver localhost
acctserver localhost
servers /etc/radiusclient/servers
编辑服务器文件:
bash
Apply to docker-compo...
Run
nano /etc/radiusclient/servers
添加:
text
Apply to docker-compo...
localhost radiussecret
配置PPP使用RADIUS:
bash
Apply to docker-compo...
Run
nano /etc/ppp/options.xl2tpd
添加:
text
Apply to docker-compo...
plugin radius.so
radius-config-file /etc/radiusclient/radiusclient.conf
步骤16:配置IPsec
bash
Apply to docker-compo...
Run
cat > /etc/ipsec.conf << EOF
config setup
charondebug="ike 1, knl 1, cfg 0"
uniqueids=yes
strictcrlpolicy=no
conn %default
ikelifetime=60m
keylife=20m
rekeymargin=3m
keyingtries=1
keyexchange=ikev1
authby=secret
ike=aes128-sha1-modp1024,3des-sha1-modp1024!
esp=aes128-sha1-modp1024,3des-sha1-modp1024!
conn L2TP-PSK
type=transport
left=%any
leftprotoport=17/1701
right=%any
rightprotoport=17/1701
auto=add
EOF
cat > /etc/ipsec.secrets << EOF
%any %any : PSK "your_pre_shared_key"
EOF
步骤17:配置XL2TPD
bash
Apply to docker-compo...
Run
cat > /etc/xl2tpd/xl2tpd.conf << EOF
[global]
ipsec saref = yes
saref refinfo = 30
[lns default]
ip range = 192.168.42.10-192.168.42.250
local ip = 192.168.42.1
refuse pap = yes
require authentication = yes
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
EOF
步骤18:配置系统参数和防火墙
bash
Apply to docker-compo...
Run
# 启用IP转发
echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/99-vpn.conf
sysctl -p /etc/sysctl.d/99-vpn.conf
# 配置防火墙
iptables -A INPUT -p udp --dport 500 -j ACCEPT
iptables -A INPUT -p udp --dport 4500 -j ACCEPT
iptables -A INPUT -p udp --dport 1701 -j ACCEPT
iptables -A FORWARD -s 192.168.42.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.42.0/24 -o eth0 -j MASQUERADE
# 持久化防火墙规则
apt install -y iptables-persistent
netfilter-persistent save
步骤19:启动和启用服务
bash
Apply to docker-compo...
Run
# 启动RADIUS
systemctl start freeradius
systemctl enable freeradius
# 启动VPN服务
systemctl start strongswan
systemctl enable strongswan
systemctl start xl2tpd
systemctl enable xl2tpd
第六部分:用户管理和限制设置
步骤20:登录daloRADIUS并初始配置
在浏览器中访问:http://服务器IP/daloradius
默认登录凭据:
用户名: administrator
密码: radius
登录后,请立即:
更改管理员密码(Management -> Operators -> Administrator -> Edit)
设置系统配置(Config -> Main Configuration)
步骤21:批量添加用户
daloRADIUS提供多种方式添加用户:
单个添加:
Management -> Users -> New User
批量添加:
Management -> Users -> Import Users
创建用户模板:
为所有用户设置共同的标准配置。
步骤22:设置使用限制
在daloRADIUS中,您可以为用户设置以下限制:
时间限制:
设置用户账号有效期 (Expiration)
设置最大使用时间 (Max-All-Session)
设置每日使用限制 (Max-Daily-Session)
流量限制:
设置最大上传流量 (Max-Upload)
设置最大下载流量 (Max-Download)
设置总流量限制 (Max-Total-Octets)
同时连接限制:
设置最大同时连接数 (Simultaneous-Use)
步骤23:创建用户组和访问策略
为便于管理大量用户,创建用户组:
在daloRADIUS中导航到 Management -> User-Groups > New User-Group
创建不同的用户组(如"管理层"、"技术部"、"普通员工"等)
为每个组设置不同的访问策略和使用限制
步骤24:配置报表和监控
设置定期报表和监控:
Reports -> 配置报表发送选项
配置通知规则,当用户接近流量或时间限制时发送提醒
步骤25:测试系统
创建测试用户账号
使用VPN客户端尝试连接
测试时间和流量限制是否生效
监控系统日志检查认证请求
第七部分:系统优化和备份
步骤26:优化数据库性能
bash
Apply to docker-compo...
Run
# 优化MySQL配置
nano /etc/mysql/mariadb.conf.d/50-server.cnf
添加或修改以下参数:
text
Apply to docker-compo...
[mysqld]
innodb_buffer_pool_size = 256M
query_cache_size = 32M
query_cache_limit = 1M
重启数据库:
bash
Apply to docker-compo...
Run
systemctl restart mariadb
步骤27:配置自动备份
创建备份脚本:
bash
Apply to docker-compo...
Run
nano /usr/local/bin/backup_radius.sh
添加以下内容:
bash
Apply to docker-compo...
Run
#!/bin/bash
BACKUP_DIR="/var/backups/radius"
DATE=$(date +%Y%m%d)
mkdir -p $BACKUP_DIR
# 备份数据库
mysqldump -u radiususer -p'StrongPassword123' radius > $BACKUP_DIR/radius_db_$DATE.sql
# 备份配置文件
tar -czf $BACKUP_DIR/radius_config_$DATE.tar.gz /etc/freeradius /etc/strongswan /etc/xl2tpd /var/www/html/daloradius/library/daloradius.conf.php
# 删除30天前的备份
find $BACKUP_DIR -name "radius_db_*" -mtime +30 -delete
find $BACKUP_DIR -name "radius_config_*" -mtime +30 -delete
设置执行权限并添加定时任务:
bash
Apply to docker-compo...
Run
chmod +x /usr/local/bin/backup_radius.sh
crontab -e
添加:
text
Apply to docker-compo...
0 2 * /usr/local/bin/backup_radius.sh
第八部分:安全加固
步骤28:设置防火墙规则
bash
Apply to docker-compo...
Run
# 限制SSH访问
ufw allow from 您的管理IP地址 to any port 22
# 只允许特定IP访问RADIUS管理界面
ufw allow from 您的管理IP地址 to any port 80
ufw allow from 您的管理IP地址 to any port 443
# 允许VPN流量
ufw allow 500/udp
ufw allow 4500/udp
ufw allow 1701/udp
# 启用防火墙
ufw enable
步骤29:配置SSL证书
bash
Apply to docker-compo...
Run
# 安装Certbot
apt install -y certbot python3-certbot-apache
# 获取证书
certbot --apache -d radius.yourdomain.com
步骤30:编写用户使用指南
创建详细的用户指南,包括:
VPN连接设置步骤(针对不同设备)
用户账号获取和管理说明
使用限制和注意事项
常见问题解答和故障排除
技术支持联系方式
完成部署
至此,您已经完成了支持200人规模的FreeRADIUS + daloRADIUS + VPN综合解决方案的部署。该系统具备以下功能:
集中化用户认证和授权管理
基于时间和流量的精细控制
分组管理和访问策略
完整的报表和监控功能
安全加固和备份机制
您可以通过daloRADIUS界面轻松管理所有用户,并根据需要调整各种限制。系统也可以进一步扩展,支持更多高级功能如动态VLAN分配、时间段限制等。
如果您在部署过程中遇到任何问题或需要进一步的定制,请告诉我具体的需求。