正向代理和反向代理

1、forward proxy
正向代理是一个位于client和origin server之间的proxy,为了从origin server取得内容,client向proxy发送一个请求并指定目标(origin server),然后proxy向origin server转交request并将获得的resopnse返回给client。client必须要进行一些特别的设置才能使用正向代理。

2、reverse proxy
反向代理对于client而言就像是origin server,并且clinet不需要进行任何特别的设置。client向反proxy发送普通请求,接着proxy将判断向何处(origin server)转交request,并将response返回给client,proxy在client看起来就像origin server一样。

3、两者区别
从网络角色来讲:
正向代理隐藏的是client,clinet可以感觉到正向代理的存在,proxy对server隐藏了client的细节。
反向代理隐藏的是origin server,client感觉不到反向代理的存在,proxy对clinet隐藏了server的细节。

从用途上来讲:
正向代理的典型用途是为在防火墙内的局域网客户端提供访问Internet的途径,正向代理还可以使用缓冲特性减少网络使用率。
反向代理的典型用途是将防火墙后面的服务器提供给Internet用户访问,反向代理还可以为后端的多台服务器提供负载平衡,或为后端较慢的服务器提供缓冲服务。另外,反向代理还可以启用高级URL策略和管理技术,从而使处于不同web服务器系统的web页面同时存在于同一个URL空间下。

从安全性来讲:
正向代理允许client通过它访问任意网站并且隐藏client自身,因此你必须采取安全措施以确保仅为经过授权的客户端提供服务。
反向代理对clinet都是透明的,clinet并不知道自己访问的是一个代理。

4、透明代理
透明代理技是指客户端感觉不到代理的存在,不需要在浏览器中设置任何代理,客户只需要设置缺省网关,客户的访问外部网络的数据包被发送到缺省网关,而这时缺省网关运行有一个代理服务器,数据实际上被被重定向到代理服务器的代理端口,即由本地代理服务器向外请求所需数据然后拷贝给客户端。理论上透明代理可以对任何协议通用。一般透明代理用于防火墙技术比较多。

Nginx中的upstream

Nginx中upstream有以下几种方式:

1、轮询(weight=1)
默认选项,当weight不指定时,各服务器weight相同,
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。

upstream bakend {
server 192.168.1.10;
server 192.168.1.11;
}

2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
如果后端服务器down掉,能自动剔除。
比如下面配置,则1.11服务器的访问量为1.10服务器的两倍。

upstream bakend {
server 192.168.1.10 weight=1;
server 192.168.1.11 weight=2;
}

3、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session不能跨服务器的问题。
如果后端服务器down掉,要手工down掉。

upstream resinserver{
ip_hash;
server 192.168.1.10:8080;
server 192.168.1.11:8080;
}

4、fair(第三方插件)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。

upstream resinserver{
server 192.168.1.10:8080;
server 192.168.1.11:8080;
fair;
}

5、url_hash(第三方插件)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存服务器时比较有效。
在upstream中加入hash语句,hash_method是使用的hash算法

upstream resinserver{
server 192.168.1.10:8080;
server 192.168.1.11:8080;
hash $request_uri;
hash_method crc32;
}

设备的状态有:
1.down 表示单前的server暂时不参与负载
2.weight 权重,默认为1。 weight越大,负载的权重就越大。
3.max_fails 允许请求失败的次数默认为1。当超过最大次数时,返回proxy_next_upstream 模块定义的错误
4.fail_timeout max_fails次失败后,暂停的时间。
5.backup 备用服务器, 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

Git02常用命令

1、设置个人信息

git config --global user.name "xxx"
git config --global user.email "xxx@xxx.xxx"

2、提交

#初始化本地git
cd hello-git
git init

#新建README文件
touch README
git add README

#提交文件到本地Git
git commit -m 'first commit'

#提交文件到远程Git
git remote add origin git@github.com:username/hello-git.git
git push -u origin master

3、取回

git clone git@github.com:username/hello-git.git

取回(包含子模块)

git clone --recursive -j6 git@github.com:username/hello-git.git

取回(包含子模块)

git clone git@github.com:username/hello-git.git
cd hello-git
git submodule update --init --recursive

4、Fork

#产生Fork后取回
git clone git@github.com:username/hello-git.git
cd hello-git

#追加上级代码信息
git remote add upstream git://github.com/SomeOne/hello-git.git
git fetch upstream
#合并上级代码
git fetch upstream
git merge upstream/master

5、创建分支

#创建分支
git checkout -b mybranch

6、合并分支

#合并分支
git checkout master
git merge mybranch
git branch -d mybranch

7、改变远程库地址

git remote set-url origin 新地址

About Unix

三大UNIX为:
IBM AIX, HP UNIX,SUN Solaris

UNIX,BSD,Linux被统称为×nix系统。

BSD与Linux系统的区别:
BSD is what you get when a bunch of UNIX hackers sit down to try to port a UNIX system to the PC.
Linux is what you get when a bunch of PC hackers sit down and try to write a UNIX system for the PC.

Linux及BSD包管理系统

大家都知道,
Linux发行版=Linux内核+包管理系统

当下,Linux的主要包管理系统分为两大阵营,RPM和DEB,
(其主要原因是,子发行版多沿用了父发行版的包管理系统)
但每种有特色的发行版,又都会开发自己独特的包管理系统。
主要Linux发行版的管理统系统计如下:

RPM:
RHEL;Fedora;CentOS;
openSUSE;SUSE Linux Enterprise;
PCLinuxOS;
Mageia;
Fuduntu;
Mandriva Linux;
Scientific Linux;
Oracle Linux;

DEB:
Debian;
Ubuntu;Kubuntu;Xubuntu;Ubuntu Studio;
Lubuntu;
Linux Mint;
Ultimate Edition;
Bodhi Linux;
Pinguy OS;
Zorin OS;
MEPIS Linux;
KNOPPIX;
BackTrack;

Pacman:
Arch Linux;
Chakra GNU/Linux;

Portage:
Gentoo

PET:
Puppy

TCE:
Tiny Core Linux

Entropy:
Sabayon Linux

TXZ:
Slackware Linux

TBZ:
FreeBSD;
DragonFly BSD;

TGZ:
OpenBSD

PBI/TGZ:
PC-BSD

IPS, pkgadm:
Oracle Solaris

pkgin:
MINIX

MyEclipe中Java工程手动增加Maven支持

1修改文件.project

<buildSpec>
	<buildCommand>
		<name>org.maven.ide.eclipse.maven2Builder</name>
		<arguments>
		</arguments>
	</buildCommand>
</buildSpec>
<natures>
	<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>

2.修改文件.classpath

<classpath>
	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
</classpath>

3.新增文件pom.xml

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&#93;
  <modelVersion>4.0.0</modelVersion>

  <groupId>groupId</groupId>
  <artifactId>artifactId</artifactId>
  <version>1.0</version>
  <name>name</name>
 
  <dependencies>
  </dependencies>

  <build>
      <plugins>
      </plugins>
  </build>  
</project>

mongrel.rb

使用Redmin1.3.2时,用命令行可以启动,但使用mongrel_service-0.4.0启动后会发生重定向
只需要将mongrel.rb拷贝到redmine-1.3.2\config\initializers下面就好了

mongrel.rb

if ['2.3.8', '2.3.9', '2.3.10', '2.3.11', '2.3.14'].include?(Rails.version) && Gem.available?('mongrel', '~>1.1.5') && self.class.const_defined?(:Mongrel)
  
  # Pulled right from latest rack. Old looked like this in 1.1.0 version.
  #
  # def [](k)
  # super(@names[k] ||= @names[k.downcase])
  # end
  #
  module Rack
    module Utils
      class HeaderHash < Hash
        def [](k)
          super(@names[k]) if @names[k]
          super(@names[k.downcase])
        end
      end
    end
  end
  
  # Code pulled from the ticket above.
  #
  class Mongrel::CGIWrapper
    def header_with_rails_fix(options = 'text/html')
      @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie']
      header_without_rails_fix(options)
    end
    alias_method_chain :header, :rails_fix
  end
  
  # Pulled right from 2.3.8 ActionPack. Simple diff was
  #
  # if headers.include?('Set-Cookie')
  # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
  # end
  #
  # to
  #
  # if headers['Set-Cookie']
  # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
  # end
  #
  module ActionController
    class CGIHandler
      def self.dispatch_cgi(app, cgi, out = $stdout)
        env = cgi.__send__(:env_table)
        env.delete "HTTP_CONTENT_LENGTH"
        cgi.stdinput.extend ProperStream
        env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
        env.update({
          "rack.version" => [0,1],
          "rack.input" => cgi.stdinput,
          "rack.errors" => $stderr,
          "rack.multithread" => false,
          "rack.multiprocess" => true,
          "rack.run_once" => false,
          "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
        })
        env["QUERY_STRING"] ||= ""
        env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
        env["REQUEST_PATH"] ||= "/"
        env.delete "PATH_INFO" if env["PATH_INFO"] == ""
        status, headers, body = app.call(env)
        begin
          out.binmode if out.respond_to?(:binmode)
          out.sync = false if out.respond_to?(:sync=)
          headers['Status'] = status.to_s
          if headers['Set-Cookie']
            headers['cookie'] = headers.delete('Set-Cookie').split("\n")
          end
          out.write(cgi.header(headers))
          body.each { |part|
            out.write part
            out.flush if out.respond_to?(:flush)
          }
        ensure
          body.close if body.respond_to?(:close)
        end
      end
    end
  end
end

搭建Redmine

1.下载Ruby1.87及DevKit,解压,并将两个bin目录加入到PATH
http://rubyinstaller.org/downloads/

2.下载RubyGems 1.3.7,并安装

ruby setup.rb

3.安装gem
1)安装Rails 2.3.14

gem install rails -v=2.3.14 --include-dependencies

2)安装rake

gem install rake --include-dependencies

3)安装rack

gem install rack

4)安装mysql插件

gem install mysql

5)安装rdoc

gem install rdoc

6)安装i18n

gem install i18n

如果网速很差,可以把gem下载到本地后再安装,比如:

gem install i18n -l

4.配置数据库
1)拷贝dll
将mysql安装目录下的libmysql.dll拷贝到ruby路径
如果你的libmysql.dll版本高于5.1.3的话请用这个
http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

2)配置数据库
下载并解压redmine-1.3.2
拷贝database.yml.example为database.yml,将production小节配置好

3)创建数据库

rake generate_session_store
rake db:migrate RAILS_ENV="production"

5.测试

ruby script/server -e production
#访问http://localhost:3000/
#用户名:admin
#密码:admin

6.配置email
拷贝configuration.yml.example为configuration.yml,
修改smtp配置,重启服务器即可

7.安装服务
1)安装gem

gem install mongrel_service

2)安装服务

mongrel_rails service::install -N Redmine -c D:\Ruby\redmine-1.3.2 -p 3000 -e production

3)设置服务依赖

sc config Redmine depend= MySQL start= auto

4)将mongrel.rb拷贝到redmin/config/initializers
mongrel.rb在github上有很多版本,但要自己改一下代码,来适应自己的rails版本

搭建Mantis

1.安装apache 2.2.x

2.配置apache端口
httpd.conf

Listen 8000

3.安装php5
需要模块:MySQL,SMTP,GD2

4.配置php
httpd.conf

AddType application/x-httpd-php .php .phtml .php3 .php4

5.解压mantis

6.配置mantis虚拟目录
httpd.conf

Alias /Mantis D:/mantisbt

<Directory "D:/mantisbt"]
        Options Indexes
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

DirectoryIndex index.html index.php index.perl

7.安装mysql

8.新建用户,数据库,并为用户分配权限

9.首次访问mantis,按提示安装数据库,主要端口及大小写
http://127.0.0.1:8000/Mantis/login_page.php

10.首次登陆mantis,修改超级用户密码
http://127.0.0.1:8000/Mantis/login_page.php
用户名:administrator
密码:root

11.设置mantis语言
config_defaults_inc.php

$g_default_language  = 'chinese_simplified';

12.配置mantis邮件
config_defaults_inc.php

$g_smtp_host = "smtp服务器地址";
$g_smtp_username = '用户名';
$g_smtp_password = '密码';

13.配置mantis文件上传
config_defaults_inc.php

$g_allow_file_upload	= ON;
$g_file_upload_method	= DISK;

14.配置mantis图形插件,这里很麻烦,大体步骤如下
1)安装mantis报表插件
2)安装JpGraph,配置路径及字体,但插件配置中没有simsun字体
3)修改mantis代码,全局搜素,在出现verasans的地方,相应增加simsun,好像是三处
4)修改JpGraph,在处理simsun字体的时候,不用做转码,直接返回就好啦
5)去插件管理的地方,选择simsun
6)刷新即可