当前位置: 首页 > 编程日记 > 正文

LVS_DR实现(负载均衡)及LVS_DR+keepalived实现(高可用+负载均衡)

client->VS->RS->client(VS只做调度,RS为虚拟服务器)

LVS_DR原理图解:

优点:负载均衡器只负责将请求包分发给物理服务器,而物理服务器将应答包直接发给用户。所以,负载均衡器能处理 很巨大的请求量,这种方式,一台负载均衡能为 超过100台的物理服务器服务,负载均衡器不再是系统的瓶颈.

缺点:这种方式需要所有的DIR和RIP都在同一广播域;不支持异地容灾。

环境:

iptables和selinux关闭

test1(调度器)端(172.25.1.1):

[root@test1 ~]# yum install -y ipvsadm

Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use
subscription-manager to register.
Setting up Install Process
No package ipvsadm available.
Error: Nothing to do

[root@test1 ~]# vim /etc/yum.repos.d/rhel-source.repo
[rhel6.5]
name=rhel6.5
baseurl=http://172.25.1.250/rhel6.5
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[LoadBalancer]                                               //添加LoadBalancer用来下载ipvsadm服务
name=LoadBalancer
baseurl=http://172.25.1.250/rhel6.5/LoadBalancer
gpgcheck=0
enabled=1

[root@test1 ~]# yum install -y ipvsadm
[root@test1 ~]# /etc/init.d/ipvsadm start       //启动服务
[root@test1 ~]# ip addr add 172.25.1.100 dev eth0      //添加虚拟IP
[root@test1 ~]# ip addr    //查看是否添加
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
link/ether 52:54:00:4f:1c:32 brd ff:ff:ff:ff:ff:ff
inet 172.25.1.1/24 brd 172.25.1.255 scope global eth0
inet 172.25.1.100/32 scope global eth0inet6 fe80::5054:ff:fe4f:1c32/64 scope link
valid_lft forever preferred_lft forever
[root@test1 ~]# ipvsadm -A -t 172.25.1.100:80 -s rr            
[root@test1 ~]# ipvsadm -a -t 172.25.1.100:80 -r 172.25.1.2:80 -g        //-a表示在添加虚拟服务中添加,-g表示使用直接模式

[root@test1 ~]# ipvsadm -a -t 172.25.1.100:80 -r 172.25.1.3:80 -g

[root@test1 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
TCP 172.25.1.100:80 rr
-> 172.25.1.2:80   Route    1    0    0
-> 172.25.1.3:80   Route    1    0    0

服务器 1(server2:172.25.1.2)端:

[root@test2 ~]# ip addr add 172.25.1.100/32 dev eth0      //添加虚拟ip,目的是让test1与其正常进行三次握手。
[root@test2 ~]# vim /var/www/html/index.html
<h1>www.westos.org-server2</h1>
/etc/init.d/httpd restart

服务器 2(server3:172.25.1.3)端:

[root@test3 ~]# ip addr add 172.25.1.100/32 dev eth0       //添加虚拟ip,目的是让test1与其正常进行三次握手。
[root@test3 ~]# vim /var/www/html/index.html
<h1>bbs.westos.org-server3</h1>
/etc/init.d/httpd restart

客户端访问:
      调度器 MAC 地址:52:54:00:4f:1c:32
      服务器 1(server2)端 MAC 地址:52:54:00:2b:85:5b
      服务器 2(server3)端 MAC 地址:52:54:00:98:3d:65
注意:访问结果会出现下面三种情况:

[root@foundation1 ~]# arp -d 172.25.1.100        //端开之前的连接
[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 ~]# arp -an | grep 100
? (172.25.1.100) at 52:54:00:2b:85:5b [ether] on br0

总结1:从MAC地址可以看出没有经过调度器,直接经过服务器 1 访问

[root@foundation1 ~]# arp -d 172.25.1.100
[r[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
oot@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
<h[root@foundation1 ~]# arp -an | grep 100
? (172.25.1.100) at 52:54:00:2b:85:5b [ether] on

总结2:从MAC地址可以看出没有经过调度器,直接经过服务器 2 访问

[root@foundation1 ~]# arp -d 172.25.1.100
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# arp -an | grep 100
? (172.25.1.100) at 52:54:00:4f:1c:32 [ether] on br0

总结3:从 MAC 地址可以看出经过了调度器,所以轮询。
总结: 从三种情况可以发现,连接到的 ip(VS 和 两个RS 的 ip 都一样)是随机的,因为三台 server 在同一
VLAN 下具有相同的 vip,故不能保证每次都会访问调度器。


解决:为了解决上面这个问题,需要设置禁止访问连接 RS。

RS(test2) :

[root@test2 ~]# yum install arptables_jf -y          //下载服务arptables
[root@test2 ~]# arptables -A IN -d 172.25.1.100 -j DROP        //目的是不允许客户端直接连接RS1
[root@test2 ~]# arptables -A OUT -s 172.25.1.100 -j mangle --mangle-ip-s 172.25.1.2       //允许VS与RS1连接
[root@test2 ~]# /etc/init.d/arptables_jf save       //保存该策略
[root@test2 ~]# cat /etc/sysconfig/arptables      //查看所写策略
# Generated by arptables-save v0.0.8 on Thu Sep 27 22:31:05 2018
*filter
:IN ACCEPT [0:0]
:OUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0][0:0] -A IN -d 172.25.1.100 -j DROP
[0:0] -A OUT -s 172.25.1.100 -j mangle --mangle-ip-s 172.25.1.2
COMMIT
# Completed on Thu Sep 27 22:31:05 2018

RS(test3)与test2步骤相同 :

[root@test3 ~]# arptables -nL      //用于查看 arptables 的具体内容
[root@test3 ~]# yum install arptables_jf -y   
[root@test3 ~]# arptables -A IN -d 172.25.1.100 -j DROP            //目的是不允许客户端直接连接RS2
[root@test3 ~]# arptables -A OUT -s 172.25.1.100 -j mangle --mangle-ip-s 172.25.1.3      //允许VS与RS1连接
[root@test3 ~]# /etc/init.d/arptables_jf save       //保存该策略
[root@test3 ~]# cat /etc/sysconfig/arptables
[root@test3 ~]# arptables -nL     //用于查看 arptables 的具体内容
# Generated by arptables-save v0.0.8 on Thu Sep 27 22:31:09 2018
*filter
:IN ACCEPT [1:28]
:OUT ACCEPT [1:28]
:FORWARD ACCEPT [0:0]
[0:0] -A IN -d 172.25.1.100 -j DROP
[0:0] -A OUT -s 172.25.1.100 -j mangle --mangle-ip-s 172.25.1.3
COMMIT
# Completed on Thu Sep 27 22:31:09 2018


客户端测试(172.25.1.250):
[root@foundation1 ~]# arp -an | grep 100
? (172.25.1.100) at 52:54:00:4f:1c:32 [ether] on br0
再次测试时 ip 的 mac 地址是VS 的

[root@foundation1 ~]# arp -d 172.25.1.100      //多次 down 掉后查看是否会依旧是VS的MAC地址
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>

问题:这种服务的缺点在于,如果后端服务器挂掉,比如说停掉 server 真实主机的 httpd 服务,
那么在客户端解析的时候们就会报错,但 server3 还会正常工作。这样用户就将得到错
误的信息:

[root@test2 ~]# /etc/init.d/httpd stop
Stopping httpd:
[ OK
[root@foundation1 ~]# curl 172.25.1.100
curl: (7) Failed connect to 172.25.1.100:80; Connection refused
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
curl: (7) Failed connect to 172.25.1.100:80; Connection refused
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>

总结: vs 对后端没有健康检查

解决这个问题的方法一:

   用 ldirectord 解决此问题


VS端:

[root@test1 ~]# vim /etc/yum.repos.d/rhel-source.repo                  //配置yum源,下载ldirectord服务
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.1.250/rhel6.5/HighAvailability
gpgcheck=0

[root@test1 ~]# ls
ldirectord-3.9.5-3.1.x86_64.rpm
[root@test1 ~]# yum install * -y
[root@test1 ~]# rpm -ql ldirectord       //查看配置文件
/usr/share/doc/ldirectord-3.9.5/ldirectord.cf
[root@test1 ~]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf  /etc/ha.d/       //拷贝一份到/etc/ha.d/
[root@test1 ~]# cd /etc/ha.d
[root@sest1 ha.d]# ls
ldirectord.cf resource.d shellfuncs
[root@test1 ha.d]# vim ldirectord.cf          //修改配置文件
virtual=172.25.1.100:80            //虚拟vip
real=172.25.1.2:80 gate           //真实服务器1的ip
real=172.25.1.3:80 gate           //真实服务器1的ip
fallback=127.0.0.1:80 gate
service=http
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcpchecktype=negotiate
checkport=80
request="index.html"
#receive="Test Page"
#virtualhost=www.x.y.z

[root@test1 ha.d]# ipvsadm -ln      //列出规则
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
TCP 172.25.1.100:80 rr
Route    1    0    3    -> 172.25.1.2:80
Route    1    0    2    -> 172.25.1.3:80

[root@test1 ~]# ipvsadm -C    //清理规则
[root@test1 ~]# ipvsadm -l      //查看是否已经清除
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
[root@test1 ha.d]# /etc/init.d/ldirectord start        //再次打开服务又可以加载出规则
Starting ldirectord... success
[root@test1 ha.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
TCP 172.25.1.100:80 rr
Route    1    0    3    -> 172.25.1.2:80
Route    1    0    2    -> 172.25.1.3:80

[root@test1 ha.d]# vim /etc/httpd/conf/httpd.conf          //修改端口为80
Listen 80
[root@test1 ha.d]# /etc/init.d/httpd start           //重起服务
[root@test1 ha.d]# cd /var/www/html/        
[root@test1 html]# vim index.html         //编辑下面内容
<h1>网站正在维护中......</h1>

客户端测试:


[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>

[root@test2 ~]# /etc/init.d/httpd stop        //若后台坏掉一个,则策略会自动更新
[root@test1 ha.d]# ipvsadm -ln                //可以看出已经实时更新坏掉的服务器
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
TCP 172.25.1.100:80 rr
-> 172.25.1.3:80
Route     1     0      2

客户端再次访问:

[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>

若两个真实服务器都挂掉:

[root@test3 ~]# /etc/init.d/httpd stop
[root@test1 ha.d]# ipvsadm -ln                    //可以看出已经没有正常的服务器了
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port
Forward Weight ActiveConn InActConn
TCP 172.25.1.100:80 rr
-> 127.0.0.1:80
Local 1    0     0

此时客户端再次访问:


[root@foundation1 ~]# curl 172.25.1.100
<h1>网站正在维护中......</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>网站正在维护中......</h1>
[root@foundation1 ~]# curl 172.25.1.100
<h1>网站正在维护中......</h1>

总结:
在客户端 curl 172.25.1.100 测试时, RS 轮询,当关闭 test2 时,只访问 test3,
RS 都关闭时会访问本地 test1,故显示“系统正在维护中......”

解决健康检查的方法二:

       用 keepalived 软件解决,

官网下载 keepalived 软件:http://www.keepalived.org/download.html

两个VS分别为:
主:test1
备:test4
VS 端分别安装 keepalived:

1.   安装keepalived服务

2.   ./configure -->openssl-devel -->  make --> make install

在主VR:test1下载keepalived服务

[root@test1 ~]# ls
keepalived-2.0.6.tar.gz
[root@test1 ~]# tar zxf keepalived-2.0.6.tar.gz                //解压压缩包
[root@test1 ~]# ls
keepalived-2.0.6 keepalived-2.0.6.tar.gz
[root@test1 keepalived-2.0.6]# ./configure --prefix=/usr/local/keepalived
--with-init=SYSV
[root@test1 keepalived-2.0.6]# yum install openssl-devel
[root@test1 keepalived-2.0.6]# ./configure --prefix=/usr/local/keepalived
--with-init=SYSV
[root@test1 keepalived-2.0.6]# make        //编译
[root@test1 keepalived-2.0.6]# make install
[root@test1 keepalived-2.0.6]# ln -s
/usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@test1 keepalived-2.0.6]# ln -s /usr/local/keepalived/etc/keepalived/
/etc/
[root@test1 keepalived-2.0.6]# ln -s
/usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@test1 keepalived-2.0.6]# ln -s /usr/local/keepalived/sbin/keepalived
/sbin/
[root@test1 keepalived-2.0.6]# cd /usr/local/
[root@test1 init.d]# chmod +x keepalived           //给keepalived执行权限
[root@test1 init.d]# /etc/init.d/keepalived start    //开启keepalived服务

在备VR:test4

创建一个虚拟机(test4:172.25.1.4),在备VR:test4下载与 test1 相同的服务 keepalived服务:

[root@test4 ~]# yum install openssh-clients -y
[root@test1 local]# scp -r keepalived/ root@172.25.1.4:/usr/local/       //将test1已经下载好的keepalived传给 test4
[root@test4 local]# ls
bin etc games include keepalived lib lib64 libexec sbin share src
[root@test4 ~]# ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
[root@test4 local]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/
[root@test4 local]# ln -s /usr/local/keepalived/etc/sysconfig/keepalived
/etc/sysconfig/
[root@test4 local]# ln -s /usr/local/keepalived/sbin/keepalived /sbin/
[root@test4 keepalived]# /etc/init.d/keepalived start


[root@test1 keepalived]# cd /etc/keepalived/
[root@test1 keepalived]# yum install mailx -y          //下载邮件服务
[root@test1 keepalived]# ip addr del 172.25.1.100/24 dev eth0      //删除虚拟ip
[root@test1 keepalived]# /etc/init.d/ldirectord stop
[root@test1 keepalived]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
link/ether 52:54:00:4f:1c:32 brd ff:ff:ff:ff:ff:ff
inet 172.25.1.1/24 brd 172.25.1.255 scope global eth0              //可以看到没有虚拟ip
inet6 fe80::5054:ff:fe4f:1c32/64 scope link

[root@test1 keepalived]# vim keepalived.conf            //修改内容
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost      
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 172.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
#vrrp_strict            //放弃修改防火墙规则

vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {

state MASTER         //MASTER表示主模式
interface eth0
virtual_router_id 1     
priority 100            //数值越大,优先级越高

advert_int 1
aauthentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.1.100           //虚拟ip地址
}
}
virtual_server 172.25.1.100 80 {            //虚拟ip地址 ,服务启动生效时会自动添加
delay_loop 6          //对后端的健康检查时间
lb_algo rr
lb_kind DR              //DR模式


#persistence_timeout 50          //注释持续连接 
protocol TCP
}
real_server 172.25.1.2 80 {        //RS1的ip
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 172.25.1.3 80 {       //RS2的ip
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}

[root@test1 keepalived]# /etc/init.d/keepalived restart

[root@test1 keepalived]# scp keepalived.conf root@172.25.1.4:/etc/keepalived/          //将配置文传给test4
[root@test4 keepalived]# cd /etc/keepalived/

[root@test4 keepalived]# yum install mailx -y
[root@test4 keepalived]# vim keepalived.conf
vrrp_instance VI_1 {
state BACKUP           //该为备模式
interface eth0
virtual_router_id 1 
priority 50                  //优先级要小于 test1 的优先级

[root@test4 keepalived]# >/var/log/messages    //清空日志
[root@test4 keepalived]# /etc/init.d/keepalived restart         //重起服务
[root@test4 keepalived]# cat /var/log/messages          //查看日志,可以看出test4做了BACKUP模式

客户端测试:

此时 test1 和 test4 的 keepalived 都是开启状态,其中 test1 做主,test4 做备

[root@foundation1 lvs]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 lvs]# arp -an | grep 100
? (172.25.1.100) at 52:54:00:4f:1c:32 [ether] on br0

从 MAC 地址可以看出走的是 test1。
若将 test1 的 keepalive 挂掉,则客户端依旧可以正常访问

[root@test1 keepalived]# /etc/init.d/ipvsadm stop
[root@foundation1 lvs]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>bbs.westos.org-server3</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>

从 MAC 地址可以看出走的是 test4。
将 test1 的 keepalived 开启,并 test3 的 http 服务关掉,则客户只能访问 test2 的

[root@test3 ~]# /etc/init.d/httpd stop
[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>
[root@foundation1 lvs]# curl 172.25.1.100
<h1>www.westos.org-server2</h1>

若将两个都挂掉,则 test1,则客户端直接不能正常访问,与 ldirectord 不同的是本地 test1
不会接替让 VS 访问

[root@foundation1 lvs]# curl 172.25.1.100
curl: (7) Failed connect to 172.25.1.100:80; Connection refused
[root@foundation1 lvs]# curl 172.25.1.100
curl: (7) Failed connect to 172.25.1.100:80; Connection refused
[root@foundation1 lvs]# curl 172.25.1.100
curl: (7) Failed connect to 172.25.1.100:80; Connection refused

相关文章:

【LeetCode】136. Single Number 解题小结

题目&#xff1a; Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 这题目的要求不仅是要求是线性时间…

iOS小技巧积累

平时项目中用到的&#xff0c;记录下来&#xff08;持续更新&#xff09;。1.在导航栏右边添加多个UIBarButtonItemUIBarButtonItem *searchScheduleBtn [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:"search_small"] style:UIBarButtonItemStylePl…

(转)iPhone开发经典语录集锦

1&#xff1a;如果无法保证子类行为的一致性&#xff0c;那么就用委托 If the subClass cannt keep with superClass,use delegate rather than inheritance. 2:屏幕上看到的&#xff0c;都是UIVew Everything you see on Screen is UIView. 3:如果对性能要求高&#xff0c;慎…

varnish 实现 CDN 缓存系统构建

cdn 搭建 (server1:172.25.1.1 ) : [roottest1 ~]# ls varnish-3.0.5-1.el6.x86_64.rpm varnish-libs-3.0.5-1.el6.x86_64.rpm [roottest1 ~]# yum install * -y [roottest1 ~]# cd /etc/varnish/ [roottest1 varnish]# vim /etc/sysconfig/varnish [roottest1 varnish]# sysct…

创建第一个 local network(I) - 每天5分钟玩转 OpenStack(80)

在 ML2 配置文件中 enable local network 后&#xff0c;本节将开始创建第一个 local network。 我们将通过 Web GUI 创建第一个 local network。 首先确保各个节点上的 neutorn agent 状态正常。GUI 菜单 为 Admin -> System -> System Infomation -> Neutron Agents…

【Android】AsyncTask异步类

一、关于AysncTask AsyncTask使得多线程编程更加简单&#xff0c;AsyncTask能在后台线程执行异步任务&#xff0c;并且在UI线程更新界面&#xff0c;而不再需要用户去操作Thread和Handler。AysncTask是一个抽象类&#xff0c;类关系如下&#xff1a; public abstract class As…

高手速成android开源项目【blog篇】

主要介绍那些乐于分享并且有一些很不错的开源项目的个人和组织。Follow大神&#xff0c;深挖大神的项目和following&#xff0c;你会发现很多。 一、个人 JakeWharton 就职于SquareGithub地址&#xff1a;https://github.com/JakeWharton代表作&#xff1a;ActionBarSherlock&a…

3、LVS_TUN实现负载均衡

LVS_TUN实现负载均衡 LVS 介绍: LVS 是 Linux Virtual Server 的简称,在实际环境中经常作为 B/S 结构的网络应用中的负载均衡器来使用,工作在 7 层网络模型中的,网络层,也就是通常说的 IP 层,由于数据的处理是在 Linux 内核态完成的,所以相对反向代理服务器来说,性能一般会高一…

【Android】Fragment官方中文文档

以下内容来自Android官方文档。 Fragment 表示 Activity 中的行为或用户界面部分。您可以将多个片段组合在一个 Activity 中来构建多窗格 UI&#xff0c;以及在多个 Activity 中重复使用某个片段。您可以将片段视为 Activity 的模块化组成部分&#xff0c;它具有自己的生命周期…

关于MSSQL导入导出时主键与约束丢失的问题解决

导入数据时&#xff0c;使用默认选项&#xff0c;会丢失主键、约束、默认值等属性&#xff0c;按如下步骤操作&#xff1a;-->导出向导 -->选择数据源 -->选择目的 -->指定表复制或查询&#xff1a;不要使用默认选项&#xff0c;选择“在SQL Server数据库之间复制对…

Java5中的线程池实例讲解

Java5增加了新的类库并发集java.util.concurrent&#xff0c;该类库为并发程序提供了丰富的API多线程编程在Java 5中更加容易&#xff0c;灵活。本文通过一个网络服务器模型&#xff0c;来实践Java5的多线程编程&#xff0c;该模型中使用了Java5中的线程池&#xff0c;阻塞队列…

LNMP架构的搭建

LNMP 架构的搭建 基础架构图 环境&#xff1a; server5: nginx mysql php //需要的安装包 (蓝色为解压后的文件) [roottest5 ~]# /etc/init.d/iptables stop //关掉防火墙 MYSQL 源码安装 [roottest6 ~]#yum install -y gcc gcc-c make ncurses-devel bison opens…

NSString属性什么时候用copy,什么时候用strong?

我们在声明一个NSString属性时&#xff0c;对于其内存相关特性&#xff0c;通常有两种选择(基于ARC环境)&#xff1a;strong与copy。那这两者有什么区别呢&#xff1f;什么时候该用strong&#xff0c;什么时候该用copy呢&#xff1f;让我们先来看个例子。 示例 我们定义一个类…

hihocoder 1152 Lucky Substrings

#1152 : Lucky Substrings 时间限制:10000ms单点时限:1000ms内存限制:256MB描述 A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empt…

随笔,记2014忆往昔岁月

博客园开通了一年多&#xff0c;这是第一篇博客。在此记下我的第一篇博客&#xff0c;同时&#xff0c;回忆过去几年自己的工作所得所想所感。 大学毕业&#xff0c;工作两年半了&#xff0c;做过很多事&#xff0c;比较杂&#xff0c;做过需求&#xff0c;做过设计&#xff0c…

PHP相关关系及定义

CGI(是一种协议): 是为了保证web server传递过来的数据是标准格式的&#xff0c;方便CGI程序的编写者。 web server&#xff08;如nginx&#xff09;是内容的分发者。 处理静态页面&#xff1a; 如果请求/index.html&#xff0c;web server就可以解…

Apache优化:修改最大并发连接数

http://www.365mini.com/page/apache-concurrency-configuration.htm Apache是一个跨平台的web服务器&#xff0c;由于其简单高效、稳定安全的特性&#xff0c;被广泛应用于计算机技术的各个领域。现在&#xff0c;Apache凭借其庞大的用户数&#xff0c;已成为用户数排名第一的…

黑马程序员___Java基础[02-Java基础语法](一)

Java语言基础组成 一、关键字 1)定义&#xff1a;被Java语言赋予了特殊含义的单词 2)特点&#xff1a;关键字中所有字母均为小写 3)作用及分类&#xff1a; 下面是Java语言保留专用的50个关键字&#xff1a; 用于定义数据类型的关键字&#xff08;12个&#xff09;&#xff1a;…

NSLog打印自定义对象

我们在开发中&#xff0c;如果直接使用NSLog打印对象&#xff0c;则会打印对象的指针&#xff08;如下图&#xff09; 但我们常常希望打印的是对象的属性的值&#xff0c;因此我们需要重写自定义类的description方法&#xff08;打印日志时&#xff0c;对象会收到description消…

数据库的安装与管理

数据库的安装与管理 1.mysql数据库的安装 yum install mariadb-server -y systemctl start mariadb ##开启数据库 netstat -antlupe | grep mysql ##查看端口 vim /etc/my.cnf ##修改配置文件。添加skip-networking1 systemctl restart mariadb ##重起服务 netstat -antlupe |…

SQL性能优化没有那么神秘

经常听说SQL Server最难的部分是性能优化&#xff0c;不禁让人感到优化这个工作很神秘&#xff0c;这种事情只有高手才能做。很早的时候我在网上看到一位高手写的博客&#xff0c;介绍了SQL优化的问题&#xff0c;从这些内容来看&#xff0c;优化并不都是一些很复杂的问题&…

腾讯云无法绑定公网IP问题解释与解决方案。

腾讯云无法绑定公网IP问题解释与解决方案。 http://blog.csdn.net/chenggong2dm/article/details/51475222 解释&#xff1a;公网IP并不直接配置在服务器上&#xff0c;而是在服务器外部的路由上&#xff0c;通过某种映射连接。 解决方案&#xff1a;绑定0.0.0.0 posted on 201…

iOS Category小举例

&#xff08;一&#xff09;Category作用&#xff1a;Category可以向已存在的类添加新的方法&#xff0c;或者覆盖原来类中已经存在的方法&#xff0c;从而扩展已有类&#xff08;在Java中为了实现类似功能&#xff0c;一般是创建子类&#xff09; &#xff08;二&#xff09;C…

memcache

nginxphpmemcache缓存 图解&#xff1a; [roottest5 ~]# /etc/init.d/iptables stop [roottest5 ~]# nginx [roottest5 ~]# /etc/init.d/php-fpm start Starting php-fpm done [roottest5 ~]# tar zxf memcache-2.2.5.tgz [roottest5 ~]# cd memcache-2.2.5 [roottest5…

iOS中KVO模式的解析与应用

最近老翁在项目中多处用到了KVO&#xff0c;深感这种模式的好处。现总结如下&#xff1a; 一、概述 KVO,即&#xff1a;Key-Value Observing&#xff0c;它提供一种机制&#xff0c;当指定的对象的属性被修改后&#xff0c;则对象就会接受到通知。简单的说就是每次指定的被观察…

C 到C++的升级

C所有的变量都可以在需要使用时再定义。 C语言中的变量都必须在作用域开始的位置定义。 register 关键字请求编译器将局部变量存储于寄存器中 在C语言无法获取register 变量的地址 在C中可以取得 register 变量的地址 C编译器有自己的优化方式&#xff0c;所以几乎不用registe…

SET QUOTED_IDENTIFIER OFF语句的作用

先看下面几个sql语句 1SETQUOTED_IDENTIFIER ON2SELECT*FROM"USER" WHEREanetasp34SETQUOTED_IDENTIFIER ON5SELECT*FROM[USER]WHEREanetasp67SETQUOTED_IDENTIFIER OFF8SELECT*FROM[USER]WHEREa"netasp" 910SETQUOTED_IDENTIFIER OFF11SELECT*FROM[USE…

proxy实现 mysql 读写分离

实现 mysql 读写分离 图解: 环境: iptables 和 selinux 关闭 proxy:test2 172.25.1.2 Master: test3 172.25.1.3 Slave:test4 172.25.1.4 环境已经实现 test3(master) 和 test4(slave) 的主从复制 Server2: [roottest2 ~]# ls mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz …

iOS开发中用到的一些第三方库

下面是我在开发中用到的一些优秀的iOS第三方开源库&#xff1a; 1.AFNetworking&#xff08;网络请求&#xff0c;类似的还有ASIHTTPRequest&#xff09; https://github.com/AFNetworking/AFNetworking/ 2.MBProgressHUD&#xff08;提示框&#xff09; https://github.…

小图标外链API

网页上有些分享的小图标&#xff0c;比如分享到facebook&#xff0c;weibo&#xff0c;qq空间等功能的时候&#xff0c;图标以前一般是自己做一个css sprite。当一个网站的图标变了的时候&#xff0c;比如facebook变成assbook的时候&#xff0c;你就要修改这个css sprite。费时…