haojianyun

welcom to my haojianyun.com

服务器流量大,就得用负载均衡

负载均衡思路

  • DNS负载平衡的方法
    • 这种方法类似于CND一样,前台做cnd域名拦截,分发到不同的机器上,
    • 目前阿里云的负载均衡就是这种思路
       
  • 服务端应用层和IP层的负载平衡方法
    • 服务端应用层方法,和ip层负载一帮就是域名已经落地到某个机器上了,完后机器在做负载转发。nginx负载权重一般都是这个方法。

集群( Cluster )Server 达成负载平衡的方法

  • Linux Virtual Server ( LVS ) 的架设
    • 三转发机制(Traffic Forward Mechanism)
      • Virtual Server ( 虚拟主机 )
      • Load Balancer (负载平衡器)
      • Linux Director (导引主机)
    • 四种分配方法(Load-balancing Methods)
      • 轮流排程 Round-Robin Scheduling (RRS)

      • 加权轮流排程 Weighted Round-Robin Scheduling (WRRS)

      • 最小连结数排程 Least-Connection Scheduling (LCS)

      • 加权最小连接数排程 Weighted Least-Connection Scheduling (WLCS)

    • http://blog.csdn.net/yanziguishi/article/details/6807165

    • http://blog.csdn.net/yanziguishi/article/details/6743504

9月 27th, 2017

Posted In: computer knowledge(电脑知识)

Leave a Comment

###在亚马孙EC2上构建L2TP VPN (Setup L2TP over IPSec VPN on Ubuntu Linux with Amazon EC2)

由于各种原因本人还是喜欢用自己搭建的服务器上外国的网站。以前经常用PPTP上网,方便配置又简单。但无奈苹果MAC升级10.12 和 IOS 10.02 之后直接去掉PPTP的VPN链接方式,但我又喜欢用系统原生的VPN不想安装什么其它辅助软件,还是动手更新新的VPN方式吧。
废话少说看步骤。

1.安装包,主要权限的, Install packages

$ sudo apt-get install openswan xl2tpd ppp

2. 配置EC2上的权限组, Configure AWS EC2 Security Group

打开UDP上端口 500,1701,4500,
Open UDP ports 500, 1701, 4500 for public access.

3.配置IPSec ,Configure Openswan for IPSec

$ sudo vi /etc/ipsec.conf

# /etc/ipsec.conf - Openswan IPsec configuration file

# This file:  /usr/share/doc/openswan/ipsec.conf-sample
#
# Manual:     ipsec.conf.5

version    2.0 # conforms to second version of ipsec.conf specification

# basic configuration
config setup  
# Do not set debug options to debug configuration issues!
# plutodebug / klipsdebug = "all", "none" or a combation from below:
# "raw crypt parsing emitting control klips pfkey natt x509 dpd private"
# eg:
# plutodebug="control parsing"
# Again: only enable plutodebug or klipsdebug when asked by a developer
#
# enable to get logs per-peer
# plutoopts="--perpeerlog"
#
# Enable core dumps (might require system changes, like ulimit -C)
# This is required for abrtd to work properly
# Note: incorrect SElinux policies might prevent pluto writing the core
dumpdir=/var/run/pluto/
#
# NAT-TRAVERSAL support, see README.NAT-Traversal
nat_traversal=yes
# exclude networks used on server side by adding %v4:!a.b.c.0/24
# It seems that T-Mobile in the US and Rogers/Fido in Canada are
# using 25/8 as "private" address space on their 3G network.
# This range has not been announced via BGP (at least upto 2010-12-21)
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:25.0.0.0/8,%v6:fd00::/8,%v6:fe80::/10
# OE is now off by default. Uncomment and change to on, to enable.
oe=off
# which IPsec stack to use. auto will try netkey, then klips then mast
protostack=netkey
# Use this to log to a file, or disable logging on embedded systems (like openwrt)
#plutostderrlog=/dev/null

# Add connections here

# sample VPN connection
# for more examples, see /etc/ipsec.d/examples/
#conn sample
#        # Left security gateway, subnet behind it, nexthop toward right.
#        left=10.0.0.1
#        leftsubnet=172.16.0.0/24
#        leftnexthop=10.22.33.44
#        # Right security gateway, subnet behind it, nexthop toward left.
#        right=10.12.12.1
#        rightsubnet=192.168.0.0/24
#        rightnexthop=10.101.102.103
#        # To authorize this connection, but not actually start it,
#        # at startup, uncomment this.
#        #auto=add


#conn L2TP-PSK-NAT
#    rightsubnet=vhost:%priv
#    also=L2TP-PSK-noNAT

conn L2TP-PSK-noNAT  
#
# Configuration for one user with any type of IPsec/L2TP client
# including the updated Windows 2000/XP (MS KB Q818043), but
# excluding the non-updated Windows 2000/XP.
#
#
# Use a Preshared Key. Disable Perfect Forward Secrecy.
#
# PreSharedSecret needs to be specified in /etc/ipsec.secrets as
# YourIPAddress  %any: "sharedsecret"
authby=secret
pfs=no
auto=add
keyingtries=3
# we cannot rekey for %any, let client rekey
rekey=no
# Apple iOS doesn't send delete notify so we need dead peer detection
# to detect vanishing clients
dpddelay=10
dpdtimeout=90
dpdaction=clear
# Set ikelifetime and keylife to same defaults windows has
ikelifetime=8h
keylife=1h
# l2tp-over-ipsec is transport mode
type=transport
#
left=YOUR.SERVER.IP.ADDRESS #AWS EC2 Internal IP
#
# For updated Windows 2000/XP clients,
# to support old clients as well, use leftprotoport=17/%any
leftprotoport=17/1701
#
# The remote user.
#
right=%any
# Using the magic port of "%any" means "any one single port". This is
# a work around required for Apple OSX clients that use a randomly
# high port.
rightprotoport=17/%any

forceencaps=yes

$ vi /etc/ipsec.secrets

# This file holds shared secrets or RSA private keys for inter-Pluto
# authentication.  See ipsec_pluto(8) manpage, and HTML documentation.

# RSA private key for this host, authenticating it to any other host
# which knows the public part.  Suitable public keys, for ipsec.conf, DNS,
# or configuration of other implementations, can be extracted conveniently
# with "ipsec showhostkey".

# AWS EC2 Internal IP
YOUR.SERVER.IP.ADDRESS %any: PSK "YourSharedSecrets"

# this file is managed with debconf and will contain the automatically created RSA keys
#include /var/lib/openswan/ipsec.secrets.inc

$ service ipsec restart

4.为L2TP 配置 XLTPD ,Configure XL2TPD for L2TP

$ vi /etc/xl2tpd/xl2tpd.conf

;
; Sample l2tpd configuration file
;
; This example file should give you some idea of how the options for l2tpd
; should work.  The best place to look for a list of all options is in
; the source code itself, until I have the time to write better documetation :)
; Specifically, the file "file.c" contains a list of commands at the end.
;
; You most definitely don't have to spell out everything as it is done here
;
[global]                                                                ; Global parameters:
ipsec saref = yes

; port = 1701                                                       ; * Bind to port 1701
; auth file = /etc/l2tpd/l2tp-secrets   ; * Where our challenge secrets are
; access control = yes                                  ; * Refuse connections without IP match
; rand source = dev                     ; Source for entropy for random
;                                       ; numbers, options are:
;                                       ; dev - reads of /dev/urandom
;                                       ; sys - uses rand()
;                                       ; egd - reads from egd socket
;                                       ; egd is not yet implemented
;
[lns default]                                                   ; Our fallthrough LNS definition
; exclusive = no                                                ; * Only permit one tunnel per host
; ip range = 192.168.0.1-192.168.0.20   ; * Allocate from this IP range
ip range = 10.1.2.2-10.1.2.255  
local ip = 10.1.2.1  
refuse chap = yes  
refuse pap = yes  
require authentication = yes  
ppp debug = yes  
pppoptfile = /etc/ppp/options.xl2tpd  
length bit = yes

; no ip range = 192.168.0.3-192.168.0.9 ; * Except these hosts
; ip range = 192.168.0.5                                ; * But this one is okay
; ip range = lac1-lac2                                  ; * And anything from lac1 to lac2's IP
; lac = 192.168.1.4 - 192.168.1.8               ; * These can connect as LAC's
; no lac = untrusted.marko.net                  ; * This guy can't connect
; hidden bit = no                                               ; * Use hidden AVP's?
; local ip = 192.168.1.2                                ; * Our local IP to use
; length bit = yes                                              ; * Use length bit in payload?
; require chap = yes                                    ; * Require CHAP auth. by peer
; refuse pap = yes                                              ; * Refuse PAP authentication
; refuse chap = no                                              ; * Refuse CHAP authentication
; refuse authentication = no                    ; * Refuse authentication altogether
; require authentication = yes                  ; * Require peer to authenticate
; unix authentication = no                              ; * Use /etc/passwd for auth.
; name = myhostname                                             ; * Report this as our hostname
; ppp debug = no                                                ; * Turn on PPP debugging
; pppoptfile = /etc/ppp/options.l2tpd.lns       ; * ppp options file
; call rws = 10                                                 ; * RWS for call (-1 is valid)
; tunnel rws = 4                                                ; * RWS for tunnel (must be > 0)
; flow bit = yes                                                ; * Include sequence numbers
; challenge = yes                                               ; * Challenge authenticate peer ;
; rx bps = 10000000                             ; Receive tunnel speed
; tx bps = 10000000                             ; Transmit tunnel speed
; bps = 100000                                  ; Define both receive and transmit speed in one option

; [lac marko]                                                   ; Example VPN LAC definition
; lns = lns.marko.net                                   ; * Who is our LNS?
; lns = lns2.marko.net                                  ; * A backup LNS (not yet used)
; redial = yes                                                  ; * Redial if disconnected?
; redial timeout = 15                                   ; * Wait n seconds between redials
; max redials = 5                                               ; * Give up after n consecutive failures
; hidden bit = yes                                              ; * User hidden AVP's?
; local ip = 192.168.1.1                                ; * Force peer to use this IP for us
; remote ip = 192.168.1.2                               ; * Force peer to use this as their IP
; length bit = no                                               ; * Use length bit in payload?
; require pap = no                                              ; * Require PAP auth. by peer
; require chap = yes                                    ; * Require CHAP auth. by peer
; refuse pap = yes                                              ; * Refuse PAP authentication
; refuse chap = no                                              ; * Refuse CHAP authentication
; refuse authentication = no                    ; * Refuse authentication altogether
; require authentication = yes                  ; * Require peer to authenticate
; name = marko                                                  ; * Report this as our hostname
; ppp debug = no                                                ; * Turn on PPP debugging
; pppoptfile = /etc/ppp/options.l2tpd.marko     ; * ppp options file for this lac
; call rws = 10                                                 ; * RWS for call (-1 is valid)
; tunnel rws = 4                                                ; * RWS for tunnel (must be > 0)
; flow bit = yes                                                ; * Include sequence numbers
; challenge = yes                                               ; * Challenge authenticate peer
;
; [lac cisco]                                                   ; Another quick LAC
; lns = cisco.marko.net                                 ; * Required, but can take from default
; require authentication = yes

$ service xl2tpd restart

5.配置用来拨号的 PPP ,Configure PPP

$ sudo vi /etc/ppp/options.xl2tpd

require-mschap-v2  
refuse-mschap  
ms-dns 8.8.8.8  
ms-dns 8.8.4.4  
auth  
mtu 1200  
mru 1000  
crtscts  
hide-password  
modem  
name l2tpd  
proxyarp  
lcp-echo-interval 30  
lcp-echo-failure 4  

$ sudo vi /etc/ppp/pap-secrets

# Secrets for authentication using CHAP
# client      server  secret          IP addresses
username      l2tpd   password        *

6.防火墙设置,设置iptable Modify iptables

$ sudo iptables --table nat --append POSTROUTING --jump MASQUERADE

保存iptable Save current iptables:

$ sudo apt-get install iptables-persistent

7.修改转发文件sysctl.conf ,Modify sysctl.conf

$ sudo vi /etc/sysctl.conf

增加下面的行到sysctl.conf: Add the following lines to sysctl.conf:

net.ipv4.ip_forward = 1  
net.ipv4.conf.all.accept_redirects = 0  
net.ipv4.conf.all.send_redirects = 0  

应用改变, Apply changes:

$ sudo sysctl -p

8.(可选)跟踪问题 ,Troubleshooting

$ tail -f /var/log/auth.log

#####⚠️注意要吧 YOUR.SERVER.IP.ADDRESS 改成EC2的内网IP
可以用ifconfig 查看eth0的地址

form: http://tanshuai.com/l2tp-over-ipsec-vpn-ubuntu-linux-aws-ec2/

10月 20th, 2016

Posted In: computer knowledge(电脑知识)

Leave a Comment

关闭 HTTPS / SSL for Virtualmin / Webmin Miniserv
  1. 登陆到服务器通过 ssh ,用 Telnet 或是 其他终端。
  2. 编辑服务器当中的下面的文档,通过vi 或是 nano:
    /etc/webmin/miniserv.conf

  1. 在miniserv.conf定位到下面的行,把ssl = 1 该成下面
ssl=0

  1. 保存miniserv.conf文件
  2. 停止然后重启Webmin
/etc/init.d/webmin restart

或者

service webmin restart

选择你可以用 http://你服务器IP:10000来访问了

参考:https://techjourney.net/disable-https-ssl-for-virtualmin-webmin-miniserv/

7月 29th, 2016

Posted In: computer knowledge(电脑知识)

Leave a Comment

最近用Wget 下载几个带有中文的文件,还有相关的目录,都出现莫名其妙的乱码,找了很多编码还原工具没效果,包括有名的convmv也没救,于是无奈自己从代码上做文章,便自己写了这个工具。

iRename for mac :

iRename

 

11月 1st, 2015

Posted In: computer knowledge(电脑知识)

标签:, ,

Leave a Comment

方法1.

重新启动并按住option健,选择recovery,进入后打开终端输入:resetpassword,这样就可以了。

方法2.

开机, 启动时按“cmd+S”。这时,你会进入Single User Model,出现像DOS一样的提示符 #root>。请在#root>下 输入 (注意空格, 大小写)  fsck -y  mount -uaw /  rm /var/db/.AppleSetupDone  reboot  紧接着,苹果电脑会重启 ,并且在开机后出现新装机时的欢迎界面。你需要像第一次打开苹果电脑一样, 重新建立一个新的管理员账号(数据会保留)。当开机完毕之后,在新的管理员下请打开 系统预制 – 账户。打开最下面的锁, 当跳出密码框时, 输入新的管理员帐号密码。这时,你会看到出现至少两个账号,包括了新的管理员的帐号和你原来的帐号。你可以点中原来的账号, 选 密码 – 更改密码。注意,你不需要有原先的密码就直接可以设定新密码了

来自:http://www.macx.cn/thread-2093882-1-1.html

12月 18th, 2014

Posted In: computer knowledge(电脑知识)

Leave a Comment

« 上一页