集群三 php+memcached缓存服务器

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDSClaw,2核4GB
RDS AI 助手,专业版
简介:
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,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
应用服务中间件 PHP nginx
当你的nginx服务器和php服务器不在一起的时候,这个nginx 的root目录问题
两个服务器的网站代码目录需要对齐,docker容器里面也是一样
|
XML 前端开发 JavaScript
PHP与Ajax在Web开发中的交互技术。PHP作为服务器端脚本语言,处理数据和业务逻辑
本文深入探讨了PHP与Ajax在Web开发中的交互技术。PHP作为服务器端脚本语言,处理数据和业务逻辑;Ajax则通过异步请求实现页面无刷新更新。文中详细介绍了两者的工作原理、数据传输格式选择、具体实现方法及实际应用案例,如实时数据更新、表单验证与提交、动态加载内容等。同时,针对跨域问题、数据安全与性能优化提出了建议。总结指出,PHP与Ajax的结合能显著提升Web应用的效率和用户体验。
364 3
|
监控 PHP Apache
优化 PHP-FPM 参数配置:实现服务器性能提升
优化PHP-FPM的参数配置可以显著提高服务器的性能和稳定性。通过合理设置 `pm.max_children`、`pm.start_servers`、`pm.min_spare_servers`、`pm.max_spare_servers`和 `pm.max_requests`等参数,并结合监控和调优措施,可以有效应对高并发和负载波动,确保Web应用程序的高效运行。希望本文提供的优化建议和配置示例能够帮助您实现服务器性能的提升。
1020 3
|
存储 缓存 NoSQL
【赵渝强老师】Memcached集群的架构
Memcached 是一个高性能的分布式内存对象缓存系统,通过在内存中维护一个巨大的 Hash 表来存储各种格式的数据,如图像、视频、文件及数据库检索结果等。它主要用于减轻数据库压力,提高网站系统的性能。Memcached 不支持数据持久化,因此仅作为缓存技术使用。其数据分布式存储由客户端应用程序实现,而非服务端。
416 0
【赵渝强老师】Memcached集群的架构
|
自然语言处理 编译器 应用服务中间件
PHP在服务器上的运行过程
PHP在服务器上的运行过程
296 7
|
缓存 监控 定位技术
|
PHP 开发者
PHP作为一门流行的服务器端脚本语言,深入理解PHP的命名空间
【10月更文挑战第22天】PHP作为一门流行的服务器端脚本语言,自1995年诞生以来,已经发展了二十多年。在这二十多年的时间里,PHP经历了多次重大版本的更新,不断增加新特性和改进。其中,命名空间(Namespace)是PHP 5.3.0引入的一个重要特性,它为PHP的代码组织和重用提供了一种新的方式。本文将从三个部分深入理解PHP的命名空间:一是命名空间的基本概念和作用;二是PHP命名空间的使用方法;三是通过实例讲解命名空间的应用。
169 4
|
缓存 NoSQL Ubuntu
大数据-39 Redis 高并发分布式缓存 Ubuntu源码编译安装 云服务器 启动并测试 redis-server redis-cli
大数据-39 Redis 高并发分布式缓存 Ubuntu源码编译安装 云服务器 启动并测试 redis-server redis-cli
253 3
|
Java PHP
PHP作为广受青睐的服务器端脚本语言,在Web开发中占据重要地位。理解其垃圾回收机制有助于开发高效稳定的PHP应用。
【10月更文挑战第1天】PHP作为广受青睐的服务器端脚本语言,在Web开发中占据重要地位。其垃圾回收机制包括引用计数与循环垃圾回收,对提升应用性能和稳定性至关重要。本文通过具体案例分析,详细探讨PHP垃圾回收机制的工作原理,特别是如何解决循环引用问题。在PHP 8中,垃圾回收机制得到进一步优化,提高了效率和准确性。理解这些机制有助于开发高效稳定的PHP应用。
218 3
|
6月前
|
缓存 负载均衡 监控
135_负载均衡:Redis缓存 - 提高缓存命中率的配置与最佳实践
在现代大型语言模型(LLM)部署架构中,缓存系统扮演着至关重要的角色。随着LLM应用规模的不断扩大和用户需求的持续增长,如何构建高效、可靠的缓存架构成为系统性能优化的核心挑战。Redis作为业界领先的内存数据库,因其高性能、丰富的数据结构和灵活的配置选项,已成为LLM部署中首选的缓存解决方案。
659 25