CEMNTOS6.x下Freeradius + Mysqsl配置服务端一键安装脚本

写在前面:

目前脚本存在几个问题:

1. mysql采用云安装

2. mysql的密码不能包含特殊字符(例如:‘$’ ‘/’ '\' 等  ),否则引发的脚本错误请 自行修改相关配置。如果有知道这个问题怎么修改的请留言告知,谢谢!!!

3.请自行到官网下载freeradius-server-2.2.6.tar.gz 与脚本放于同一个目录下,再执行脚本

4.本人在centos6.X下测试成功,再其他系统下请自行修改配置:

5.脚本中不含开放端口命令,请自行开放相关端口:1812,1813

脚本如下:

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install lnmp"
    exit 1
fi

clear
echo "========================================================================="
echo "freeradois + mysql V1.1 for CentOS/RadHat Linux Server, Written by Hot_VC"
echo "========================================================================="
echo "A tool to auto-compile & install freeradius+mysql  on Linux "
echo "========================================================================="
cur_dir=$(pwd)
echo "==========================="
isinstallmysql="n"
echo "Install MySQL 5.1.73,Please input y"
echo "Install MySQL 5.1.73,Please input n or press Enter"
echo "Is install Mysql"
read -p "(Please input y , n):" isinstallmysql

case "$isinstallmysql" in
	y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)
		echo "You will install MySQL"
		isinstallmysql="y"
		;;
	n|N|No|NO|no|nO)
		echo "You will  not install MySQL"
		isinstallmysql="n"
		;;
	*)
		echo "INPUT error,You will not install MySQL "
		isinstallmysql="n"
esac
echo "MySQL root password:$isinstallmysql"
#set mysql root password
echo "==========================="
mysqlrootpwd="root"
echo "Please input the root password of mysql:"
read -p "(Default password: root):" mysqlrootpwd
if [ "$mysqlrootpwd" = "" ]; then
	mysqlrootpwd="root"
fi

echo "==========================="
echo "MySQL root password:$mysqlrootpwd"
echo "==========================="
echo ""
echo ""
echo "==========================="
echo "Install Dependent Libraries "
echo "==========================="
yum -y install pam-devel openssl-devel make gcc gcc-c++ ncurses-devel libtool cmake bison-devel mysql-devel
echo "==========================="
echo "Install Dependent Libraries end"
echo "==========================="
echo ""
echo ""

echo "==========================="
echo "Install MySql"
echo "==========================="
echo ""
echo ""
if [ "$isinstallmysql" = "y" ]; then
	yum install -y mysql-server
else
	echo "MySQL will not install"
fi
echo ""
echo ""
echo "==========================="
echo "Install Mysql complete"
echo "==========================="
echo ""
echo ""
echo "==========================="
echo "Config Mysql "
echo "==========================="
echo ""
echo ""
service mysqld start
if [ "$isinstallmysql" = "y" ]; then
	mysqladmin -uroot password "$mysqlrootpwd"
fi
echo ""
echo ""
echo "==========================="
echo "Config Mysql complete"
echo "==========================="
echo ""
echo ""
echo "==========================="
echo "Install freeradius"
echo "==========================="
echo ""
echo ""
if [ -s freeradius-server-2.2.6.tar.gz ]; then
	tar zxf freeradius-server-2.2.6.tar.gz     
	cd freeradius-server-2.2.6
	./configure --prefix=/usr --sysconfdir=/etc 
	make && make install
	if [ $(getconf WORD_BIT) = '32' ] && [ $(getconf LONG_BIT) = '64' ] ; then
		echo "include /usr/lib" >> /etc/ld.so.conf
		ldconfig
	fi
	sed -i "s/allow_vulnerable_openssl = no/allow_vulnerable_openssl = yes/g" /etc/raddb/radiusd.conf

	#Troubleshooting:
	#rlm_sql (sql): Could not link driver rlm_sql_mysql: rlm_sql_mysql.so: cannot open shared object file: No such file or directory 
	cd src/modules/rlm_sql/drivers/rlm_sql_mysql/
	./configure --with-mysql-dir=/var/lib/mysql --with-mysql-lib-dir=/usr/lib64/mysql 
	make && make install
	cd ../../../../..
	cd ..
else 
	echo "Error: freeradius-server-2.2.6.tar.gz not found!!!please  chectout files"
fi

echo "==========================="
echo "Install freeradius complete"
echo "==========================="
echo ""
echo ""

#Mod /etc/raddb/radiusd.conf
sed -i "743s/#/ /g" /etc/raddb/radiusd.conf
sed -i "568s/no/yes/g" /etc/raddb/radiusd.conf
#Mod /etc/raddb/sql.conf
sed -i "38s/login = \"radius\"/login = \"root\"/g" /etc/raddb/sql.conf
sed -i "39d" /etc/raddb/sql.conf
sed -i "38a password = \"$mysqlrootpwd\"" /etc/raddb/sql.conf
sed -i "170s/files/#files/g" /etc/raddb/sites-enabled/default
sed -i "177s/#//g" /etc/raddb/sites-enabled/default
sed -i "372s/files/#files/g" /etc/raddb/sites-enabled/default
sed -i "406s/#//g" /etc/raddb/sites-enabled/default
sed -i "454s/#//g" /etc/raddb/sites-enabled/default
sed -i "475s/#//g" /etc/raddb/sites-enabled/default
sed -i "577s/#//g" /etc/raddb/sites-enabled/default


mysql -uroot -p$mysqlrootpwd <<EOF
create database radius;
EOF
mysql -uroot -p$mysqlrootpwd radius </etc/raddb/sql/mysql/schema.sql;
mysql -uroot -p$mysqlrootpwd radius </etc/raddb/sql/mysql/nas.sql;
mysql -uroot -p$mysqlrootpwd radius </etc/raddb/sql/mysql/ippool.sql;
mysql -uroot -p$mysqlrootpwd radius </etc/raddb/sql/mysql/cui.sql;
mysql -uroot -p$mysqlrootpwd radius </etc/raddb/sql/mysql/wimax.sql;
#Mod /etc/raddb/clients.conf
cat >>/etc/raddb/clients.conf <<EOF
client 0.0.0.0/0 {
        secret = $freeradiussecret
        shortname = remote
}
EOF
echo ""
echo ""
echo "==========================="
echo "Install freeradius complete"
echo "==========================="



测试是否成功:

进入mysql向radius库中的radcheck表插入数据:

INSERT INTO radcheck (username,attribute,op,VALUE) VALUES ('test','Cleartext-Password',':=','test');

然后启动radiusd

root@localhost auto-install]# radiusd

打开另一个窗口执行:

<pre name="code" class="html">[root@localhost auto-install]# radtest test test 127.0.0.1 1812 testing123
 
 

出现Access-Accept字样表示成功:

nding Access-Request of id 253 to 127.0.0.1 port 1812
User-Name = "test"
User-Password = "test"
NAS-IP-Address = 127.0.0.1
NAS-Port = 1812
Message-Authenticator = 0x00000000000000000000000000000000
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=253, length=20



你可能感兴趣的:(linux,shell,一键安装,freeradius)