手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

LNMP+SSL+ LVS-DR+ipvsadm+LVS Persistence

[日期:2012-04-20] 来源:Linux社区  作者:lihuan [字体:大 中 小]

3.在RS2上配置IP与arp规则:

  1. # ifconfig eth0 172.16.22.11 255.255.0.0 
  2. # ifconfig lo down 
  3. # ifconfig lo up 
  4. # echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore 
  5. # echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore 
  6. # echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce 
  7. # echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce 
  8. # ifconfig lo:0 172.16.22.2 broadcast 172.16.22.2 netmask 255.255.255.255 up 
  9. # route add –host 172.16.22.2 dev lo:0 
  10. #echo 
  11. “rs2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222” > /var/www/html/index.html 
  12. # setenforce=0 
  13. # service httpd restart 
  14. # elinks -dump http://172.16.22.11 

此时说明本机可以正常访问web服务了。

4.为RS1和RS2准备证书文件与私钥文件

(1).在RS1上:

# cd /etc/pki/tls

# vim openssl.cnf

[ CA_default ]

dir           = ../../CA            # Where everything is kept

把上面”=../../CA”改为”=/etc/pki/CA”

  1. # cd .. 
  2. # cd CA 
  3. # mkdir certs crl newcerts 
  4. # touch index.txt 
  5. # echo 01 > serial 
  6. # echo 01 > crlnumber 
  7. # (umask 077;openssl genrsa 2048 > private/cakey.pem)   #生成CA自己的私钥 
  8. # openssl req –new –x509 –key private/cakey.pem –out cacert.pem –days 3650 

依次输入”CN、Henan、ZZ、M、Tech 、  、 ” 这是CA为自己签发证书

  1. # mkdir /etc/nginx/ssl 
  2. # cd /etc/nginx/ssl 
  3. # (umask 077;openssl genrsa 1024 > nginx.key)   #生成nginx自己的私钥 
  4. # openssl req –new –key nginx.key –out nginx.csr  

依次输入”CN、Henan、ZZ、M、Tech 、  、 ”,这是生成nginx的证书签发请求

# openssl ca –in nginx.csr –out nginx.crt  #CA为nginx颁发证书

(2).在RS2上:

  1. # mkdir /etc/nginx/ssl 
  2. # cd /etc/nginx/ssl 
  3. # (umask 077;openssl genrsa 1024 > nginx.key)   #生成nginx自己的私钥 
  4. # openssl req –new –key nginx.key –out nginx.csr  

依次输入”CN、Henan、ZZ、M、Tech 、  、 ”,这是生成nginx的证书签发请求

# scp nginx.csr root@172.16.22.10:/root  #此时需要输入RS1的root用户的密码

把RS2上nginx的证书签发请求拷贝到RS1上,由RS1的CA签发证书

在RS1上:

# cd

# openssl ca –in nginx.csr –out nginx.crt  #CA为nginx颁发证书

# scp nginx.crt root@172.16.22.11:/etc/nginx/ssl  #此时需要输入RS2的root用户的密码

5.更改RS1和RS2的nginx配置文件,以支持https协议

在RS1上:

# vim /etc/nginx/nginx.conf

修改:

# HTTPS server

    #

    #server {

    #    listen       443;

    #    server_name  localhost;

 

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_timeout  5m;

 

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers   on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

#}为:

# HTTPS server

    #

    server {

        listen       443;

        server_name  www.linuxidc.com;

 

        ssl                  on;

        ssl_certificate      cert.pem;

        ssl_certificate_key  cert.key;

 

        ssl_session_timeout  5m;

 

        ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers   on;

 

        location / {

            root   html;

            index  index.html index.htm;

        }

    }

说明:RS2上修改配置文件支持https协议的方法同RS1,这里不再赘述。

 

6.在director上定义ipvsadm规则与持久防火墙标记,以实现同一个服务的不同端口定向到同一台realserver中

# iptables –t mangle –A PREROUTING –i eth0 –p tcp –d 172.16.22.2 –dport 80 –j MARK –set-mark 20 

# iptables –t mangle –A PREROUTING –i eth0 –p tcp –d 172.16.22.2 –dport 443 –j MARK –set-mark 20 

# ipvsadm –A –f 20 –s wlc –p 2000

# ipvsadm –a –f 20 –r 172.16.22.10 –g –w 5

# ipvsadm –a –f 20 –r 172.16.22.11 –g –w 4

说明:上面几条语句中绿色的字体的范围可以是0-99的任意整数,此处选为20,一旦选为20,这几条语句必须都是用20才能保证同一服务的不同端口定向到同一台realserver中

 

7.测试

前提:把RS1上的CA证书导入到windows物理机的浏览器中。

在浏览器输入:

http://172.16.22.2,出现:

然后再输入https://172.16.22.2,出现:

此时发现http和https的结果是一样的,说明同一服务的的不同端口定向到

同一台realserver中(有可能是RS1或者RS2,这个是不确定的)

linux
相关资讯       SSL  LNMP  LVS 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款