centos7下源码搭建FreeRadius+DaloRadius
一、安装软件及作用
1.1、Mariadb
Mariadb 用作认证服务所需的主数据库
1.2、FreeRadius
Rasius服务器的核心认证服务,用于提供radius认证服务
1.3、Apache 2.4+PHP7.4
用于部署FreeRadius服务的Web管理端
1.4、DaloRadius
FreeRadius服务的web管理端
二、部署前系统环境准备
2.1.1、更新系统
2.1.1.1、命令
yum update
2.1.1.2、命令执行部分截图
2.1.2、安装epel-release软件仓库
2.1.2.1、命令
yum install -y epel-release
2.1.2.2、命令部分截图
2.1.3、重启服务器
2.1.3.1、命令
reboot now
2.1.4、关闭SElinux(重启后失效)
2.1.4.1、临时关闭重启后失效
2.1.4.1.1、命令
setenforce 0 && getenforce
2.1.4.1.2、命令执行截图
2.1.4.2、长期关闭SElinux(重启后有效)
2.1.4.2.1、命令
==sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config ==
2.1.4.2.2、命令截图
2.1.5、关闭防火墙
2.1.5.1、命令
systemctl disable --now firewalld && systemctl status firewalld
2.1.5.2、命令执行截图
2.1.5.3、备注说明
上述命令的前段为取消开机启动防火墙并立即关闭防火墙,后段为查看服务状态命令,目的是便于部署测试,部署工作完成之后建议开启防火墙并将服务端口添加到放行列表中,radius服务所用的端口通常为1812和1813,数据库的端口通常为3306,web的端口默认为80。可以使用如下命令添加放行端口:
firewall-cmd --permanent --add-port=1812/udp
firewall-cmd --permanent --add-port=1813/udp
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --permanent --add-port=80/tcp
三、安装Mariadb
3.1、安装命令
yum install mariadb mariadb-server -y
3.2、部署截图(开始和结束中间省略)
3.3、添加开机启动并启动mariadb服务命令
systemctl enable --now mariadb && systemctl status mariadb
3.4、初始化数据库配置命令
mysql_secure_installation
初始化过程是交互式的过程,当前密码字段直接回车,新密码为本机的数据库管理员(root)密码,其他的选项按需选择即可。
3.5、创建FreeRadius所需的数据库
3.5.1、登录数据库
mysql -uroot -p *******
-p之后的****为实际的数据库密码,根据自己服务器的设置填写
3.5.2、创建数据库
- 建库脚本
create database if not exists radius character set ‘utf8’;
- 授权root可以远程访问数据库
grant all privileges on *.* to root@‘%’ identified by ‘root的密码’;
flush privileges;
四、安装FreeRadius
4.1、准备临时路径以及安装路径
mkdir -p /var/freeradius
上述目录用于存放FreeRadius源码
4.2、准备源码包
下载网站:https://github.com/FreeRADIUS/freeradius-server/releases
源码包下载后存放到/var/freeradius目录下
本文档使用的版本为3.2.3
4.3、安装源码包
[localhost]# cd /var/freeradius/
[localhost]# tar -xvf freeradius-server-3.2.3.tar.gz
[localhost]# cd /var/freeradius/freeradius-server-3.2.3
/*依赖包安装*/
[localhost]# yum install libtalloc-devel openssl-devel mysql-devel
[localhost]# cd /var/freeradius/freeradius-server-3.2.3/src/modules/rlm_sql/drivers/rlm_sql_mysql
[localhost]# ./configure --with-mysql-dir=/usr/share/mysql/ --with-mysql-lib-dir=/usr/lib/mysql/
[localhost]# cd /var/freeradius/freeradius-server-3.2.3/
[localhost]# ./configure
[localhost]# make && make install
4.4、配置服务启动文件
vi /usr/lib/systemd/system/radiusd.service
[Unit]
Description=FreeRADIUS high performance RADIUS server.
After=syslog.target network.target ipa.service dirsrv.target krb5kdc.service
[Service]
Type=forking
PIDFile=/usr/local/var/run/radiusd/radiusd.pid
ExecStartPre=-/bin/chown -R radiusd.radiusd /usr/local/var/run/radiusd
ExecStartPre=/usr/local/sbin/radiusd -C
ExecStart=/usr/local/sbin/radiusd -d /usr/local/etc/raddb
ExecReload=/usr/local/sbin/radiusd -C
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
4.5、配置开机启动
systemctl enable --now radiusd && systemctl status radiusd
4.6、导入表结构
FreeRadius的表结构于DaloRadius的表结构存在结构上的冲突,问题有可能是因为RadoRadius的数据脚本参照了低版本FreeRadius造成的,存在确实字段的情况。
为了解决此问题,小编将两者的数据库表结构修正调整成如下脚本,刷新后在部署DaloRadius的时后,就不需要单独刷新软件包自带的数据库脚本了。
- 数据库结构脚本radius.sql
- 基础数据脚本data.sql
mysql -uroot -p**** radius < radius.sql
mysql -uroot -p**** radius < data.sql
4.7、建立测试用户组
使用mysql -uroot -p**** radius命令登录到mysql执行sql语句,建立用户与用户入组过程的sql语句均在此环境下执行
insert into radgroupreply (groupname,attribute,op,value) values ('user','Auth-Type',':=','Local');
insert into radgroupreply (groupname,attribute,op,value) values ('user','Service-Type',':=','Framed-User');
insert into radgroupreply (groupname,attribute,op,value) values ('user','Framed-IP-Address',':=','255.255.255.255');
insert into radgroupreply (groupname,attribute,op,value) values ('user','Framed-IP-Netmask',':=','255.255.255.0');
4.8、建立测试用户
insert into radcheck (username,attribute,op,value) values ('test','Cleartext-Password',':=','testpwd');
4.9、用户入组
insert into radusergroup (username,groupname) values ('test','user');
4.10、修改认证配置
cd /usr/local/etc/raddb/mods-enabled/ && ln -s ../mods-available/sql
4.11、调整FreeRadius服务mysql配置
vi /usr/local/etc/raddb/mods-enabled/sql
dialect = “sqlite” 修改成 dialect = “mysql” #在文档的40行
driver = "rlm_sql_null"修改成driver = “rlm_sql_mysql” #在文档的65行
read_clients = yes #在文档的346行,去掉注释符号#“”
167到170行如下
# server = "localhost"
# port = 3306
# login = "radius"
# password = "radpass"
更换成如下内容,注意前边的注释符号“#”要去掉
server = "本服务器ip或localhost"
port = 3306
login = "root"
password = "您配置的密码"
删除87至95行,关闭tls
84 mysql {
85 # If any of the files below are set, TLS encryption is enabled
86 tls {
87 ca_file = "/etc/ssl/certs/my_ca.crt"
88 ca_path = "/etc/ssl/certs/"
89 certificate_file = "/etc/ssl/certs/private/client.crt"
90 private_key_file = "/etc/ssl/certs/private/client.key"
91 cipher = "DHE-RSA-AES256-SHA:AES128-SHA"
92
93 tls_required = no
94 tls_check_cert = no
95 tls_check_cert_cn = no
96 }
97
98 # If yes, (or auto and libmysqlclient reports warnings are
99 # available), will retrieve and log additional warnings from
100 # the server if an error has occured. Defaults to 'auto'
101 warnings = auto
102 }
调整后内容如下
mysql {
warnings = auto
}
4.12、测试从数据库取数据进行认证
4.12.1、确保radius服务处于关闭状态
systemctl stop radiusd
systemctl status radiusd
4.12.2、以调试模式启动FreeRadius
radiusd -X
4.12.3、在新终端中使用测试工具测试认证功能
radtest test testpwd localhost 1812 testing123
其中test为测试用户,testpwd为密码,localhost为radiusd服务监听地址,1812为radius端口号,testing123为NAS共享密钥
五、部署Daloradius
5.1、安装Apache
yum install httpd httpd-devel -y
systemctl enable --now httpd && systemctl status httpd
5.2、安装PHP7.4
5.2.1、依赖包安装
yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libicu-devel freetype-devel openldap-devel openldap openldap-devel libtool sqlite-devel re2c httpd httpd-devel
cp -frp /usr/lib64/libldap* /usr/lib/
5.2.2、下载PHP7.4
mkdir -p /var/PHP
cd /var/PHP
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-7.4
./buildconf
5.2.3、编译安装PHP7.4
cp -frp /usr/lib64/libldap* /usr/lib/
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --enable-gd --with-jpeg --with-freetype --with-apxs2=/usr/bin/apxs
make && make install
5.2.4、PHP命令全局化
ln -s /usr/local/php/sbin/* /usr/local/sbin/
ln -s /usr/local/php/bin/* /usr/local/bin/
5.2.5、添加并刷新环境变量
vi /etc/profile
export PATH=$PATH:/usr/local/php/bin
source /etc/profile
5.2.6、配置php-fpm(FastCGI进程管理器)
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
vi /usr/local/php/etc/php-fpm.d/www.conf
修改配置文件将用户更改成apache用户,结果如图
5.2.7、测试php-fpm
php-fpm && php -v
#创建php-fpm日志路径
mkdir /var/log/php-fpm
#修改php-fpm配置文件
vi /usr/local/php/etc/php-fpm.conf
cp /var/PHP/php-src/sapi/fpm/php-fpm.service /usr/lib/systemd/system/
systemctl enable --now php-fpm
systemctl status php-fpm
5.2.8、Apache启用PHP7.4
#打开Apache配置文件
vi /etc/httpd/conf/httpd.conf
#增加配置
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
#重新启动httpd
systemctl restart httpd
5.2.9、生成PHP信息查看页面并查看PHP信息
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
5.3、安装DaloRadius
5.3.1、下载源码
mkdir -p /var/daloradius && cd /var/daloradius
git clone https://github.com/lirantal/daloradius.git
cd daloradius
git checkout v1.1-2
pear install DB
pear install -a Mail_Mime
5.3.2、部署DaloRadius站点
cp -R daloradius/ /var/www/html/daloradius
chmod 664 /var/www/html/daloradius/library/daloradius.conf.php
vi /var/www/html/daloradius/library/daloradius.conf.php
$configValues['CONFIG_DB_HOST'] = 'mysql地址';
$configValues['CONFIG_DB_PORT'] = '3306';
$configValues['CONFIG_DB_USER'] = 'mysql登录账户';
$configValues['CONFIG_DB_PASS'] = 'mysql登录密码';
#Daloradius主目录
$configValues['CONFIG_PATH_DALO_VARIABLE_DATA'] = '/var/www/html/daloradius/';
5.3.3、登录daloradius
网址:http://*******/daloradius/login.php
用户名:administrator
密码:radius