集群三 php+memcached缓存服务器

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
nginx+php 安装
yum -y  install  gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel  bzip2  bzip2 -devel ncurses ncurses-devel gd gd-devel curl curl-devel e2fsprogs e2fsprogs-devel  krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel ImageMagick ImageMagick-devel git
 
mkdir  /hequan  &&  cd  /hequan
wget http: //cn2 .php.net /distributions/php-5 .6.22. tar .bz2
wget http: //ncu .dl.sourceforge.net /project/mhash/mhash/0 .9.9.9 /mhash-0 .9.9.9. tar .gz
wget http: //nchc .dl.sourceforge.net /project/mcrypt/Libmcrypt/2 .5.8 /libmcrypt-2 .5.8. tar .gz
wget http: //nchc .dl.sourceforge.net /project/mcrypt/MCrypt/2 .6.8 /mcrypt-2 .6.8. tar .gz
wget http: //ftp .gnu.org /pub/gnu/libiconv/libiconv-1 .14. tar .gz
wget http: //pecl .php.net /get/memcache-2 .2.7.tgz
wget http: //xcache .lighttpd.net /pub/Releases/3 .2.0 /xcache-3 .2.0. tar .gz
wget http: //pecl .php.net /get/imagick-3 .1.2.tgz
git clone https: //github .com /cfsego/ngx_log_if .git
php安装简单版
. /configure  --prefix= /usr/local/php  --with-config- file -path= /etc  --with-mysql --with-mysqli \
--with-config- file -scan- dir = /etc/php .d -- enable -fpm --with-gd --with-iconv \
--with-zlib -- enable -xml -- enable -inline-optimization --with-openssl -- enable -pcntl \
-- enable -zip --with-curl --with-bz2 --with-jpeg- dir  --with-png- dir  -- enable -mbstring
 
tar  -zvxf libiconv-1.14. tar .gz
cd  libiconv-1.14 /srclib
sed  -i -e  '/gets is a security/d'  . /stdio . in .h
cd  ../
. /configure  --prefix= /application/
make
make  install
cd  /hequan
tar  -zxvf libmcrypt-2.5.8. tar .gz
cd  libmcrypt-2.5.8/
. /configure
make
make  install
cd  libltdl/
. /configure  -- enable -ltdl- install
make
make  install
cd  /hequan
tar  -zxvf mhash-0.9.9.9. tar .gz
cd  mhash-0.9.9.9/
. /configure
make
make  install
ln  -s  /usr/local/lib/libmcrypt .la  /usr/lib/libmcrypt .la
ln  -s  /usr/local/lib/libmcrypt .so  /usr/lib/libmcrypt .so
ln  -s  /usr/local/lib/libmcrypt .so.4  /usr/lib/libmcrypt .so.4
ln  -s  /usr/local/lib/libmcrypt .so.4.4.8  /usr/lib/libmcrypt .so.4.4.8
ln  -s  /usr/local/lib/libmhash .a  /usr/lib/libmhash .a
ln  -s  /usr/local/lib/libmhash .la  /usr/lib/libmhash .la
ln  -s  /usr/local/lib/libmhash .so  /usr/lib/libmhash .so
ln  -s  /usr/local/lib/libmhash .so.2  /usr/lib/libmhash .so.2
ln  -s  /usr/local/lib/libmhash .so.2.0.1  /usr/lib/libmhash .so.2.0.1
ln  -s  /usr/local/bin/libmcrypt-config  /usr/bin/libmcrypt-config
cd  /hequan
tar  -zxvf mcrypt-2.6.8. tar .gz
cd  mcrypt-2.6.8
export  LD_LIBRARY_PATH= /usr/local/lib : LD_LIBRARY_PATH
. /configure
make
make  install
cd  /hequan/
tar  -jxvf php-5.6.22. tar .bz2
cd  php-5.6.22
. /configure  --prefix= /usr/local/php  --with-config- file -path= /application/php/etc  -- enable -fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv- dir  --with-freetype- dir  --with-jpeg- dir  --with-png- dir  --with-zlib --with-libxml- dir = /usr  -- enable -xml --disable-rpath -- enable -magic-quotes -- enable -safe-mode -- enable -bcmath -- enable -shmop -- enable -sysvsem -- enable -inline-optimization --with-curl --with-curlwrappers -- enable -mbregex -- enable -mbstring --with-mcrypt -- enable - ftp  --with-gd -- enable -gd-native-ttf --with-openssl --with-mhash -- enable -pcntl -- enable -sockets --with-xmlrpc -- enable -zip -- enable -soap --without-pear --with-gettext --disable-fileinfo -- enable -maintainer-zts
make  ZEND_EXTRA_LIBS= '-liconv'
make  install
cp  php.ini-production  /usr/local/php/etc/php .ini
cp  sapi /fpm/init .d.php-fpm  /etc/init .d /php-fpm
chmod  u+x  /etc/init .d /php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
groupadd www
useradd  -s  /sbin/nologin  -g www -M www
mv  /usr/local/php/etc/php-fpm .conf.default  /usr/local/php/etc/php-fpm .conf
ln  -s  /usr/local/php/etc/php .ini  /etc/php .ini
ln  -s  /usr/local/php/etc/php-fpm .conf  /etc/php-fpm .conf
  /usr/local/php/sbin/php-fpm
iptables -I INPUT -s 172.16.10.0 /24  -p tcp --dport 9000 -j ACCEPT
zlib====》提供数据压缩用的函式库
pcre====》rewrite的支持库
openssl====》https的支持库
libiconv====》字符编码转换库
libxml====》XML库
libpng====》图片库
freetype====》字库
libmcrypt====》加密算法
mhash====》加密库
curl====》URL传输
gd====》绘图
 
 
yum -y  install   nfs 
vim  /etc/exports
/data/web/       192.168.50.58 /24 (rw, sync )
/data/web/       192.168.50.59 /24 (rw, sync )
/data/web/       192.168.50.60 /24 (r, sync )
/data/web/       192.168.50.61 /24 (r, sync )
systemctl rstart nfs.service
systemctl  enable  nfs.service  
yum  install  nfs-utils  -y
showmount -e  192.168.50.62
mkdir  -p  /data/web/
mount  -t nfs 192.168.50.62: /data/web/   /data/web
  echo  "<h1>DynamicServer is Health.</h1> "   /data/web/www/health .php
  echo  "<h1>StaticServer  is Health.</h1> "    >   /data/web/www/health .html
Memcached 安装
 
下载
cd  /tmp
wget http: //downloads .sourceforge.net /levent/libevent-2 .0.22-stable. tar .gz
wget http: //www .memcached.org /files/memcached-1 .4.33. tar .gz
 
tar  zxvf libevent-2.0.22-stable. tar .gz
cd  libevent-2.0.22-stable
. /configure   -prefix= /usr/local/
make  &&  make  install
ls  -al  /usr/local/lib  grep  libevent-   
 
 
cd  /tmp
tar  zxvf memcached-1.4.33. tar .gzsgh5+9
cd  memcached-1.4.33
. /configure   --with-libevent= /usr/local/  -- enable -64bit -- enable -threads
make  &&  make  install
ls  -al  /usr/local/bin/memcached   0sac
 
groupadd memcached
useradd  -g memcached memcached
 
cd  /var/run
mkdir  memcached
chown  -R memcached.memcached memcached
 
cp  /tmp/memcached-1 .4.33 /scripts/memcached .sysv  /etc/init .d /memcached
chown  memcached.memcached  /etc/init .d /memcached
chmod  755  /etc/init .d /memcached
 
vim  /etc/init .d /memcached
PORT=11211
 
USER=memcached
 
MAXCONN=1024
 
CACHESIZE=128
 
OPTIONS=””
 
chown  $USER  /usr/local/bin/memcached
 
/usr/local/bin/memcached  –d –p $PORT –u $USER –m $CACHESIZE –c $MAXCONN –P  /var/run/memcached/memcached .pid $OPTIONS
 
 
启动
chkconfig --add memcached
chkconfig --level 235 memcached on
chkconfig --list memcached
 
service memcached start
ps  -ef |  grep  memcached
service memcached stop
magent安装
cd  /usr/local   
mkdir  magent   
cd  magent
tar  zxvf magent-0.5. tar .gz
vim ketama.h           #在开头添加这三行
#ifndef SSIZE_MAX   
#define SSIZE_MAX 32767   
#endif
ln  -s  /usr/lib64/libm .so  /usr/lib64/libm .a
/sbin/ldconfig
sed  -i  "s#LIBS = -levent#LIBS = -levent -lm#g"  Makefile   
vi  Makefile
CFLAGS = -lrt -Wall -O2 -g   #修改这行
make
 
keepalived设置
 
主memcache:    开机不启动keepalved  memcached 
vim   /etc/keepalived/keepalived .conf
! Configuration File  for  keepalived   
global_defs {
  router_id  mem1
}
vrrp_script chk_magent {
   script  "/opt/magent.sh"
   interval 2
}
vrrp_script chk_memcached {
    script  "killall -0 memcached"
    interval 1
    weight -20
}
vrrp_instance VI_1 {
     state MASTER
     interface eth0
     virtual_router_id  101
     priority 100
     advert_int 1
     authentication {
         auth_type PASS
         auth_pass 1111
     }
     virtual_ipaddress {
         192.168.50.199 /24
     }
     track_script {
         chk_magent
             chk_memcached
         }
    notify_master   "/etc/keepalived/changemail.py master"
    notify_backup    "/etc/keepalived/changemail.py backup"
    notify_fault     "/etc/keepalived/changemail.py fault"
}
vim   /opt/magent .sh
#!/bin/bash
k=` ps  -ef | grep  keepalived | grep  - v  grep  | wc  -l`
if  [ $k -gt 0 ]; then
     /usr/local/magent/magent   -u root -n 51200 -l 192.168.50.199 -p 12000 -s 192.168.50.63:11211 -b 192.168.50.64:11211
else
pkill -9 magent
fi
 
备用memcache:
vim  /etc/keepalived/keepalived .conf
! Configuration File  for  keepalived   
global_defs {
  router_id  mem2
}
vrrp_script chk_magent {
         script  "/opt/magent.sh"
         interval 2
}
vrrp_script chk_memcached {
    script  "killall -0 memcached"
    interval 1
    weight -20
}
vrrp_instance VI_1 {
     state BACKUP
     interface eth0
     virtual_router_id  101
     priority 90
     advert_int 1
     authentication {
         auth_type PASS
         auth_pass 1111
     }
     virtual_ipaddress {
         192.168.50.199 /24
     }
     track_script {
        chk_magent
           chk_memcached
         }
    notify_master   "/etc/keepalived/changemail.py master"
    notify_backup    "/etc/keepalived/changemail.py backup"
    notify_fault     "/etc/keepalived/changemail.py fault"
}
vim  /opt/magent .sh
#!/bin/bash
k=`ip a | grep  192.168.50.199 | wc  -l`
if  [ $k -gt 0 ]; then
         /usr/local/magent/magent  -u root -n 51200 -l 192.168.50.199 -p 12000 -s 192.168.50.53:11211 -b 192.168.50.64:11211
else
pkill -9 magent
fi
 
注意:如果将故障的memcached节点修复后,缓存是不会再通过到已修复的节点上的,如果是magent指定的主节点故障,那么主节点的缓存数据会丢失,修复后不能立刻重启memcached服务,如果重启,客户端会去查询主节点的数据。并发高的网站会拖死数据库。因此,建议一般业务低峰期的时候再启动memcached主节点服务。然后通过magent再指定主缓存节点和备缓存节点。
 
1.若memcached读写的数据多,一定将关掉防火墙或将防火墙设置为不使用跟踪链接表,否则会导致 /var/log/message 报错“kernel: nf_conntrack: table full, dropping packet”,详情请参考本博客中的博文http: //blog .csdn.net /yanggd1987/article/details/45886913
2.使用service iptables stop关掉,并且不能用iptables -L -vnx查看,因此使用此命令会将防火墙开启,虽然规则是清空的,但仍会记录连接跟踪表。
 
https: //my .oschina.net /kisops/blog/150995
安装php扩展
cd  /tmp
tar  zxvf  /software/memcache-3 .0.8.tgz -C  /tmp
cd  memcache-3.0.8
/usr/local/php/bin/phpize
. /configure  -- enable -memcache --with-php-config= /usr/local/php/bin/php-config  --with-zlib- dir
make
make  install
vim  /usr/local/php/etc/php .ini
extension_dir =  "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"
extension=memcache.so
[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
发布discuz
unzip  /software/Discuz_X3 .2_SC_UTF8.zip -d  /discuz/
chmod  -R 777  /discuz/
#开启memcache支持
vim  /discuz/upload/config/config_global .php
$_config[ 'memory' ][ 'memcache' ][ 'server' ] =  '192.168.50.199' ;   #magent代理服务器地址
$_config[ 'memory' ][ 'memcache' ][ 'port' ] = 12000;
$_config[ 'memory' ][ 'memcache' ][ 'pconnect' ] = 1;
$_config[ 'memory' ][ 'memcache' ][ 'timeout' ] = 1;
 
yum  install  -y telnet
telnet 192.168.50.199  12000
stats
STAT cmd_get 199
STAT cmd_set 37
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 167
STAT get_misses 32









本文转自 295631788 51CTO博客,原文链接:http://blog.51cto.com/hequan/1886309,如需转载请自行联系原作者
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
4月前
|
缓存 NoSQL PHP
Redis作为PHP缓存解决方案的优势、实现方式及注意事项。Redis凭借其高性能、丰富的数据结构、数据持久化和分布式支持等特点,在提升应用响应速度和处理能力方面表现突出
本文深入探讨了Redis作为PHP缓存解决方案的优势、实现方式及注意事项。Redis凭借其高性能、丰富的数据结构、数据持久化和分布式支持等特点,在提升应用响应速度和处理能力方面表现突出。文章还介绍了Redis在页面缓存、数据缓存和会话缓存等应用场景中的使用,并强调了缓存数据一致性、过期时间设置、容量控制和安全问题的重要性。
84 5
|
4月前
|
存储 缓存 NoSQL
【赵渝强老师】Memcached集群的架构
Memcached 是一个高性能的分布式内存对象缓存系统,通过在内存中维护一个巨大的 Hash 表来存储各种格式的数据,如图像、视频、文件及数据库检索结果等。它主要用于减轻数据库压力,提高网站系统的性能。Memcached 不支持数据持久化,因此仅作为缓存技术使用。其数据分布式存储由客户端应用程序实现,而非服务端。
133 0
【赵渝强老师】Memcached集群的架构
|
4月前
|
缓存 监控 定位技术
|
5月前
|
存储 缓存 分布式计算
大数据-89 Spark 集群 RDD 编程-高阶 编写代码、RDD依赖关系、RDD持久化/缓存
大数据-89 Spark 集群 RDD 编程-高阶 编写代码、RDD依赖关系、RDD持久化/缓存
80 4
|
5月前
|
缓存 NoSQL Ubuntu
大数据-39 Redis 高并发分布式缓存 Ubuntu源码编译安装 云服务器 启动并测试 redis-server redis-cli
大数据-39 Redis 高并发分布式缓存 Ubuntu源码编译安装 云服务器 启动并测试 redis-server redis-cli
93 3
|
5月前
|
缓存 NoSQL 数据处理
原生php实现redis缓存配置和使用方法
通过上述步骤,你可以在PHP项目中配置并使用Redis作为高性能的缓存解决方案。合理利用Redis的各种数据结构和特性,可以有效提升应用的响应速度和数据处理效率。记得在实际应用中根据具体需求选择合适的缓存策略,如设置合理的过期时间,以避免内存过度消耗。
117 0
|
6月前
|
XML 存储 缓存
Squid 缓存服务器配置
Squid 缓存服务器配置
216 0
|
7月前
|
缓存 应用服务中间件 nginx
Web服务器的缓存机制与内容分发网络(CDN)
【8月更文第28天】随着互联网应用的发展,用户对网站响应速度的要求越来越高。为了提升用户体验,Web服务器通常会采用多种技术手段来优化页面加载速度,其中最重要的两种技术就是缓存机制和内容分发网络(CDN)。本文将深入探讨这两种技术的工作原理及其实现方法,并通过具体的代码示例加以说明。
703 1
|
7月前
|
缓存 NoSQL 网络安全
【Azure Redis 缓存】使用开源工具redis-copy时遇见6379端口无法连接到Redis服务器的问题
【Azure Redis 缓存】使用开源工具redis-copy时遇见6379端口无法连接到Redis服务器的问题
101 0
|
2天前
|
消息中间件 缓存 NoSQL
缓存与数据库的一致性方案,Redis与Mysql一致性方案,大厂P8的终极方案(图解+秒懂+史上最全)
缓存与数据库的一致性方案,Redis与Mysql一致性方案,大厂P8的终极方案(图解+秒懂+史上最全)

热门文章

最新文章