一、CentOS系统设置和LAMP
1.安装系统并设置源
1、#首先备份/etc/yum.repos.d/CentOS-Base.repo
mv/etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、#下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
rpm -Uvh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-6.noarch.rpm
#安装所需软件包
yum -y installhttpd mysql mysql-devel mysql-server php php-mysql php-gd php-imap php-odbcphp-pear php-xml php-xmlrpc
yum -y installgcc gcc-c++ autoconf libjpeg libjpeg-devel libpnglibpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-develglibc glibc-devel glib2 glib2-devel bzip2bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-develkrb5 krb5-devel libidn libidn-devel openssl openssl-devel
##############################################
sed -i "s/^SELINUX=*/SELINUX=disabled/g"/etc/selinux/config #修改selinux的配置文件,禁用selinux
setenforce 0 #关闭selinux
chkconfig httpd on #将http设置为永久开启
chkconfig mysql on #将mysql设置为永久开启
/etc/init.d/httpd start #启动http
/etc/init.d/mysqld start #启动mysql
mysqladmin -u root password jjker1314 #设置mysql的root密码为jjker1314
iptables -F #清楚防火墙规则
vi /var/www/html/test.php #建立php测试文件,输入一下内容
<?php
phpinfo();
?>
#保存退出
二、安装raidus,并配置mysql验证
yum install -y freeradius freeradius-mysql freeradius-utils #安装radius
vi /etc/raddb/users #配置本地用户测试radius
testuser Cleartext-Password := "testpassword" #在文件的最后一行加入 ,保存退出
/etc/init.d/radiusd restart #重启radius服务
radtest testuser testpassword localhost 1812 testing123 #测试radius服务器的配置,如果看到下面内容,说明服务器配置成功
[ Sending Access-Request of id 176 to 127.0.0.1 port 1812
User-Name = "testuser"
User-Password = "testpassword"
NAS-IP-Address = 127.0.0.1
NAS-Port = 1812
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=176, length=20 ]
#为radius配置mysql验证
cp /etc/raddb/clients.conf /etc/raddb/clients.conf.bak #备份radius的客户端配置文件
grep -v \# /etc/raddb/clients.conf.bak > /etc/raddb/clients.conf #将clients.conf.bak 中的注释行过滤掉,并输出到clients.conf中
vi /etc/raddb/clients.conf #编辑客户端文件,内容如下
client 0.0.0.0 {
ipaddr = 127.0.0.1
secret = testing123
shortname = localhost
}
vi /etc/raddb/users #编辑用户文件,注释掉刚才添加的测试用户
# testuser Cleartext-Password := "testpassword" #将该测试用户注释掉
cp /etc/raddb/sql/mysql/admin.sql /etc/raddb/sql/mysql/admin.sql.bak #备份admin.sql文件
grep -v ^# /etc/raddb/sql/mysql/admin.sql.bak > /etc/raddb/sql/mysql/admin.sql #将admin.sql.bak 中的注释行过滤掉并输出到admin.sql中
vi /etc/raddb/sql/mysql/admin.sql #修改admin.sql文件,内容如下
CREATE USER 'radius'@'localhost';
SET PASSWORD FOR 'radius'@'localhost' = PASSWORD('radpass');
GRANT ALL ON radius.* TO 'radius'@'localhost';
#以上内说明“ 数据库为radius,密码为radpass”如果要自己设置,设置完成后还要修改sql.conf把密码改为自己设置的
{ # vi /etc/raddb/sql.conf
#找到
#login = "radius" ---> 登录用户名,可以在这里修改登录radius数据库的用户名
#password = "radpass" --->登录用户密码 ,可以在这里修改登录radius数据库的密码 }
#导入radius数据库
mysql -u root -p #登录mysql数据库,输入之前设置的root密码,就可以登录mysql了
create database radius; #创建radius表
exit #退出mysql数据库
mysql -u root -pradius </etc/raddb/sql/mysql/admin.sql #输入这行的时候,有可能会出现“
ERROR 1396 (HY000) at line 2: Operation CREATE USER failed for 'radius'@'localhost'
”,这个表示radius帐号已经存在,可以不用理会
mysql -u root -pradius </etc/raddb/sql/mysql/schema.sql #导入schema.sql 文件
mysql -u root -pradius </etc/raddb/sql/mysql/nas.sql #导入nas.sql文件
mysql -u root -pradius </etc/raddb/sql/mysql/ippool.sql #导入ippool.sql文件
mysql -u root -p #登录mysql数据库,输入之前设置的root密码,就可以登录mysql了
flush privileges; #使刚才导入的配置生效
vi /etc/raddb/radiusd.conf #编辑radius配置文件,使其使用sql认证,去掉前面的#号
$INCLUDE sql.conf
修改sql.conf,只修改下面的内容
server = "localhost"
port = 3306
login = "radius"
password = "radpass"
radius_db = "radius"
readclients = yes
#修改认证的方式
vi /etc/raddb/sites-enabled/default #编辑radius默认的认证文件
# authorize { --->找到这一行,将其注释掉,并把结束的“}”也注释掉
# }
# accounting { ---->找到这一行,将其注释掉,并把结束的“}”也注释掉
#}
#session { ---->找到这一行,将其注释掉,并把结束的“}”也注释掉
#}
#然后到文件的末尾添加如下内容,保存退出
authorize {
preprocess
chap
mschap
suffix
eap
sql
pap }
accounting {
detail
sql }
session {
radutmp
sql }
#插入测试数据
mysql -u root -p #登录mysql数据库
useradius; #使用radius库
INSERT INTO radcheck (UserName,Attribute, Value) VALUES ('user1', 'Password','password1'); #插入测试帐号“user1”和“password1”
exit #退出mysql数据库
/etc/init.d/radiusdrestart #重启radius服务
radtest user1 password1 localhost 1812 testing123 #用测试帐号测试一下radius的mysql认证是否成功,如果看到下图的内容,则说明已经配置成功了
Sending Access-Request of id 134 to 127.0.0.1 port 1812
User-Name = "user1"
User-Password = "password1"
NAS-IP-Address = 127.0.0.1
NAS-Port = 1812
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=134, length=20
三、安装openvpn
yum install-yopenvpn #安装openvpn软件包
cp -R /usr/share/openvpn/easy-rsa/ /etc/openvpn/ #将easy-rsa下的全部文件复制到openvpn下
cd /etc/openvpn/easy-rsa/2.0/ #进入证书目录,编辑vars文件,在文件的末尾修改自己的信息如下图
export KEY_COUNTRY="CN"
export KEY_PROVINCE="CN"
export KEY_CITY="ShangHai"
export KEY_ORG="ShangHai"
export KEY_EMAIL="lixiaoyu@iwgame.com"
export KEY_EMAIL=lixiaoyu@iwgame.com
export KEY_CN=changeme
export KEY_NAME=changeme
export KEY_OU=changeme
export PKCS11_MODULE_PATH=changeme
export PKCS11_PIN=1234
source ./vars #指定编译源
./clean-all #清理一下
./build-ca ca #生成CA证书,一路回车就行
./build-key-server server #生成server.key,一路回车直到最后两项,按“Y”确认
./build-dh #生成Diffie Hellman参数
openvpn --genkey --secret keys/ta.key #生成一个tls验证key
#####以上生成的文件都放在/etc/openvpn/easy-rsa/2.0/keys/,记住,我们等会会用到这个路径###########
安装radiusplugin
{radiusplugin是radius的一个插件,可以让openvpn使用radius服务器来验证}
yum install-y libgcrypt libgpg-error libgcrypt-devel #安装所需软件包
wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1.tar.gz #下载radiusplugin的tar包
yum -y installgcc-g++ #重新安装gcc-g++
yum -y insatllcompat-libstdc* #安装compat-libstdc*
tar zxf radiusplugin_v2.1.tar.gz #解压
cd radiusplugin #进入radiusplugin目录
make #执行make安装命令
cp radiusplugin.so /etc/openpnvpn #复制radiusplugin.so 文件到/etc/openvpn文件夹下
cp radiusplugin.cnf /etc/openvpn #复制radiusplugin.so 文件到/etc/openvpn文件夹下
vi /etc/openvpn/radiusplugin.cnf #编辑radiusplugin.cnf,找到server区域,更改内容如下,编辑好后保存退出
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
}
配置OPENVPN
\cp /usr/share/doc/openvpn-2.2.1/sample-config-files/server.conf /etc/openvpn/ #复制样本server.conf到/etc/openvpn下面
grep -v ^# /usr/share/doc/openvpn-2.2.1/sample-config-files/server.conf > /etc/openvpn/server.conf #将server.conf文件里面的注释行取消
vi /etc/openvpn/server.conf #清空server.conf的内容,写入一下内容
port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt #指定ca证书的位置
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt #指定server.crt的位置
key /etc/openvpn/easy-rsa/2.0/keys/server.key #指定server.key的位置
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem #指定dh的位置
tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0 #指定tls密钥的位置
client-config-dir /etc/raddb/clients.conf
server10.8.0.0 255.255.255.0
push "redirect-gatewaydef1"
push "dhcp-optionDNS 8.8.8.8"
push "dhcp-optionDNS 8.8.4.4"
push "dhcp-optionDNS 10.8.0.1"
client-to-client
keepalive 10120
comp-lzo
persist-key
persist-tun
client-cert-not-required
username-as-common-name
plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf#这里是指定radiusplugin.so这个插件
log /var/log/openvpn.log #log 日志存放目录
status /var/log/openvpn-status.log #日志存放目录
# Verbosity level.
# 0 -- quiet except for fatal errors.
# 1 -- mostly quiet, but display non-fatal networkerrors.
# 3 -- medium output, good for normal operation.
# 9 -- verbose, good for troubleshooting
#日志级别 verb 3
verb 3
vi /etc/sysctl.conf #更改系统参数,将net.ipv4.ip_forward = 0修改为net.ipv4.ip_forward = 1
sysctl -p #使其立即生效,有报错不用管
更改防火墙策略
vi /etc/sysconfig/iptables
# iptables -APOSTROUTING -s 10.8.0.0/24-o eth0 -j SNAT --to-source 192.168.1.2 #设置NAT “192.168.1.2为本机IP”
iptables -A INPUT -p udp-m udp --dport1194-jACCEPT
iptables -A INPUT -p tcp-m tcp --dport22-jACCEPT
iptables -A INPUT -p tcp-m tcp --dport80-jACCEPT
iptables -A INPUT -itun0 -j ACCEPT
iptables -A INPUT -itun0 -j ACCEPT
iptables -A FORWARD -itun0 -j ACCEPT
iptables -A OUTPUT -otun0 -j ACCEPT
service iptables save #保存防火墙策略
service iptables restart # 重启防火墙
chkconfig openvpn on #永久开启openvpn
service openvpn start # 重启openvpn
安装daloradius
wget http://download.pear.php.net/package/DB-1.7.14RC2.tgz #下载软件包
pear install DB-1.7.14RC2.tgz #安装软件包
wget http://nchc.dl.sourceforge.net/project/daloradius/daloradius/daloradius0.9-9/daloradius-0.9-9.tar.gz #下载软件包
tar-zxvf daloradius-0.9-9.tar.gz #安装软件包
mvdaloradius-0.9-9daloradius #将文件daloraidus-0.9-9重命名
cp-rf daloradius/*/var/www/html/ #复制daloradius/*所有文件到html下
chown apache:apache -R /var/www/html/ #将html文件夹极其下面的所有文件设置为apache组和apache用户所拥有
chmod 644/var/www/html/library/daloradius.conf.php #将daloraidus.conf.php文件的权限设置为rw-r--r--
cd /var/www/html/contrib/db/ #进入/var/www/html/contrib/db/目录
mysql -u root -p radius < mysql-daloradius.sql #将mysql-daloradius.sql 导入到mqsql中radius数据库中
vi /var/www/html/library/daloradius.conf.php #修改daloradius.conf.php ,将以下涉及到的内容更改,其他的别动
$configValues['DALORADIUS_VERSION'] = '0.9-9';
$configValues['FREERADIUS_VERSION'] = '2';
$configValues['CONFIG_DB_ENGINE'] = 'mysql';
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_USER'] = 'radius';
$configValues['CONFIG_DB_PASS'] = 'radpass';
$configValues['CONFIG_DB_NAME'] = 'radius';
$configValues['CONFIG_DB_TBL_RADCHECK'] = 'radcheck';
$configValues['CONFIG_DB_TBL_RADREPLY'] = 'radreply';
$configValues['CONFIG_DB_TBL_RADGROUPREPLY'] = 'radgroupreply';
$configValues['CONFIG_DB_TBL_RADGROUPCHECK'] = 'radgroupcheck';
$configValues['CONFIG_DB_TBL_RADUSERGROUP'] = 'radusergroup';
$configValues['CONFIG_DB_TBL_RADNAS'] = 'nas';
$configValues['CONFIG_DB_TBL_RADPOSTAUTH'] = 'radpostauth';
$configValues['CONFIG_DB_TBL_RADACCT'] = 'radacct';
#保存退出
touch /tmp/daloradius.log #建立daloraidus的日志文件
chown apache.apache /tmp/daloradius.log #将其文件设置为apache组及apache用户拥有
安装完后打开Http://xxx.xxx.xxx.xxx就可以看到daloradius了,登录的用户名密码为
username: administrator
password: radius
#client端设置
#下载http://swupdate.openvpn.org/community/releases/openvpn-2.2.1-install.exe
#在安装目录下有个config目录,
#将服务器上的ca.crt,ca.key,ta.key三个文件复制到config下。
#新建一个文本文件,输入以下内容。
client
dev tun
proto udp
remote 192.168.1.2 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-auth ta.key 1 ns-cert-type server
comp-lzo
verb 3
auth-user-pass
# 保存为client.ovpn,remote为你的openvpn服务器外网ip,端口1194
#设置运行openvpn-gui,在左面右下角,右键点击,connect,就可以连接到openvpn服务器了