网站搜索

在 Rocky/Alma/CentOS 9|8 上安装 FreeRADIUS 和 Daloradius


我想在 CentOS 8/RHEL 8 上安装 FreeRADIUS 和 Daloradius。RADIUS,全称“远程认证拨号用户服务”,是一种用于远程用户认证和计费的网络协议。它提供 AAA 服务,即授权、认证和计费。

FreeRADIUS 是一个开源、高性能、可扩展、模块化且功能丰富的 RADIUS 服务器。FreeRADIUS 支持请求代理、故障转移和负载均衡,并且能够访问各种数据库后端。

FreeRADIUS 的主要功能

  • 通过多种方法选择用户配置,实现灵活配置。
  • 完全支持 RFC 2865 和 RFC 2866 属性。
  • EAP及其子类型:EAP-MD5、EAP-SIM、EAP-TLS、EAP-TTLS、EAP-PEAP和Cisco LEAP
  • 供应商 对近一百家供应商的特定属性,包括 BinTec、 Foundry、Cisco、Juniper、Lucent/Ascend、HP ProCurve、Microsoft、 USR/3Com、Acc/Newbridge 等等。

将 daloRADIUS 纳入其中

daloRADIUS 是一个先进的 RADIUS 网络管理 Web 平台,由 PHP 和 JavaScript 编写。它主要用于管理热点和基于 FreeRADIUS 服务器的通用 ISP 部署。以下是 daloRADIUS 的主要功能:

  • 支持多种数据库系统的数据库抽象层 – MySQL、SQLite、PostgreSQL、MsSQL 和 Oracle
  • 高级用户管理
  • 强大的图形报表和会计功能
  • 与 Google 地图集成以实现地理定位
  • 有计费引擎

按照接下来的步骤在 CentOS 8/RHEL 8 Linux 系统上安装 FreeRADIUS 和 daloRADIUS。

步骤 1:更新你的服务器

永远不要信任未更新的系统。所有已安装的包都可以通过在终端中执行以下命令来更新。

sudo dnf -y update

步骤 2:安装 Apache 和 PHP

我们将使用 Apache httpd 服务器在您的系统上托管 daloRADIUS。使用以下命令安装 httpd 和 PHP 软件包。

sudo dnf module reset -y php
sudo dnf module reset -y php && sudo dnf module install -y php:8.0
sudo dnf -y install php-{cli,curl,mysqlnd,devel,gd,pear,mbstring,xml,pear,zip}
sudo pear install DB
sudo pear install MDB2

检查已安装的 PHP 版本以确认安装是否成功。

$ php -v
PHP 8.0.30 (cli) (built: Aug  3 2023 17:13:08) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies

安装 Apache 网络服务器:

sudo dnf -y install @httpd

启动并启用 php-fpm 和 httpd 服务。

sudo systemctl enable --now httpd php-fpm

让我们通过检查这两个服务的状态来验证启动情况。

systemctl status httpd php-fpm

允许防火墙上的 HTTP 和 HTTPS 端口。

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Apache httpd 安装参考:

  • 在 RHEL/CentOS 8 上安装 Apache httpd 服务器

步骤 3:安装并配置 MariaDB

我们有一份关于在 RHEL/CentOS 8 上安装 MariaDB 数据库服务器的单独指南。请使用以下链接查阅。

  • 在 CentOS/RHEL 8 上安装 MariaDB 数据库服务器

安装完成后,以 root 用户身份访问 MySQL 控制台,并为 FreeRADIUS/daloRADIUS 创建数据库/用户。

$ mysql -u root -p
CREATE DATABASE radius;
GRANT ALL ON radius.* TO radius@localhost IDENTIFIED BY "StrongradIusPass";
FLUSH PRIVILEGES;
\q

步骤 4:安装 FreeRADIUS

FreeRADIUS 软件包可在模块化仓库中获得。

$ sudo dnf module list freeradius
Last metadata expiration check: 0:04:00 ago on Thu 10 Oct 2019 05:08:54 PM EAT.
CentOS-8 - AppStream
Name                      Stream                 Profiles                 Summary                                                                  
freeradius                3.0 [d]                server [d]               High-performance and highly configurable free RADIUS server              

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

要安装,只需运行该命令。

sudo dnf install -y @freeradius freeradius-utils freeradius-mysql

安装后启动服务。

sudo systemctl enable --now radiusd.service

现在您可以查看状态:

$ systemctl status radiusd.service
● radiusd.service - FreeRADIUS high performance RADIUS server.
   Loaded: loaded (/usr/lib/systemd/system/radiusd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-11-23 01:53:42 UTC; 3s ago
  Process: 14781 ExecStart=/usr/sbin/radiusd -d /etc/raddb (code=exited, status=0/SUCCESS)
  Process: 14778 ExecStartPre=/usr/sbin/radiusd -C (code=exited, status=0/SUCCESS)
  Process: 14732 ExecStartPre=/bin/sh /etc/raddb/certs/bootstrap (code=exited, status=0/SUCCESS)
  Process: 14731 ExecStartPre=/bin/chown -R radiusd.radiusd /var/run/radiusd (code=exited, status=0/SUCCESS)
 Main PID: 14783 (radiusd)
    Tasks: 6 (limit: 22612)
   Memory: 77.8M
   CGroup: /system.slice/radiusd.service
           └─14783 /usr/sbin/radiusd -d /etc/raddb

Nov 23 01:53:41 rocky8.mylab.io sh[14769]:                   URI:http://www.example.com/example_ca.crl
Nov 23 01:53:41 rocky8.mylab.io sh[14769]: Certificate is to be certified until Jan 22 01:53:41 2024 GMT (60 days)
Nov 23 01:53:41 rocky8.mylab.io sh[14769]: Write out database with 1 new entries
Nov 23 01:53:41 rocky8.mylab.io sh[14769]: Data Base Updated
Nov 23 01:53:41 rocky8.mylab.io sh[14741]: openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12  -passin pass:'whatever' -passout pass:'whatever'
Nov 23 01:53:41 rocky8.mylab.io sh[14741]: chmod g+r client.p12
Nov 23 01:53:41 rocky8.mylab.io sh[14741]: openssl pkcs12 -in client.p12 -out client.pem -passin pass:'whatever' -passout pass:'whatever'
Nov 23 01:53:41 rocky8.mylab.io sh[14741]: chmod g+r client.pem
Nov 23 01:53:41 rocky8.mylab.io sh[14741]: cp client.pem '[email '.pem
Nov 23 01:53:42 rocky8.mylab.io systemd[1]: Started FreeRADIUS high performance RADIUS server..

如果您的 Firewalld 服务正在运行,请允许 radius 和 http 的进出流量。Radius 服务器使用 UDP 端口 1812 和 1813。

sudo firewall-cmd --add-service=radius --permanent
sudo firewall-cmd --reload

步骤5:配置FreeRADIUS

要配置 FreeRADIUS 使用 MariaDB,请按照以下步骤操作。

1 – 导入 Radius 数据库模式以填充 radius 数据库

sudo su -
mysql -u root -p radius < /etc/raddb/mods-config/sql/main/mysql/schema.sql

2 – 配置 Radius

首先,你需要在 /etc/raddb/mods-enabled 下为 SQL 创建一个软链接

sudo ln -s /etc/raddb/mods-available/sql /etc/raddb/mods-enabled/

配置 SQL 模块 /raddb/mods-available/sql 并更改数据库连接参数以适应您的环境:

sudo vi /etc/raddb/mods-available/sql
  • sql 部分应类似于以下内容。
sql {
driver = "rlm_sql_mysql"
dialect = "mysql"

# Connection info:

server = "localhost"
port = 3306
login = "radius"
password = "StrongradIusPass"

# Database table configuration for everything except Oracle

radius_db = "radius"
}

# Set to ‘yes’ to read radius clients from the database (‘nas’ table)
# Clients will ONLY be read on server startup.
read_clients = yes

# Table to keep radius client info
client_table = "nas"

注释 MySQL SSL 设置。

 mysql {
                # If any of the files below are set, TLS encryption is enabled
#               tls {
#                       ca_file = "/etc/ssl/certs/my_ca.crt"
#                       ca_path = "/etc/ssl/certs/"
#                       certificate_file = "/etc/ssl/certs/private/client.crt"
#                       private_key_file = "/etc/ssl/certs/private/client.key"
#                       cipher = "DHE-RSA-AES256-SHA:AES128-SHA"
#
#                       tls_required = yes
#                       tls_check_cert = no
#                       tls_check_cert_cn = no
#               }

然后将 /etc/raddb/mods-enabled/sql 的组权限更改为 radiusd:

sudo chgrp -h radiusd /etc/raddb/mods-enabled/sql

重启 radiusd 服务

sudo systemctl restart radiusd

步骤 6:安装并配置 Daloradius(可选)

您可以使用 Daloradius 通过网页界面管理 RADIUS 服务器。这是一个可选配置,您可以根据自己的使用需求选择是否启用。

从 Github 下载 daloradius 代码。

sudo yum -y install git vim
git clone https://github.com/lirantal/daloradius.git

导入 Daloradius MySQL 表

mysql -u root -p radius < daloradius/contrib/db/fr3-mariadb-freeradius.sql
mysql -u root -p radius < daloradius/contrib/db/mariadb-daloradius.sql

将 daloradius 文件夹移动到 /var/www/html 路径下

sudo mv daloradius /var/www/

然后更改 http 文件夹的权限,并为 daloradius 配置文件设置正确的权限。

cd /var/www/daloradius/app/common/includes/
sudo cp daloradius.conf.php.sample daloradius.conf.php
sudo chown -R apache:apache /var/www/daloradius/

您现在应该修改 daloradius.conf.php 文件以调整 MySQL 数据库信息。

sudo vim daloradius.conf.php

设置连接所用的数据库名称、用户名和密码。

$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_PORT'] = '3306';
$configValues['CONFIG_DB_USER'] = 'radius';
$configValues['CONFIG_DB_PASS'] = 'StrongradIusPass';
$configValues['CONFIG_DB_NAME'] = 'radius';

为了确保一切正常工作,请重新启动 radiusd 和 httpd 服务。

sudo systemctl restart radiusd.service httpd
systemctl status radiusd.service httpd

服务状态输出中不应有错误:

创建所需的额外目录。

cd /var/www/daloradius/
sudo mkdir -p var/{log,backup}
sudo chown -R apache:apache var

安装以下 PHP 模块。

sudo pear install DB
sudo pear install MDB2

配置 Apache 网络服务器

配置 Apache 以监听端口 80 和端口 8000

$ sudo vim /etc/httpd/conf/httpd.conf
Listen 80
Listen 8000

为运维模块配置虚拟主机:

sudo tee /etc/httpd/conf.d/operators.conf<<EOF
<VirtualHost *:8000>
    ServerAdmin operators@localhost
    DocumentRoot /var/www/daloradius/app/operators

    <Directory /var/www/daloradius/app/operators>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    <Directory /var/www/daloradius>
        Require all denied
    </Directory>

    ErrorLog /var/log/httpd/daloradius/operators/error.log
    CustomLog /var/log/httpd/daloradius/operators/access.log combined
</VirtualHost>
EOF

接下来我们为用户创建虚拟主机:

sudo tee /etc/httpd/conf.d/users.conf<<EOF
<VirtualHost *:80>
    ServerAdmin users@localhost
    DocumentRoot /var/www/daloradius/app/users

    <Directory /var/www/daloradius/app/users>
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    <Directory /var/www/daloradius>
        Require all denied
    </Directory>

    ErrorLog /var/log/httpd/daloradius/users/error.log
    CustomLog /var/log/httpd/daloradius/users/access.log combined
</VirtualHost>
EOF

创建用于存储日志文件的目录。

sudo mkdir -p /var/log/httpd/daloradius/{operators,users}

禁用默认的 Apache 网络服务器欢迎页面。

sudo rm /etc/httpd/conf.d/welcome.conf

如果你启用了 SELinux,请相应地标记目录。

sudo yum -y install policycoreutils-python-utils
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/daloradius(/.*)?"
sudo restorecon -Rv /var/www/daloradius

如果SELinux处于强制模式,为httpd使用的端口8000添加标签。

sudo semanage port -m -t http_port_t -p tcp 8000

检查是否正确应用。

# semanage port -l | grep -w http_port_t
http_port_t                    tcp      8000, 80, 81, 443, 488, 8008, 8009, 8443, 9000

允许防火墙访问端口。

sudo firewall-cmd --add-service={http,https,radius} --permanent
sudo firewall-cmd --add-port=8000/tcp --permanent
sudo firewall-cmd --reload

重新启动服务以确保一切正常运行。

sudo systemctl restart httpd radiusd.service

可以使用 systemctl 检查您的服务状态:

systemctl status httpd radiusd

现在使用以下网址访问 daloradius。

  • RADIUS 管理应用程序: http://<ip>:8000/
  • RADIUS 用户门户应用程序:http://<ip>

RADIUS管理应用门户界面示例。

默认登录信息是:

Username: administrator
Password: radius

daloRADIUS 管理界面外观:

享受使用 FreeRADIUS 和 daloRADIUS:

  • 在 Ubuntu 上安装 FreeRADIUS 和 daloRADIUS