9月 26

centos安装node.js简单测试

操作系统

Centos 5.4 Linux 2.6.18-164.el5 4G内存、Xeon(TM) CPU 3.20GHz

node-v0.5.7

node的官方网站http://nodejs.org/ 使用官方网站示例。

再安装前请将开发工具(tcl-developenssl-develglibc-devel bzip2*等)安装,可以使用yum工具。

安装

# tar zxvf node-v0.5.7.tar.gz

# cd node-v0.5.7

# ./configure

# make

有报make: [all] Error 1 (ignored) 但是没有找到问题,忽略了直接做下一步。

# make install

收到安装成功讯息。

建立一个node.js档案。

vim node.js

var http = require(‘http’);

http.createServer(function (req, res) {

res.writeHead(200, {‘Content-Type’: ‘text/plain’});

res.end(‘Hello Node.jsn‘);

}).listen(8124, “192.168.1.200”);

console.log(‘Server running at http://192.168.1.200:8124/’);

执行node.js

# node node.js

打开浏览器使用连接http:// 192.168.1.200:8124看到Hello Node.js,就表示node.js已经正在运作中。

进行个简单测试,使用apacheab工具

命令# ./ab -c10000 -n 40000 http:// 192.168.1.200:8124/

Complete requests: 40000

并发数: 3498.75 [#/sec]

平均返回相应时间: 0.286 [ms]

传输量: 266.51 [Kbytes/sec]

无请求失败。

在同一台机器上使用django写个,测试一下。

环境Python 2.6.6 django 1.3.0 关闭debug状态

代码为:

#!/bin/evn python

from django.http import HttpResponse

def index(request):

html = “Hello Djangon”

return HttpResponse(html)

直接使用python自带的调试服务器

# python manage.py runserver 192.168.1.200:9000

因为4000030000时将服务器跑死了(报错apr_socket_recv: Connection timed out (110)),所以修改为25000进行测试,结果也死了,改20000也死了,直接改15000也死了。算了我不测了。

总结:初步看node js效率确实很高,python+django自带的服务器的效

9月 07

测试mydumper导出效果

网上介绍mydumper可以同时备份多个table,导出速度比较mysqldump快,今天测试一下。

首先升级模块

yum install glib2-devel mysql-devel zlib-devel pcre-devel

还需要安装cmake

# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz

# tar zxvf cmake-2.8.5.tar.gz

# cd cmake-2.8.5

# ./configure && make && make install

开始安装工具

# wget http://launchpad.net/mydumper/0.2/0.2.3/+download/mydumper-0.2.3.tar.gz

# tar zxvf mydumper-0.2.3.tar.gz

# cd mydumper-0.2.3

# cmake .
# make
# make install

有两个工具

备份工具:mydumper

恢复工具:myloader

使用mydumper导出测试

# time mydumper -u root -p test -h 127.0.0.1 -P 3306 -B test -S /tmp/mysql.sock -o /tmp/mysql

real 2m11.954s

user 0m20.359s

sys 0m11.472s

使用mydump导出测试

# time mysqldump -u root -p -h 127.0.0.1 -P 3306 test>/tmp/test.sql

Enter password:

real 3m0.272s

user 0m47.459s

sys 0m16.837s

初步看导出速度提高的并不是很大。

3月 16

linux 系统数据恢复

[整理人:张子萌 2011-03-14]

linux管理员不小心rm了数据,会很郁闷,所以需要数据恢复。我记录个人的恢复实验结果。如果可以把硬盘拿下里挂载windows上可以试试Raise Data Recovery for Ext2/Ext3/Ext4、r-linux工具,其它工具也很多,但是收费的居多。用windows恢复后容易造成使用权限错误等问题,所以不能直接恢复到linux盘上使用。据说winpe里也可以用,但是我没有做实验,毕竟用winpe在服务器上也挺怪的。主要实验一下在linux上实际操作。TestDisk、PhotoRec、ext3grep。TestDisk主要用来恢复损坏的分区以及拯救无法引导的磁盘。PhotoRec 主要用于恢复损坏的数据文件和文档等。Ext3grep恢复大部分数据文件。

PhotoRec 下载地址

http://www.cgsecurity.org/wiki/PhotoRec

ext3grep下载地址

http://ext3grep.googlecode.com/files/ext3grep-0.10.2.tar.gz

软件主站

http://www.xs4all.nl/~carlo17/howto/undelete_ext3.html

先看ext3grep效果,我的分区如下

linux 系统数据恢复 - simon-zzm - simon个人观点

在program下随便放了一个文档pdf。并且见了3个目录abc,在a目录下放了一个txt文件。

# rm -rf 2011.pdf a/

把a目录和2011.pdf删除,删除完毕卸载/program分区,准备测试恢复。

首先安装或升级一下e2fsprogs、e2fslibs库,在CentOS中安装e2fsprogs库。如果是Ubuntu需要安装两个库,命令sudo apt-get install e2fsprogs e2fslibs-dev。我的实验环境是Centos。(任何恢复都需要安装此库)

#yum install –y e2fsprogs

# wget http://ext3grep.googlecode.com/files/ext3grep-0.10.2.tar.gz

# tar zxvf ext3grep-0.10.2.tar.gz

# cd ext3grep-0.10.2

# ./configure

# make && make install

ext3grep主要参数:

–print 打印块、inode和所有信息

–ls 打印目录、过滤信息

–inode 从某个indoechazhao

–block 从某个块查找

–group 只找某个组

–after 找在某点时间后删除的数据

–before 找在某点时间前删除的数据

–restore-file 恢复文件到某个目录

–restore-all 恢复所有删除,删除的数据会在当前的RESTORED_FILES目录中

开始从第二个inode扫描删除的文件

# ext3grep /dev/sda4 –ls –inode 2

扫描完成如下图

linux 系统数据恢复 - simon-zzm - simon个人观点

在第四列为inode值,第五列中写有D的就是被删除的文件。

使用一下命令我看看a目录下有什么东西,a目录的inode值为75777

# # ext3grep /dev/sda4 –ls –deteled –inode 75777

linux 系统数据恢复 - simon-zzm - simon个人观点

# ext3grep /dev/sda4 –restore-file a/123.txt

linux 系统数据恢复 - simon-zzm - simon个人观点

看到Restoring 已经恢复成功,查看123.txt文件文件内容没有问题,但是pdf的没有成功,不知道为什么。又测试删除mysql数据库的数据,经过恢复的数据也可以使用。总体说效果挺好。

然后试试PhotoRec,官方说明能恢复格式如下:

– RIFF audio/video (.avi/.wav)

– BMP bitmap (.bmp)

– bzip2 compressed data (.bz2)

– Source code written in C (.c)

– Canon Raw picture (.crw)

– Canon catalog (.ctg)

– FAT subdirectory

– Microsoft Office Document (.doc)

– Nikon dsc (.dsc)

– HTML page (.html)

– JPEG picture (.jpg)

– MOV video (.mov)

– MP3 audio (MPEG ADTS, layer III, v1) (.mp3)

– Moving Picture Experts Group video (.mpg)

– Minolta Raw picture (.mrw)

– Olympus Raw Format picture (.orf)

– Portable Document Format (.pdf)

– Perl script (.pl)

– Portable Network Graphics (.png)

– Raw Fujifilm picture (.raf)

– Contax picture (.raw)

– Rollei picture (.rdc)

– Rich Text Format (.rtf)

– Shell script (.sh)

– Tar archive (.tar )

– Tag Image File Format (.tiff)

– Microsoft ASF (.wma)

– Sigma/Foveon X3 raw picture (.x3f)

– zip archive (.zip)

支持的磁盘格式如下:

– DOS/Windows FAT12, FAT16 and FAT32

– NTFS ( Windows NT/2K/XP )

– Linux Ext2 and Ext3

– BeFS ( BeOS )

– BSD disklabel ( FreeBSD/OpenBSD/NetBSD )

– CramFS (Compressed File System)

– HFS and HFS+, Hierarchical File System

– JFS, IBM’s Journaled File System

– Linux Raid

– Linux Swap (versions 1 and 2)

– LVM and LVM2, Linux Logical Volume Manager

– Netware NSS

– ReiserFS 3.5, 3.6 and 4

– Sun Solaris i386 disklabel

– UFS and UFS2 (Sun/BSD/…)

– XFS, SGI’s Journaled File System

试试看

# wget http://www.cgsecurity.org/testdisk-6.11.3.linux26.tar.bz2

# bunzip2 testdisk-6.11.3.linux26.tar.bz2

# tar xvf testdisk-6.11.3.linux26.tar

# cd /root/testdisk-6.11.3/linux

# ./testdisk_static

linux 系统数据恢复 - simon-zzm - simon个人观点

英文提示很简。测试了一下图片格式恢复没有问题,其它格式没有试,但是名称都变成索引名了,有点不方便。

还存在一个问题就是ext4格式。ext4在rehdat5中已经支持,但是需要安装e4fsprogs,在redhat6中已经是默认安装,所以将来使用ext4的几率也很大。Ext3grep工具在ext4下已经无能为力,所以需要其它工具的支持。上网上找找是否会有ext4grep,发现了http://tjworld.net/wiki/Linux/Ext4Undelete,没有搞清楚。

介绍较多的是extundelete。

extundelete的下载地址

http://extundelete.sourceforge.net/

linux 系统数据恢复 - simon-zzm - simon个人观点

首先安装e2fsprogs和e2fslibs,然后编译

# cd extundelete-0.2.0

# ./configure

# make

不安装了直接用

#cd src

# /extundelete /dev/sda9 –restore-all

应该是我系统内核版本太低,虽然支持ext4,但软件恢复却没有成功。内核2.6.28以上的应该没有问题。Fedora上有人测试过没有问题,redhat和centos就应该没有问题。

试试PhotoRec是否可以恢复ext4的盘。步骤抓图如下:

启动

linux 系统数据恢复 - simon-zzm - simon个人观点

选择磁盘

linux 系统数据恢复 - simon-zzm - simon个人观点

选择好分区类型

linux 系统数据恢复 - simon-zzm - simon个人观点

选择要恢复的盘

linux 系统数据恢复 - simon-zzm - simon个人观点

不知道为什么支持了,和介绍里说的不一样,选第一项

linux 系统数据恢复 - simon-zzm - simon个人观点

选第一项

linux 系统数据恢复 - simon-zzm - simon个人观点

选择恢复后的路径,直接点y,保存到当前目录的recup_dir.1目录中

linux 系统数据恢复 - simon-zzm - simon个人观点
进入recup_dir.1目录查看jpg文件恢复了,并且可以使用,但是名称有变化了。pdf的好像没有成功。
linux 系统数据恢复 - simon-zzm - simon个人观点

照目前看txt等文本类和图片类的恢复也没有问题,但是只能靠grep在去找那个是需要的文件了。

经验总结:

使用rm需要格外小心(会出人命的)。在不小心删除后,最好及时卸载分区,避免数据覆盖写入。如果必须挂载,可以使用只读模式。

3月 28

nagios 安装调试

[整理人:张子萌 2010-04]

需要准备软件如下:
centos

nagios-3.2.0
nagios-plugin-1.4.14

除了nagios还需要安装以下软件
apache2 安装路径为/usr/local/apache
perl
gcc 编译工作系统默认即可,如果没有安装推荐使用yum安装。
php nagios3.2页面需要php环境
yum install gcc glibc glibc-common
绘制图表需要安装以下包
freetype-2.3.5.tar.gz
libiconv-1.11.tar.gz
libmcrypt-2.5.7.tar.gz
libpng-1.2.10.tar.bz2
jpegsrc.v6b.tar.gz
gd-2.0.35.tar.gz
可以使用yum或者源码安装。
以上绘图包和apache安装可以参照:http://simon-zzm.blog.163.com/blog/static/88809522201028104721790/

1. 建组建帐号nagios

# groupadd nagios
# groupadd apache
# useradd -g nagios -G apache nagios
# useradd -g apache -G nagios apache

2. 编译安装nagios

# tar zxvf nagios-3.2.0.tar.gz
# cd nagios-3.2.0
# ./configure –prefix=/usr/local/nagios
–with-command-group=nagios
–with-httpd-conf=/usr/local/apache/conf/
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf

3. 装nagios-plugin-1.4.13

# tar zxvf nagios-plugin-1.4.14.tar.gz
# cd nagios-plugin-1.4.14
# ./configure –prefix=/usr/local/nagios –with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install

注:centos4 上安装时
在checking for redhat spopen problem…停住。
需要添加–enable-redhat-pthread-workaround参数

4. 创建web登录nagios账号

# cd /usr/local/apache/bin
# ./htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin ;创建一个登录WEB的帐号

5. 配置nagios和apache整合
本文使用虚拟机配置。
# cd /usr/local/apache/conf/extra/
# vi httpd-vhosts.conf

配置apache的cgi ,在httpd-vhosts.conf后增加配置如下:

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

Alias /nagios /usr/local/nagios/share

Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

首先测试配置文件是否正确
# /usr/local/apache/bin/apachectl configtest

重启apache
# /usr/local/apache/bin/apachectl stop
# /usr/local/apache/bin/apachectl start

6. 启动nagios

测试nagios配置是否可用
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果可用启动服务
# /etc/init.d/nagios start

现在你可以通过浏览器访问监控的界面了,http://x.x.x.x/nagios

7. 定义监控组

7.1 建立test监控组,监控192.268.1.103服务器。

在/usr/local/nagios/etc/目录下建立test目录,并定义主机.
监控192.168.1.103服务器的配置文件名为test_1_103.cfg.
# mkdir -p /usr/local/nagios/etc/test
# vi /usr/local/nagios/etc/testgroup.cfg
# 定义主机
define host{
use test-host
alias test Linux Server
address test_1_103; 如多个文件可以用逗号分开
}

7.2 建立监控文件
# vi /usr/local/nagios/etc/test_1_103.cfg
# 定义Ping远程Linux主机
define service{
use test-service ; 这个名字要和监控模板中一样,见7.3
host_name test;
service_description PING;
check_command check_ping!100.0,20%!500.0,60% ;check_ping命令在commands.cfg中定义,后跟两个参数,命令及参数间用!分割。
}
# 检查远程Linux主机根分区使用情况,必须安装nrpe并在/usr/local/nagios/etc/objects/commands.cfg中定义,见第8部分。
define service{
use generic-service ; Name of service template to use
host_name sectop
service_description Root Partition
check_command check_nrpe!check_disk_root
}
# 检查远程Linux主机的登录人数
define service{
use generic-service ; Name of service template to use
host_name sectop
service_description Current Users
check_command check_nrpe!check_users
}
# 检查远程Linux的主机的负载
define service{
use generic-service ; Name of service template to use
host_name sectop
service_description Current Load
check_command check_nrpe!check_load
}
# 检查远程Linux主机swap分区使用情况
define service{
&nb
sp; use generic-service ; Name of service template to use
host_name sectop
service_description Swap Usage
check_command check_nrpe!check_swap
}
# 检查远程Linux主机的SSH服务
define service{
use generic-service ; Name of service template to use
host_name sectop
service_description SSH
check_command check_ssh
notifications_enabled 1 ;0为不发送告警信息 1为发送

}
# 检查远程Linux主机的HTTP服务
define service{
use generic-service ; Name of service template to use
host_name sectop
service_description HTTP
check_command check_http
notifications_enabled 1 ;0为不发送告警信息 1为发送
}

7.3 定义监控组的模板
# vi /usr/local/nagios/etc/objects/templates.cfg

define contact{
name test-contact ; The name of this contact template
service_notification_period 24×7 ; service notifications can be sent anytime
host_notification_period 24×7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}

define host{
name test-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24×7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
}

define host{
name te
st-server ; The name of this host template
use test-host ; This template inherits other values from the generic-host template
check_period 24×7 ; By default, Linux hosts are checked round the clock
check_interval 5 ; Actively check the host every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each Linux host 10 times (max)
check_command check-host-alive ; Default command to check Linux hosts
notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day
notification_interval 120 ; Resend notifications every 2 hours
notification_options d,u,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
}

define service{
name test-service ; The ‘name’ of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service ‘freshness’
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24×7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the serv
ice up to 3 times in order to determine its final (hard) state
normal_check_interval 10 ; Check the service every 10 minutes under normal conditions
retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the ‘admins’ group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24×7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}

7.4 修改告警模板
# vi vi /usr/local/nagios/etc/objects/contact.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use test-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email admin@mail.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}

7.5 添加加载项

在nagios.cfg配置文件中开启对/usr/local/nagios/etc/test/加载
cfg_dir=/usr/local/nagios/etc/test/testgroups.cfg
cfg_dir=/usr/local/nagios/etc/test/test_1_103.cfg

测试nagios配置是否可用
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果重启服务
# /etc/init.d/nagios restart

8. 安装nrpe
nrpe用于和远程服务器交互使用。
nrpe分为两部分:一部分是运行在client端。一部分运行在客户端

8.1 nagios服务器上安装
#tar xzvf nrpe-2.12.tar.gz
#cd nrpe-2.12
#./configure
#make all
#make install-plugin #服务器端只要安装nrpe监控插件就行

在/usr/local/nagios/etc/objects/commands.cfg中定义check_nrpe命令
#vi /usr/local/nagios/etc/objects/commands.cfg
添加如下
# ‘check_nrpe ‘ command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

8.2 在要监控的客户端上
参照 1 中在客户服务器上建立nagios用户组和nagios用户
# tar xzvf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14
# ./configure –prefix=/usr/local/nagios
# make
# make install
# chown -R nagios:nagios /usr/local/nagios/

# tar xzvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure –prefix=/usr/local/nagios
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
修改配置文件
# vi /usr/local/nagios/etc/nrpe.cfg #修改nrpe配置文件,允许Nagios监控服务器监控本机

allowed_hosts=127.0.0.1,192.168.0.19 #此处IP为监控服务器的地址,如多个地址可以使用逗号分隔

启动客户端
#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
查看端口是否已经监听
#netstat -tln #查看端口
tcp 0 0 0.0.0.0:5666 0.0.0.0:*

添加随系统启动,启动nrep客户端
#vi /etc/rc.d/rc.local
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

9. 设置被监控的windows服务器。
找了个NSClient++-windows*.msi的安装包,安装完毕修改配置,在nagios服务器也需要配
置,此处不做详解。

附录:
1. 配置nagios及其plugins

/usr/local/nagios/etc下的文件
#控制cgi访问的配置文件
cgi.cfg

#Nagios主配置文件
nagios.cfg

#resource.cfg定义了一些变量,以便被其它文件引用,如$USER1$
resource.cfg

# objects是一个目录,用于定义Nagios对象
objects

/usr/local/nagios/etc/objects下的文件

#命令

3月 21

linux 简单搭建vpn服务器

[整理 :张子萌 如有转载请保留整理人信息]

测试系统为redhat linux

搭建pptpd VPN服务需要内核支持mppe,内核为2.6以后的内核支持该选项。

查看内核命名# uname -r。注意:如果要远程安装调试,首先将防火墙设置为

不随操作系统启动。

1. 需要安装ppp和pptp服务,本文为使用yum安装。如果希望手动安装请到

http://poptop.sourceforge.net下载pptp源码包。

#yum -y install ppp

#yum -y install pptpd

查看内核是否加载 mppe 模块

# lsmod | grep ppp

如下图:

linux 简单搭建vpn服务器   - simon-zzm - simon个人观点

说明pptp 所又模块加载成功

2. 修改配置文件

安装完成后修改配置文件

2.1 配置pptpd.conf文件

#vi /etc/pptpd.conf

option /etc/ppp/options.pptpd # PPP使用的配置文件位置

stimeout 10 # 控制pptp连接超时,单位为秒

localip 192.168.0.1 # 服务器VPN虚拟接口将分配的IP地址

remoteip 192.168.0.234-238,192.168.0.245 # 客户端VPN连接成功后将分配的IP或IP地址范围。

说明localip和remoteip 不需要必须在同一网段,网络可以连通网段均可。

2.2 配置options.pptpd文件,此处只是对配置文件中部分配置做说明,如无特殊要求可以使用默认配置。

# vi /etc/ppp/options.pptpd

lock

auth # 启用身份验证

name cc3 # 相当于身份验证时的域,这里填上VPN服务器的名字

refuse-pap # 拒绝pap身份验证

refuse-chap # 拒绝chap身份验证

refuse-mschap # 拒绝mschap身份验证

refuse-eap # 拒绝eap身份验证

require-mschap-v2 #使用mschap-v2身份验证,使用windows可以直接建客户端

require-mppe-128 # 要求128位MPPE加密

nomppe-stateful # 无状态,有状态有mppe-stateful

ms-dns 202.106.46.151 # VPN客户端连接成功后将被分配的DNS参数,如只是ip访问可以不用此项

ms-wins 64.32.16.8 # VPN客户端连接成功后将被分配的WINS参数

proxyarp # 启用ARP代理

2.3 创建用户名和密码,可以再文件中直接编写,也可以使用命令创建。推荐使用命令创建。

2.3.1 创建用户

账户为vpntest 密码为123

#vpnuser add vpntest 123

2.3.2 删除用户:

删除 vpntest账户

#vpnuser del vpntest

2.3.3 查看当前用户表

# vpnuser show

2.3.4 直接文件编辑修改账户

#vi /etc/ppp/chap-secrets

格式如下

test pptpd 123 *

注:末尾“*”为分配给vpn客户端ip池的地址,也就是上面设置的remoteip部分。如需要分配指定IP,可以直接打入IP地址。

3. 启动pptpd服务

#service pptpd start

# /etc/init.d/pptpd start

pptpd参数有start|stop|restart|restart-kill|status,分别为启动、停止、重启、直接杀进程后重启、查看进程运行状态。

要查看连入vpn服务器的客户端信息,可以使用route命令,Use Iface列为ppp的为连入vpn服务器的客户信息。也可以使用ifconfig查看。

到此linux pptp vpn配置完成,可以使用windows来连接看看是否正常。

4. 安全防范

VPN使用GRE协议用的47端口 也需要开放 1723,如果使用防火墙需要添加如下配置。

#i ptables -A INPUT -p gre -j ACCEPT

如果开启selinux 还需要设置

#setsebool pppd_disable_trans 1

#setsebool pptp_disable_trans 1

如果客户端想用vpn server来上网的话,需要打开vpn server上的ip_forward

# echo “1” > /proc/sys/net/ipv4/ip_forward

永久更改:

# vi /etc/sysctl.conf

net.ipv4.ip_forward = 0 将 0 改为 1

保存后运行# sysctl –p 是参数生效。

设置ip伪装

#iptables -t nat -A POSTROUTING -o eth0 -j SNAT –to-source XXX.XXX.XXX.XXX (vpn 服务器公网ip)

#iptables -t nat -A FORWARD -o eth0 -j ACCEPT

如果还想访问vpn server所在的局域网,还需要在vpn server上添加路由

* 使用route 命令配置路由表 */

//添加到主机路由

# route add –host 192.168.168.110 dev eth0:1

# route add –host 192.168.168.119 gw 192.168.168.1

//添加到网络的路由

# route add –net IP netmask MASK eth0

# route add –net IP netmask MASK gw IP

# route add –net IP/24 eth1

//添加默认网关

# route add default gw IP

//删除路由

# route del –host 192.168.168.110 dev eth0

5. 常见问题处理

a) MGR: Maximum of 10 connections reduced to 3, not enough IP addresses given

说明配置文件中最大连接为10,但是只分配了3个地址。通过/etc/pptpd.conf配置文件修改

b)连接vpn后经常断线
pppd[18052]: Terminating on signal 15
pppd[18052]: Modem hangup
pppd[18052]: Connect time 1.0 minutes.
pppd[18052]: Sent 12143 bytes, received 4968 bytes.
pppd[18052]: MPPE disabled
pppd[18052]: Connection terminated.
pppd[18052]: Exit.

查看日志发现以上信息:

“Connect time 1.0 minutes.”说明用户连接vpn服务器后只连接了1分钟就断开了。

“Sent 12143 bytes, received 4968 bytes.”说明客户在连接后与vpn服务器间的传输量也不大。如

果流量过大,需要注意检查是否存在攻击。

“Terminating on signal 15”此条信息比较主要,说明vpn程序是被系统其它程序发出停止命令后强行

中断连接的。具体信号可以查看http://simon-zzm.blog.163.com/blog/static/8880952220103110240877/