lvs持久连接适用于大部分调度算法。当某一种请求需要定向到一个real server 时,就要用到持久连接
一般应用到:ssl(http.https等)、ftp。
-p //表示此连接为持久连接
N //表示维持此持久连接的时间。默认6分钟。当超过这个时间后,如果网页还没有关掉,仍处于激活状态,重新复位时间为2分钟。
1、创建CA,并生成自签证书PEM(windwos系统的格式通常是DER)
[root@ 192.168.1.15 CA]# (umask 077; openssl genrsa 2048 >private/cakey.pem)
Generating RSA private key, 2048 bit long modulus
........+++
........................................+++
e is 65537 (0x10001)
[root@ 192.168.1.15 CA]# openssl req -new -x509 -in private/cakey.pem -out cacert1.pem -days 3650
Generating a 2048 bit RSA private key
........................................+++
....................................................+++
writing new private key to 'privkey.pem'
Enter PEM pass phrase:
140021996894024:error:28069065:lib(40):UI_set_result:result too small:ui_lib.c:869:You must type in 4 to 1024 characters
140021996894024:error:0906406D:PEM routines:PEM_def_callback:problems getting password:pem_lib.c:111:
140021996894024:error:0907E06F:PEM routines:DO_PK8PKEY:read key:pem_pk8.c:130:
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert1.pem -days 3650
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HENAN
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MAGEEDU
Organizational Unit Name (eg, section) []:TECH
Common Name (eg, your name or your server's hostname) []:ca.magedu.com
Email Address []:ca@magedu.com
[root@ 192.168.1.15 CA]# touch index.txt
[root@ 192.168.1.15 CA]# echo “01”>serial
2、创建服务器的证书签发请求CSR
[root@192.168.1.12 ~]# cd /etc/httpd/conf/&& mkdir ssl&& cd ssl &&(umask 077;openssl genrsa 1024 >httpd.key)
Generating RSA private key, 1024 bit long modulus
................++++++
......................................++++++
e is 65537 (0x10001)
[root@192.168.1.12 /etc/httpd/conf/ssl]# openssl req -new -key httpd.key -out httpd.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HENAN
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MAGEEDU
Organizational Unit Name (eg, section) []:TECH
Common Name (eg, your name or your server's hostname) []:test.magedu.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate. If
# the certificate is encrypted, then you will be prompted for a
# pass phrase. Note that a kill -HUP will prompt again. A new
# certificate can be generated using the genkey(1) command.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/httpd/conf/ssl/httpd.crt
# Server Private Key:
# If the key is not combined with the certificate, use this
# directive to point at the key file. Keep in mind that if
# you've both a RSA and a DSA private key you can configure
# both in parallel (to also allow the use of DSA ciphers, etc.)
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/httpd/conf/ssl/httpd.key
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
#ServerName www.example.com:443
常见ipvs的持久链接,方式为防火墙标记:
[root@localhost ~]# iptables -t mangle -A PREROUTING -d 10.40.0.51 -p tcp --dport 80 -j MARK --set-mark 9
[root@localhost ~]# iptables -t mangle -A PREROUTING -d 10.40.0.51 -p tcp --dport 443 -j MARK --set-mark 9
[root@localhost ~]# iptables -L -t mangle
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
MARK tcp -- anywhere 10.40.0.51 tcp dpt:http MARK set 0x9
MARK tcp -- anywhere 10.40.0.51 tcp dpt:http MARK set 0x9
MARK tcp -- anywhere 10.40.0.51 tcp dpt:https MARK set 0x9