Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2876891
  • 博文数量: 471
  • 博客积分: 10012
  • 博客等级: 上将
  • 技术积分: 5255
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-10 23:58
文章分类

全部博文(471)

文章存档

2011年(3)

2010年(61)

2009年(52)

2008年(212)

2007年(69)

2006年(74)

我的朋友

分类: LINUX

2010-05-20 11:30:55

centos5.4环境下openvpn+mysql+freeradius+daloradius+bigfish 的配置
山西 :左脑
   2010年元月奉献,我女儿出生快两个月了,在她的哭啼声中,完成了以下工作。做此工作主要是用来解决我校内网的资源通过VPN可以让外网用户访问。
   freeradius研究了一段时间,很好的东西,计划做完这个,用它来做数据整合的研究。
   

以下是我的总结:(大部分不是原创,只是在前辈的基础上加以总结和修改,阿涛的文章我引用了很多,希望不要介意)

一、软件准备:(centos5.4系统的安装按照以下步骤做,其他软件在这里只是做一个介绍,不用下载,下面的安装里会介绍)
centos5.4:(网络安装,采用net-install光盘)(安装时只安装必要的软件,我只选择了BASE)
          1、将光盘放入光驱,引导系统)出现安装界面后输入,linux text
          2、安装方式采用HTTP
          3、配置你的网卡地址
          4、地址:mirrors.sohu.com
          5、文件位置centos/5.4/os/i386   
          6、开始安装(由于是网络安装,期间视网络速度,需要等待时间)
          7、接下来就是安装一般方式安装(大家应该都会,不会就别玩LINUX了)
openvpn : openvpn-2.0.9.tar.gz
mysql:系统自带的通过yum 安装(不要着急,后面我们还要升级成最新版)
freeradius:freeradius-1.1.7.tar.gz
daloradius:daloradius-0.9-8.tar.gz(一个非常优秀的radius WEB管理程序)
LZO:lzo-2.02.tar.gz(支持openvpn的压缩功能)
RadiusPlugin:radiusplugin_v2.0b_beta2.tar.gz (freeradius插件)

二、
1、更新系统内核到最新.
yum -y update
系统更新后,如果yum安装时提示错误信息,请执行以下命令修复.
rpm –import  /etc/pki/rpm-gpg/RPM-GPG-KEY*
2、安装必要的编译环境
(安装GCC编译环境) yum install gcc
  (安装GCC++编译环境)yum install gcc-c++
3、 安装Apahce, PHP, Mysql, 以及php连接mysql库组件

yum -y install httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-mcrypt php-gd
php-xml php-mbstring php-ldap php-pear php-xmlrpc mysql-connector-odbc mysql-devel libdbi-dbd-mysql

4、mysqladmin -u root password ‘新密码’ [引号内填密码]
5、这里参考《阿涛的博客》安装freeradius
(1)、编译安装freeradius
下载文件包:
wget
解压文件包:
tar zxvf freeradius-1.1.7.tar.gz
cd freeradius-1.1.7
编译文件包:
./configure
cp libltdl/ltdl.h src/include/
make
make install
注释:如果没有cp libltdl/ltdl.h src/include/ 在make的时候会有2个错误,应该是路径的问题

(2)、
vi /etc/ld.so.conf
加入以下:
/usr/local/lib
ldconfig

(3)、构建radius数据库(建立相关用户和密码)
  mysql –uroot –p
  创建radius数据库:
  mysql>create database radius;
  mysql>GRANT ALL PRIVILEGES ON radius.* TO radius@localhost IDENTIFIED BY 'radius的密码';
  mysql>\q

  cd /usr/local/src/freeradius-1.1.7

  导入数据库:
  /usr/local/mysql/bin/mysql -uroot -pXXXX radius < ./doc/examples/mysql.sql

(4)、配置radiusd.conf以及sql.conf
   vi /usr/local/etc/raddb/radiusd.conf
   proxy_requests = no
  authorize {
   preprocess
   chap
   mschap
   suffix
   eap
   sql
#      pap
#      files
}
注释:使用sql,authorize中的file必须被注释掉。

preacct {
        preprocess
        acct_unique
        suffix
#       files
}


accounting {
      detail
      unix
      radutmp
      sql
}      

(5)sql.conf配置
vi /usr/local/etc/raddb/sql.conf
driver = "rlm_sql_mysql"
server = "localhost"
login = "radius"
password = "radius密码"
radius_db = "radius"
配置NAS信息:
vi /usr/local/etc/raddb/clients.conf
#本地帐号,用于测试
client 127.0.0.1 {
        secret          = testing123
        shortname       = localhost
        nastype         = other
}
注释:
secret 这里是针对client 127.0.0.1通讯密匙
#mysql -u root -p
mysql> use radius;

建立组信息:
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Auth-Type',':=','Local');
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Service-Type',':=','Framed-User');
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Framed-IP-

Address',':=','255.255.255.255');
mysql> insert into radgroupreply (groupname,attribute,op,value) values ('user','Framed-IP-

Netmask',':=','255.255.255.0');
建立用户信息:
mysql> insert into radcheck (username,attribute,op,value) values ('test','User-Password',':=','test');
mysql> insert into radcheck (username,attribute,op,value) values ('sense','User-Password',':=','123456');
将用户加入组中:
mysql> insert into usergroup (username,groupname) values ('test','user');

(6)、测试radius

  radiusd –x &
这个时候控制台会被占用

另开一个控制台进行测试
ln -s /usr/local/bin/radtest /sbin/radtest

/sbin/radtest test test localhost 0 testing123

如显示以下内容说明freeradius-mysql工作正常:
Sending Access-Request of id 204 to 127.0.0.1 port 1812
        User-Name = "test"
        User-Password = "test"
        NAS-IP-Address = 255.255.255.255
        NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=204, length=38
        Service-Type = Framed-User
        Framed-IP-Address = 255.255.255.255
        Framed-IP-Netmask = 255.255.255.0

如显示以下内容说明freeradius-mysql工作正常:
/sbin/radtest sense 123456 localhost 0 testing123
Sending Access-Request of id 212 to 127.0.0.1 port 1812
        User-Name = "sense"
        User-Password = "123456"
        NAS-IP-Address = 255.255.255.255
        NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=212, length=20
由于test加入了组所以信息量多一点

以上测试说明freeradius-mysql工作正常!
说明(freeradius\rlm_sql_mysql.so\mysql\)正常!

6、安装openvpn及lzo
(1)、lzo
wget
tar zxvf lzo-2.02.tar.gz
cd lzo-2.02
./configure
make
make install
这一部分是支持openvpn的压缩功能

(2)、openvpn

查看是否安装必要的软件,如没有请通过YUM 安装
rpm -aq|grep openssl
openssl-devel-0.9.8b-8.3.el5
openssl-0.9.8b-8.3.el5
cd /usr/local/src

下载软件包
wget

解压软件包
tar zxvf openvpn-2.0.9.tar.gz
cd openvpn-2.0.9

编译软件包:
./configure --prefix=/usr/local/openvpn --with-lzo-headers=/usr/local/include/lzo \
--with-lzo-lib=/usr/local/lib --with-ssl-headers=/usr/include/openssl \
--with-ssl-lib=/usr/lib
make
make install

(3)、生成密匙
cd /usr/local/src/openvpn-2.0.9
cp -rf ./easy-rsa/ /usr/local/openvpn/
cd /usr/local/openvpn/easy-rsa/2.0
source ./vars
./clean-all
./build-ca
./build-key-server server
./build-dh
./build-key cl1
cd keys
/usr/local/openvpn/sbin/openvpn --genkey --secret ta.key
cd /usr/local/openvpn
mkdir ssl
cp -a ./easy-rsa/2.0/keys/ca.crt ./ssl/
cp -a ./easy-rsa/2.0/keys/dh1024.pem ./ssl/
cp -a ./easy-rsa/2.0/keys/ta.key ./ssl/
cp -a ./easy-rsa/2.0/keys/server.crt ./ssl/
cp -a ./easy-rsa/2.0/keys/server.key ./ssl/

7、安装RadiusPlugin
(1)、安装
cd /usr/local/src/
wget wget
tar zxvf radiusplugin_v2.0b_beta2.tar.gz
cd radiusplugin_v2.0b_beta2
make

cp /usr/local/src/radiusplugin_v2.0b_beta2/radiusplugin.so /usr/local/openvpn/
cp /usr/local/src/radiusplugin_v2.0b_beta2/radiusplugin.cnf /usr/local/openvpn/
vi /usr/local/openvpn/radiusplugin.cnf
(2)、配置radiusplusin插件的配置文件radiusplugin.cnf

# The NAS identifier which is sent to the RADIUS server
NAS-Identifier=OpenVpn
# The service type which is sent to the RADIUS server
Service-Type=5
# The framed protocol which is sent to the RADIUS server
Framed-Protocol=1
# The NAS port type which is sent to the RADIUS server
NAS-Port-Type=5
# The NAS IP address which is sent to the RADIUS server
NAS-IP-Address=127.0.0.1
# Path to the OpenVPN configfile. The plugin searches there for
# client-config-dir PATH   (searches for the path)
# status FILE                      (searches for the file, version must be 1)
# client-cert-not-required (if the option is used or not)
# username-as-common-name (if the option is used or not)

OpenVPNConfig=/usr/local/openvpn/server.conf   (OPENVPN的安装位置)

# Support for topology option in OpenVPN 2.1
# If you don't specify anything, option "net30" (default in OpenVPN) is used.
# You can only use one of the options at the same time.
# If you use topology option "subnet", fill in the right netmask, e.g. from OpenVPN option "--server NETWORK

NETMASK"
#subnet=255.255.255.0
# If you use topology option "p2p", fill in the right network, e.g. from OpenVPN option "--server NETWORK NETMASK"
#p2p=10.10.0.1
####################### Ich benutze die Default Option

# Allows the plugin to overwrite the client config in client config file directory,
# default is true
overwriteccfiles=true

# Path to a script for vendor specific attributes.
# Leave it out if you don't use an own script.
# vsascript=/root/workspace/radiusplugin_v2.0.5_beta/vsascript.pl

# Path to the pipe for communication with the vsascript.
# Leave it out if you don't use an own script.
# vsanamedpipe=/tmp/vsapipe

# A radius server definition, there could be more than one.
# The priority of the server depends on the order in this file. The first one has the highest priority.
server
{
        # The UDP port for radius accounting.
        acctport=1813
        # The UDP port for radius authentication.
        authport=1812
        # The name or ip address of the radius server.
        name=127.0.0.1
        # How many times should the plugin send the if there is no response?
        retry=1
        # How long should the plugin wait for a response?
        wait=1
        # The shared secret.
        sharedsecret= testing123
}

注释:这里的sharedsecret= testing123跟radiusd的设置相关,注意/usr/local/etc/raddb/clients.conf中的client 127.0.0.1

的设置,(这个clients.conf是调用radius的客户端配置)
client 127.0.0.1 {
    secret = testing123
       shortname = localhost
    nastype = other
}
同时重要的是要在正式应用的时候 同时修改这2个地方的testing123,这个就是radius的密匙

(3)、配置openvpn的服务器设置文件server.conf
cp /usr/local/src/openvpn-2.0.9/sample-config-files/server.conf /usr/local/openvpn/server.conf
vi /usr/local/openvpn/server.conf

注释:注意这里的server.conf要与/usr/local/openvpn/radiusplugin.cnf中OpenVPNConfig的设置一致
这里的openvpn服务器端可以有多个配置文件,每一个配置等于开启了一个单独的vpn服务,但是要单独设置每个服务器端配置文

件./build-key-server ser*** 同时不同的客户端./build-key cl1*** 对应于相应 ser****的unit name,同时客户端要拷贝不同的

ser***.crt

注意这里的通讯协议和OPENVPN-GUI得通讯协议要一致(proto udp)

port 1194   
proto udp
# Which device
dev tun
user nobody
group nogroup
persist-tun
persist-key
server 100.100.0.0 255.255.0.0
float
username-as-common-name
client-cert-not-required
client-to-client
ping-timer-rem
keepalive 10 120
comp-lzo
tls-server
tls-auth ssl/ta.key 0
dh ssl/dh1024.pem
ca ssl/ca.crt
cert ssl/server.crt
key ssl/server.key
max-clients 200
plugin /usr/local/openvpn/radiusplugin.so /usr/local/openvpn/radiusplugin.cnf
verb 3
mute 10
status /var/log/openvpn/status.log 1
log /var/log/openvpn/openvpn.log
  
(4)、建两个文件
   mkdir /usr/local/openvpn/ccd
   mkdir /var/log/openvpn
  
(5)、创建用户组
         groupadd nogroup
  
(6)、创建用户
          useradd nobody(是阿涛文章中没有提到的,所以大部分人在启动OPENVPN时要报错)
   
(7)、建立openvpn的shell执行脚本
       cp /usr/local/src/openvpn-2.0.9/sample-scripts/openvpn.init /etc/init.d/
       ln -s /usr/local/openvpn/sbin/openvpn /usr/sbin/openvpn
       vi /etc/init.d/openvpn.init
       修改:work=/usr/local/openvpn
(8)、启动openvpn
      /etc/init.d/openvpn.init start
       这个时候要看一下 ifconfig 有没有 tun0设备,如果有就基本ok了!

8、windows下client.opvn客户端配置文件:(这里需要做个补充,您需要把ca.key、ca.crt、ta.key下载到客户端OPENVPN安装目录下的CONFIG下)

注意这里的通讯协议和SERVER端的通讯协议要一致(proto udp)

client
;dev tap
dev tun
proto udp
remote 192.168.0.100 1194
;remote my-server-2 1194
remote-random
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
auth-user-pass
ns-cert-type server
tls-auth ta.key 1
route 0.0.0.0 0.0.0.0  //(这里根据自己的实际情况设置,意思就是你要让什么网段的数据包通过VPN)
comp-lzo
verb 3
mute 10

9、用SETUP 设置开机启动服务 httpd、mysqld

10、在/etc/rc.d/rc.local
   
添加(让radius和OPENVPN开机启动):
     /usr/local/sbin/radiusd -x &
     /usr/sbin/openvpn

11、升级MYSQL、php(这步是为后面安装Daloradius 做准备,应为Daloradius 需要的插件比较多,通过YUM升级方便一些)
     rpm --import
      
      # /etc/yum.repos.d/utterramblings.repo

把以下内容添加进去,保存退出就OK了

[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=
enabled=1
gpgcheck=1
gpgkey=
yum update php*
yum update mysql*
yum install php-pear-DB
yum install php-mcrypt
yum install php-mbstring

12、重新启动计算机

13、安裝 Daloradius
   wget
   #tar zxvf daloradius-0.9-8.tar.gz
   #cp -R daloradius-0.9-8 /var/www
   设定 Daloradius
   #chown -R apache:apache /var/www/daloradius-0.9-8
   #chmod 644 /var/www/daloradius-0.9-8/library/daloradius.conf.php
   
   在radius数据库中加入daloradius的表.
   #mysql -u root -p radius < /var/www/daloradius-0.9-8/contrib/db/mysql-daloradius.sql

    设定 daloradius.conf.php
    #vi /var/www/daloradius-0.9-8/library/daloradius.conf
    $configValues['FREERADIUS_VERSION'] = '1';
    $configValues['CONFIG_DB_ENGINE'] = 'mysql';
    $configValues['CONFIG_DB_HOST'] = '127.0.0.1';
    $configValues['CONFIG_DB_USER'] = 'radius';    --> radius用户名
    $configValues['CONFIG_DB_PASS'] = 'radpass';   --> radius密码
    $configValues['CONFIG_DB_NAME'] = 'radius';    --> radius数据库
     
  在apache2 加虚拟目录( Alias )

   #vi /etc/apache2/apache2.conf

在apache2.conf 中加入以下.
==================================================================
  Alias /myradius "/var/www/daloradius-0.9-8/"
   
      Options None
      order deny,allow   
      allow from all

重新启动HTTPD:service httpd restart   

用戶: administrator
密碼: radius

14、关于IPTABLES的配置网上有很多教程,大家可以参考,在这里不再阐述
总结:说实话我按照网上的教程搞了3天,总是不行,最后只能自己分析原理来配置,如阿涛一文中的OPENVPN的启动,就是因为没有nogroup组而启动失败,在安装Daloradius时老提示没有DB.PHP,其实是没有安装php-pear-DB这个包。

本文觉大部分是总结或者是摘录了前辈们的东西,只是自己整理了一下,供各位像我一样的菜鸟参考。

如有疑问可以Q我:19935284  注明:OPENVPN   
接下来的工作:
    1、计划重新编译定制OPENVPN客户端(等出来了我把工程文件共享出来)
    2、目前正在进行的工作是:汉化Daloradius(等完工一定给大家共享)

做个补充:
关于IPTABLES的管理与设置可以用基于WEB的开源IPTABLES WEB管理软件bigfish
里面有安装文档,大家可以自己看,很简单
阅读(5724) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~