阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Debian8(amd64)安装部署Memcached管理工具MemAdmin

140次阅读
没有评论

共计 9562 个字符,预计需要花费 24 分钟才能阅读完成。

目录
1、memadmin 工具简介
2、nginx 及 php 环境安装
3、memadmin 工具部署
4、memadmin 工具的简单运用
5、额外的配置优化
6、总结

1、memadmin 工具简介
MemAdmin 是一款可视化的 Memcached 管理与监控工具,使用 PHP 开发,体积小,操作简单。
主要功能:
服务器参数监控:STATS、SETTINGS、ITEMS、SLABS、SIZES 实时刷新
服务器性能监控:GET、DELETE、INCR、DECR、CAS 等常用操作命中率实时监控
支持数据遍历,方便对存储内容进行监视
支持条件查询,筛选出满足条件的 KEY 或 VALUE
数组、JSON 等序列化字符反序列显示
兼容 memcache 协议的其他服务,如 Tokyo Tyrant (遍历功能除外)
支持服务器连接池,多服务器管理切换方便简洁

2、nginx 及 php 环境安装

2.1、安装 nginx
1234567 root@com:~# uname -r
3.16.0-4-amd64
root@com:~# cat /etc/issue
Debian GNU/Linux 8 \n \l
root@test1:~# apt-get install nginx
root@test1:~# chkconfig –list nginx
nginx                    0:off  1:off  2:on  3:on  4:on  5:on  6:off

浏览器访问可见 nginx 的默认页面,如下:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

2.2、php 环境部署
root@test1:~# apt-get install php5-fpm
root@test1:~# dpkg -L php5-fpm
/.
/etc
/etc/php5
/etc/php5/fpm
/etc/php5/fpm/conf.d
/etc/php5/fpm/pool.d
/etc/php5/fpm/pool.d/www.conf    #这个是 php5-fpm 的配置文件
/etc/php5/fpm/php-fpm.conf
/etc/logrotate.d
/etc/logrotate.d/php5-fpm
/etc/init
/etc/init/php5-fpm.conf
/etc/init.d
/etc/init.d/php5-fpm
/usr
/usr/sbin
/usr/sbin/php5-fpm
/usr/lib
/usr/lib/php5
/usr/lib/php5/20131226
/usr/lib/php5/php5-fpm-checkconf
/usr/lib/php5/php5-fpm-reopenlogs
/usr/share
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/php5-fpm.8.gz
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/php5-fpm
/usr/share/php5
/usr/share/php5/sapi
/usr/share/php5/sapi/fpm
/usr/share/bug
/usr/share/bug/php5-fpm
/usr/share/bug/php5-fpm/script
/usr/share/bug/php5-fpm/control
/usr/share/doc
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/php5-fpm.service
/usr/share/doc/php5-fpm

root@test1:~# vim /etc/php5/fpm/pool.d/www.conf
#listen = /var/run/php5-fpm.sock      注释此行,这不是必须的,只是我习惯让 php5-fpm 监听在一个端口而不是 sock 上
listen = 9000                                    增加此行使 php5-fpm 监听在 9000 端口
root@test1:~# /etc/init.d/php5-fpm restart
[ok] Restarting php5-fpm (via systemctl): php5-fpm.service.
root@test1:~# ss -tnl | grep 9000
LISTEN    0      128                      *:9000                    *:*

root@test1:~# vim /etc/nginx/sites-enabled/default   
# 修改 nginx 配置,使其能把 php 的请求转发到 php5-fpm,在“#location ~ \.php$ {”代码块的下方增加如下代码:
      location ~ \.php$ {
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
                include        fastcgi_params;
        }
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@test1:~# vim /var/www/html/info.php
<?php
    phpinfo();
?>
root@test1:~# nginx -t
root@test1:~# /etc/init.d/nginx restart
[ok] Restarting nginx (via systemctl): nginx.service.

浏览器打开 php 的测试面试,如下:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

3、memadmin 工具部署及简单运用

123456 root@test1:~# ls
memadmin-1.0.12.tar.gz
root@test1:~# tar xf memadmin-1.0.12.tar.gz -C /var/www/html/
root@test1:~# cd /var/www/html/
root@test1:/var/www/html# ls
index.nginx-debian.html  info.php  memadmin

访问 memadmin 测试,如下:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

报错了,根据错误提示安装 memcache 的扩展支持:
root@test1:/var/www/html# apt-get install php5-memcache
root@test1:/var/www/html# dpkg -L php5-memcache
/.
/usr
/usr/lib
/usr/lib/php5
/usr/lib/php5/20131226
/usr/lib/php5/20131226/memcache.so      #库文件在这里
/usr/share
/usr/share/doc
/usr/share/doc/php5-memcache
/usr/share/doc/php5-memcache/examples
/usr/share/doc/php5-memcache/examples/memcache.php.gz
/usr/share/doc/php5-memcache/examples/example.php
/usr/share/doc/php5-memcache/changelog.Debian.gz
/usr/share/doc/php5-memcache/copyright
/usr/share/doc/php5-memcache/memcache.php.gz
/usr/share/doc/php5-memcache/changelog.gz
/usr/share/doc/php5-memcache/package.xml.gz
/usr/share/doc/php5-memcache/README.gz
/usr/share/doc/php5-memcache/CREDITS
/usr/share/doc/php5-memcache/example.php
/usr/share/php
/usr/share/php/.registry
/usr/share/php/.registry/.channel.pecl.php.net
/usr/share/php/.registry/.channel.pecl.php.net/memcache.reg
/etc
/etc/php5
/etc/php5/mods-available
/etc/php5/mods-available/memcache.ini

root@test1:/var/www/html# vim /etc/php5/fpm/php.ini
# 搜索“extension”关键字,在“; extension_dir = “ext””下增加下边的代码
extension_dir = “/usr/lib/php5/20131226”
extension = memcache.so
root@test1:/var/www/html# /etc/init.d/php5-fpm restart
[ok] Restarting php5-fpm (via systemctl): php5-fpm.service.

再次访问测试页面,如下,有 memcache 的相关信息:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

再访问 memadmin 的页面,如下:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

至此,memadmin 工具部署完成。
4、memadmin 工具的简单运用

默认时 memadmin 工具的登陆用户名及密码都为 admin,可以在配置文件中进行更改,如下:
root@test1:/var/www/html# pwd
/var/www/html
root@test1:/var/www/html# vim memadmin/config.php
<?php
if (!defined(‘IN_MADM’)) exit();
$config[‘user’] = “admin”; // your username
$config[‘passwd’] = “admin”; // your password
………

登陆 memadmin 后是如下页面:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

点击“添加”后,memcached 就被添加到“服务器连接列表”中,如下:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

再点击“开始管理”后,就可察看 memcached 服务器的监控信息,如下图:

Debian8(amd64)安装部署 Memcached 管理工具 MemAdmin

接下来就摸索着使用这工具吧!
5、额外的配置优化

    现在,我们是可以尽情的使用 memadmin 这工具了,但此服务器的主要功能是提供 memcached 服务,而 memadmin 只是一个对 memcached 的管理工具而已,使用频率并不是特别高,所以,分配给 nginx,php5-fpm 的资源只需要一点即可,特别是在你服务器资源很紧张的情况下更应该对 nginx 和 php5-fpm 这两个服务进行优化。
5.1、nginx 优化
    先来看看默认时 nginx 的工作特性,如下:
root@test1:~# pgrep nginx
11748
11750
11751
11752
11753
root@test1:~# ps aux | grep nginx
root      11748  0.0  0.3  91172  3064 ?        Ss  12:25  0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  11750  0.0  0.4  91816  4776 ?        S    12:25  0:01 nginx: worker process                         
www-data  11751  0.0  0.4  91828  5028 ?        S    12:25  0:00 nginx: worker process                         
www-data  11752  0.0  0.3  91476  3752 ?        S    12:25  0:01 nginx: worker process                         
www-data  11753  0.0  0.3  91476  3752 ?        S    12:25  0:01 nginx: worker process                         
root      12909  0.0  0.2  12948  2196 pts/1    S+  15:53  0:00 grep nginx
# 默认时,nginx 有一个主进程,4 个 worker 进程

1234 root@test1:~# ss -tnl | grep 80
LISTEN    0      128                      *:80                      *:*   
LISTEN    0      128                      :::80                      :::* 
# 默认时,nginx 监听了 IPV6 的地址

针对我这里的环境,nginx 只需要开启一个 worker 进程即可,对 IPV6 地址的监听也没有必要,所以做如下修改:
root@test1:~# find /etc/nginx/* -type f | xargs grep “worker_processes”
/etc/nginx/nginx.conf:worker_processes 4;
root@test1:~# vim /etc/nginx/nginx.conf 
worker_processes 1;  #修改为“1”
root@test1:~# find /etc/nginx/* -type f | xargs grep “listen 80”
/etc/nginx/sites-available/default:listen 80 default_server;
/etc/nginx/sites-available/default:#listen 80;
root@test1:~# vim /etc/nginx/sites-available/default
…..
server {
        listen 80 default_server;
        #listen [::]:80 default_server;  #注释此行
root@test1:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@test1:~# /etc/init.d/nginx reload
[ok] Reloading nginx configuration (via systemctl): nginx.service.
优化后的结果如下:
root@test1:~# ps aux | grep nginx
root      11748  0.0  0.4  91280  5000 ?        Ss  12:25  0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  13031  0.0  0.3  91600  3808 ?        S    16:00  0:00 nginx: worker process                         
root      13052  0.0  0.2  12948  2064 pts/1    S+  16:01  0:00 grep nginx
root@test1:~# ss -tnl | grep 80
LISTEN    0      128                      *:80                      *:*

5.2、php 优化

    在这里针对 php 的优化,我们可以控制 php5-fpm 的工作进程数来达到节约资源的目的,最开始在“/etc/php5/fpm/php-fpm.conf”文件是找了半天都没有找到相关的配置选项,最后还是动用强大的 find 命令找到了相关的配置文件。
    先来看看默认时 php 的启动进程数:
root@test1:~# ps aux | grep php
root      11946  0.0  1.3  93540 13996 ?        Ss  12:32  0:01 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                   
www-data  11949  0.0  1.0  94124 10720 ?        S    12:32  0:00 php-fpm: pool www                                                     
www-data  11950  0.0  1.1  93980 12088 ?        S    12:32  0:00 php-fpm: pool www                                                     
root      13124  0.0  0.2  12948  2204 pts/1    S+  16:06  0:00 grep php

默认时 php 也开启了两个工作进程,这里只需要一个即可,做如下操作:

root@test1:~# find /etc/php5/* -type f | xargs grep “max_children”    #查找有 ”max_children” 关键字的文件
/etc/php5/fpm/pool.d/www.conf:;  static  – a fixed number (pm.max_children) of child processes;
/etc/php5/fpm/pool.d/www.conf:;            pm.max_children      – the maximum number of children that can
/etc/php5/fpm/pool.d/www.conf:;            pm.max_children          – the maximum number of children that
/etc/php5/fpm/pool.d/www.conf:pm.max_children = 5

关于 Php 的优化参数有如下几个:
pm、pm.max_children、pm.start_servers、pm.min_spare_servers、pm.max_spare_servers
pm = dynamic #对于专用服务器,pm 可以设置为 static。
# 如何控制子进程,选项有 static 和 dynamic。如果选择 static,则由 pm.max_children 指定固定的子进程数。如果选择 dynamic,则由下开参数决定:
pm.max_children #,子进程最大数
pm.start_servers #,启动时的进程数
pm.min_spare_servers #,保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
pm.max_spare_servers #,保证空闲进程数最大值,如果空闲进程大于此值,此进行清理

在这里,我设置的取值如下:
root@test1:~# vim /etc/php5/fpm/pool.d/www.conf
…..
pm = static  #把 pm 值改为 static,默认是 dynamic
pm.max_children = 1  #把 pm.max_clildren 的值修改为“1”,默认是“5″
root@test1:~# /etc/init.d/php5-fpm restart
[ok] Restarting php5-fpm (via systemctl): php5-fpm.service.
root@test1:~# ps aux | grep php-fpm
root      13235  0.0  1.3  93524 14016 ?        Ss  16:29  0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                   
www-data  13238  0.0  0.6  93524  6428 ?        S    16:29  0:00 php-fpm: pool www                                                     
root      13258  0.0  0.1  12944  1984 pts/1    S+  16:29  0:00 grep php-fpm
# 现在就只有一个 php-fpm 的工作进程了

通过观察,一个 nginx 的 worker 进程占用约 4MB 内存,一个 php-fpm 占用约 6.5MB 内存,通过计算优化后可节约内存 =4MB*4+6.5=22.5MB 的内存大小。

6、总结

现在公司的系统环境慢慢在从 CentOS 向 Debian 上迁移,对从没有接触过 Debian 系统的我来说,还需要一个适应过程,通过这段时间的使用,发现 Debian 与 Centos 在使用上还是有许多的不同,这次搭建 php 环境时就遇到一些问题。

MemAdmin 中文界面,操作十分简单,但我在使用中发现几个问题,比如:只能写入数据,而不能读取数据,对状态监控时的刷新时间间隔不生效等。

还有一款简洁的 memcached 的状态监视工具也不错,叫 memcachephp-master,能实现获取 KEY 所对应的 VALUE 值,正好弥补我这里 MemAdmin 不能获取值的不足。此工具部署也很简单,此处就不再演示。

相关附件在 Linux 公社资源站下载

—————————————— 分割线 ——————————————

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2016 年资料 / 1 月 /25 日 /Debian8(amd64) 安装部署 Memcached 管理工具 MemAdmin/

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

—————————————— 分割线 ——————————————

CentOS 6.6 下 Memcached 源码安装配置  http://www.linuxidc.com/Linux/2015-09/123019.htm

Memcached 安装及启动脚本 http://www.linuxidc.com/Linux/2013-07/87641.htm

PHP 中使用 Memcached 的性能问题 http://www.linuxidc.com/Linux/2013-06/85883.htm

Ubuntu 下安装 Memcached 及命令解释 http://www.linuxidc.com/Linux/2013-06/85832.htm

Memcached 的安装和应用 http://www.linuxidc.com/Linux/2013-08/89165.htm

使用 Nginx+Memcached 的小图片存储方案 http://www.linuxidc.com/Linux/2013-11/92390.htm

Memcached 使用入门 http://www.linuxidc.com/Linux/2011-12/49516p2.htm

Memcached 的详细介绍:请点这里
Memcached 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-01/127843.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计9562字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中