centos7.2安装radius服务器

安装radius服务器

一.安装LAMP环境
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel

yum -y install httpd httpd-devel
yum -y install mariadb-server mariadb
yum -y install php php-devel php-mysql php-common php-gd php-mbstring php-mcrypt php-imap php-odbc php-pear php-xml php-xmlrpc php-pear-DB
环境centos7.2
1.安装http和mariadb
systemctl enable httpd
systemctl enable mariadb

systemctl start httpd
systemctl start mariadb

systemctl status httpd
systemctl status mariadb

本文中radius的密码统一设置成radpass,主要是为了安装方便,后续可以在数据库中更改
初始设置MariaDB,设置root密码,出于安全考虑,考虑删除匿名用户和禁用远程根登录,参见下面的示例配置。
#设置密码后一路回车
mysql_secure_installation

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

2.创建radius数据库和用户名密码
mysql -u root -pradpass
MariaDB [(none)]> create database radius;
#GRANT 权限 ON 数据库. TO 用户名@主机名IDENTIFIED BY "密码";
#对某个特定数据库中的所有表单给予授权和创建数据库管理账户
MariaDB [(none)]> grant all on radius.
to radius@"localhost" identified by "radpass";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
参考参照文档:
https://www.cnblogs.com/opsprobe/p/9769555.html
https://blog.51cto.com/wzlinux/1736744?cid=727963
如果上面所安装的php和本机的php不适配,按照如下方法进行安装即可。
3.安装PHP7
yum -y upgrade :只是升级所有软件包,但是不升级软件和系统内核。
systemctl restart httpd.service
yum -y remove php-common
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum list php*|sort -r
yum -y install php72w php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel php-pear-DB
重启httpd服务
systemctl restart httpd.service
查看php版本
php -v
4.测试php
vim /var/www/html/info.php
输入以下内容:
<?php
phpinfo();
?>
centos7.2安装radius服务器
curl http://192.168.0.163//info.php
以上LAMP环境搭建完成

二.安装Radius
yum -y install freeradius freeradius-utils freeradius-mysql
启动radius和设置为开机启动
systemctl start radiusd.service
systemctl enable radiusd.service

查看Radius使用的端口,然后添加Radius服务到防火墙中;
防火墙直接关闭就算了
firewall-cmd --state
not running
##########################################忽略##########################################
cat /usr/lib/firewalld/services/radius.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>RADIUS</short>
<description>The Remote Authentication Dial In User Service (RADIUS) is a protocol for user authentication over networks. It is mostly used for modem, DSL or wireless user authentication. If you plan to provide a RADIUS service (e.g. with freeradius), enable this option.</description>
<port protocol="tcp" port="1812"/>
<port protocol="udp" port="1812"/>
<port protocol="tcp" port="1813"/>
<port protocol="udp" port="1813"/>
</service>
firewall-cmd --state #查看防火墙状态,启动状态才能添加规则,centos7中默认防火墙就是firewalld,一般不需要额外设置。
firewall-cmd --add-service=radius --permanent # 添加 Radius 服务到 firewalld 防火墙中。
firewall-cmd --reload #让配置的防火墙策略立即生效
firewall-cmd --list-services #列举区域中启用的服务
##########################################忽略##########################################
三、配置FreeRadius
cd /etc/raddb/mods-config/sql/main/mysql/
mv setup.sql setup.sql-backup #备份 setup.sql 配置文件
grep -v "#" /etc/raddb/mods-config/sql/main/mysql/setup.sql-backup > /etc/raddb/mods-config/sql/main/mysql/setup.sql
centos7.2安装radius服务器
#过滤有#注释符号的信息行
进入 vim setup.sql 查看配置文件

CREATE USER 'radius'@'localhost';
SET PASSWORD FOR 'radius'@'localhost' = PASSWORD('radpass');
GRANT SELECT ON radius.* TO 'radius'@'localhost';
GRANT ALL on radius.radacct TO 'radius'@'localhost';
GRANT ALL on radius.radpostauth TO 'radius'@'localhost';
mysql -u root -p 回车,输入密码后
然后执行source /etc/raddb/mods-config/sql/main/mysql/setup.sql
然后 use radius 回车,打开radius数据库
导入 schema.sql 表的信息
source /etc/raddb/mods-config/sql/main/mysql/schema.sql
导入完成后,可以用命令查看导入的数据表的信息
show databases; #查看有哪些库
use radius; #打开radius数据库
show tables; #显示radius数据库里的所有表
/etc/raddb/sql/mysql/schema.sql #主数据库定义8个表,包括
nas #网络设备表
radacct #计费情况表
radcheck #用户检查信息表
radgroupcheck #用户组检查信息表
radgroupreply #用户组回复信息表
radpostauth #认证后处理信息,可以包括认证请求成功和拒绝的记录。
radreply #用户回复信息表
radusergroup #用户和组关系表
为/etc/raddb/mods-enabled 创建软连接
ln -s /etc/raddb/mods-available/sql /etc/raddb/mods-enabled/

编辑/etc/raddb/mods-available/sql文件
centos7.2安装radius服务器
driver = "rlm_sql_mysql"
dialect = "mysql"
server = "localhost"
port = 3306
login = "radius"
password = "radpass"
radius_db = "radius"
将/etc/raddb/mods-enabled/sql所属组更改为radiusd:
chgrp -h radiusd /etc/raddb/mods-enabled/sql
添加启动服务,调整FreeRadius与MariaDB的启动顺序,FreeRadius必须在MariaDB启动之后启动,在[Unit]部分,增加After=mariadb.service,如下所示:
systemctl enable radiusd.service

编辑/etc/systemd/system/multi-user.target.wants/radiusd.service文件
centos7.2安装radius服务器
[Unit]
Description=FreeRADIUS high performance RADIUS server.
After=syslog.target network.target ipa.service dirsrv.target krb5kdc.service
After=mariadb.service

添加客户端连接设置
mv /etc/raddb/clients.conf /etc/raddb/clients.conf-backup
grep -v "#" /etc/raddb/clients.conf-backup > /etc/raddb/clients.conf
编辑/etc/raddb/clients.conf
无特殊设置让所有的IP都可以连接
centos7.2安装radius服务器
client all_client {
ipaddr = 0.0.0.0/0
secret = testing123
require_message_authenticator = no
}
raidus 客户端配置ip信息,例如:
client x.x.x.x { #路由器的IP地址
ipaddr = x.x.x.x #路由器的IP地址
secret = xxxxxxxxxx #路由器和radius服务器的连接密码
}

可以执行 tail -f /var/log/radius/radius.log 去查看radius服务的日志看有没有错误。

四、安装FreeRADIUS管理界面Daloradius
cd /var/www/html/
wget https://github.com/lirantal/daloradius/archive/master.zip
链接: https://pan.baidu.com/s/1RnXOxkZs3LXGwTl-3CUPow 提取码: bs6n
unzip master.zip
mv daloradius-master/ daloradius
daloradius-0.9-9.tar.gz
链接:https://pan.baidu.com/s/1vuyPLVnXhb78Bb68ZGNWAQ
提取码:fa63
tar -zxvf daloradius-0.9-9.tar.gz
mv daloradius-0.9-9 daloradius

进入daloradius目录,导入daloradius数据库
cd daloradius
mysql -u root -p radius < contrib/db/fr2-mysql-daloradius-and-freeradius.sql
mysql -u root -p radius < contrib/db/mysql-daloradius.sql

设置daloradius目录用户组和用户,设置daloradius.conf.php权限
chown -R apache:apache /var/www/html/daloradius/
chmod 664 /var/www/html/daloradius/library/daloradius.conf.php

编辑/var/www/html/daloradius/library/daloradius.conf.php文件,数据库连接信息
centos7.2安装radius服务器
centos7.2安装radius服务器
(28-33行)
$configValues['CONFIG_DB_ENGINE'] = 'mysql';
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_PORT'] = '3306'; #连接mysql数据库的端口
$configValues['CONFIG_DB_USER'] = 'root'; #连接mysql数据库的账户
$configValues['CONFIG_DB_PASS'] = 'rdbpass'; #连接mysql数据库账号的密码
$configValues['CONFIG_DB_NAME'] = 'radius'; #连接mysql的radius数据库

下面还有几个 daloradius 的 bug,默认配置中有几个文件路径和我们导入的不一样,把它改过来:

$configValues['CONFIG_FILE_RADIUS_PROXY'] = '/etc/raddb/proxy.conf';(68行)
$configValues['CONFIG_PATH_DALO_VARIABLE_DATA'] = '/var/www/html/daloradius/var'; (70行)
$configValues['CONFIG_MAINT_TEST_USER_RADIUSSECRET'] = 'testing123'; (88行) #注意这条,要和 /etc/raddb/clients.conf 文件设置的secret = xxxxxxxxxx 值一样。

配置完成后保存退出

重启radius、maridb、http服务
systemctl daemon-reload #重新加载守护进程
systemctl restart radiusd.service
systemctl restart mariadb.service
systemctl restart httpd
centos7.2安装radius服务器
这个报错我没有碰到,这个报错产生的原因是,上面重装php的时候卸载多了,只需要在安装的时候加入这个包就行了
cat /etc/httpd/logs/error_log #查看 http 服务的日志,发现有以下错误:

PHP Fatal error: Uncaught Error: Class 'DB' not found in /var/www/html/daloradius/library/opendb.php:86\nStack trace:\n#0 /var/www/html/daloradius/dologin.php(49): include()\n#1 {main}\n thrown in /var/www/html/daloradius/library/opendb.php on line 86

解决方法:yum -y install php-pear-DB
测试:daloradius界面
浏览器访问 http://192.168.0.238//daloradius
登录web界面
用户名: administrator
密码: radius
至此LAMP+FreeRadius+Daloradius Web管理界面已经安装成功,下面是Web界面汉化教程。
centos7.2安装radius服务器
五、Daloradius 中文版设置
下载文件zh.php;
链接: https://pan.baidu.com/s/1KAXHh9_inckAKv4_2s9OOA 提取码: bydk

将下载的zh.php文件放入/var/www/html/daloradius/lang目录

进入 /var/www/html/daloradius文件目录,修改config-lang.php,添加中文选项:
vim /var/www/html/daloradius/config-lang.php
centos7.2安装radius服务器
<option value="zh"> Simplified Chinese </option> (79行)

进入/var/www/html/daloradius/lang目录,修改main.php,增加简体中文文件
vim /var/www/html/daloradius/lang/main.php
centos7.2安装radius服务器
case "zh":
include (dirname(FILE)."/zh.php");
break;
重启radiusd服务
systemctl restart radiusd.service
systemctl restart httpd

登录网页http://192.168.0.238/daloradius/设置中文显示
点击Config -> Language Settings ->Simplified Chinese
centos7.2安装radius服务器
数据库中查看某些信息
查看用户列表
centos7.2安装radius服务器
更改管理员默认密码
centos7.2安装radius服务器

起初的想法是配合SoftEther Server 管理工具使用,结果SoftEther Server的开源版本,不支持radius和证书认证,企业版本也没有就记录一次吧
这三种方式都不支持,准备选择其他***,
centos7.2安装radius服务器

猜你喜欢

转载自blog.51cto.com/7794482/2488181