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服務器

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章