linux开启nscd服务缓存加速
在我使用的阿里云主机上有观察到开启了一个服务nscd ,后来谷哥了下该服务的作用。了解到nscd会缓存三种服务passwd group hosts,所以它会记录三个库,分别对应源/etc/passwd, /etc/hosts 和 /etc/resolv.conf每个库保存两份缓存,一份是找到记录的,一份是没有找到记录的。每一种缓存都保存有生存时间(TTL)。其作用就是在本当中增加cache ,加快如DNS的解析等的速度。
一、nscd的配置
通过编辑/etc/nscd.conf文件,在其中增加如下一行可以开启本地DNS cache:
阿里云配置如下:
[root@iZ250eahq29Z ~]# more /etc/nscd.conf
#logfile /var/log/nscd.log
threads 6
max-threads 128
server-user nscd
debug-level 5
paranoia no
enable-cache passwd no
enable-cache group no
enable-cache hosts yes
positive-time-to-live hosts 5
negative-time-to-live hosts 20
suggested-size hosts 211
check-files hosts yes
persistent hosts yes
shared hosts yes
max-db-size hosts 33554432
查看配置文件服务的软件包名称
$rpm -qf /etc/nscd.conf
nscd-2.17-196.el7_4.2.x86_64
相关参数的解释如下:
logfile debug-file-name
指定调试信息写入的文件名。
debug-level value
设置希望的调试级别。
threads number
这是启动的等待请求的线程数。最少将创建5个线程。
server-user user
如果设置了该选项,nscd将作为该用户运行,而不是作为root。如果每个用户都使用一个单独的缓存(-S参数),将忽略该选项。
enable-cache service <yes|no>
启用或禁用制定的 服务 缓存。
positive-time-to-live service value
设置 service 在指定缓存中正的项目(成功的请求)的TTL(存活时间)。 Value 以秒为单位。较大的值将增加缓存命中率从而减低平均响应时间,但是将增加缓存的一致性问题。
negative-time-to-live service value
设置 service 在指定缓存中负的项目(失败的请求)的TTL(存活时间)。 Value 以秒为单位。如果存在由不在系统数据库中的uid(用户ID)(例如在以root身份解包linux 内核源代码时)所拥有的文件将明显改善性能;应该维持较小的值以降低缓存一致性问题。
suggested-size service value
这是内部散列表的大小, value 应该保持一个素数以达到优化效果。
check-files service <yes|no>
启用或禁用检查属于指定 服务 的文件的改变。这些文件是 /etc/passwd, /etc/group, 以及/etc/hosts。
二、nscd 服务查看和清除
默认该服务在redhat或centos下是关闭的,可以通过services nscd start开启。缓存DB文件在/var/db/nscd下。可以通过nscd -g查看统计的信息,这里列出部分:
nscd -g
nscd configuration:
5 server debug level
34d 23h 14m 18s server runtime
6 current number of threads
128 maximum number of threads
0 number of times clients had to wait
no paranoia mode enabled
3600 restart internal
5 reload count
passwd cache:
no cache is enabled
no cache is persistent
no cache is shared
0 suggested size
0 total data pool size
0 used data pool size
3600 seconds time to live for positive entries
20 seconds time to live for negative entries
0 cache hits on positive entries
0 cache hits on negative entries
0 cache misses on positive entries
0 cache misses on negative entries
0% cache hit rate
0 current number of cached values
0 maximum number of cached values
0 maximum chain length searched
0 number of delays on rdlock
0 number of delays on wrlock
0 memory allocations failed
yes check /etc/passwd for changes
……………………………………………………………………………………
清除缓存
- nscd -i passwd
- nscd -i group
- nscd -i hosts
除了上面的方法,重启nscd服务同样可以达到清理cache的目的。
三、nscd的效果
首先要看网络和dns服务器的能力,dns解析越慢,dns缓存的优势就越大.比如我们在北京用的dns服务器202.106.0.20和google的dns服务器8.8.8.8速度会差不少.
如果dns服务器比较稳定,那它对效率的影响就是一个常数.这个常数有多大呢?
我简单试了一下.在局域网内进行压力测试,压一个nginx下的静态页面,使用202.106.0.20这个dns服务器,不用dns缓存.平均一分钟可以访问27万次.压一个简单的php页面,平均一分钟可以访问22万次.加上nscd服务后,静态页面平均一分钟可以访问120万次,要快4倍多.php页面平均一分钟可以访问50万次,快一倍多.
如果是做搜索引擎或是一些代理服务类的项目,比如短信通道,数据推送服务,这个性能提升还是比较可观的.但在一般的项目中,一台服务器每分钟发22万次请求的情况是很少见的,所以这个性能提升也微呼其微.
linux开启nscd服务缓存加速的更多相关文章
- kali linux 开启ssh服务
kali linux 一般默认不开启ssh服务,可使用命令查看ssh服务是否开启 命令:service ssh status 如果显示ssh服务没有开启需要修改ssh配置文件将ssh服务开启,kali ...
- Linux实战教学笔记36:PHP服务缓存加速深度优化实践
一,PHP缓存加速器介绍与环境准备 1.1 PHP缓存加速器介绍 1.1.1 操作码介绍及缓存原理 当客户端请求一个PHP程序时,服务器的PHP引擎会解析该PHP程序,并将其编译为特定的操作码(Ope ...
- linux开启ssh服务
本文概略:1)ubuntu发行版开启ssh.2)centos发行版开启ssh 1.ubuntu发行版安装/开启ssh服务 1.1 安装ssh服务端 sudo apt-get install opens ...
- linux开启FTP服务
目录 打开FTP服务 客户端链接时会出现的问题 打开FTP服务 先ping,查看网络是否联通 打开ssh服务 查看一些服务的状态 #查看ssh状态 service sshd status #防火墙的状 ...
- SuSE Linux 开启VNC服务
一.启动VNC服务输入命令 vncserver 二.编辑启动脚步vi /root/.vnc/xstartup 把twm &注释改为#twm & 然后再最下面增加2行startgnom ...
- LINUX开启SAMBA服务
samba,用于网络文件共享,类似于nfs, samba多用于win和linux之间 linux之间多用nfs c/s架构 smb协议 samba主要是两个服务,核心启动服务SMB,监听139TCP端 ...
- linux开启oracle服务
linux下启动oracle su - oracle sqlplus /nolog conn /as sysdba startup exit lsnrctl start exit 2. linux下关 ...
- linux开启telnet服务
步骤: sudo apt-get install xinetd telnetd 安装成功后,系统会显示有相应得提示 sudo vim /etc/inetd.conf 并加入内容: teln ...
- 解决kali linux 开启ssh服务后连接不上的问题
今天在手机端装了NetHunter 想连接PC的kali ,可是怎么都连不上 综合网友的经验: 1.修改sshd_config文件,命令为:vi /etc/ssh/sshd_config 将#Pass ...
随机推荐
- \r\n和\n的区别
写Java代码的时候习惯用\r\n换行,这样可移植性比较好但是,在UVa - 160中就出现了错误,来看看是为什么吧. http://bbs.csdn.net/topics/220033879
- 删除编辑文件警告Swap file “…” already exists!
Linux下多个用户同时编辑一个文件,或编辑时非正常关闭,再下次编辑打开文件时均为显示如下警告信息: Swap file "test.xml.swp" already exists ...
- js 数组函数
Array.prototype.join Array.prototype.reverse Array.prototype.sort Array.prototype.concat Array.proto ...
- ZOJ 3203 Light Bulb
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow a ...
- Oracle管理监控之使用utl_mail自动邮件报警配置
--代发邮件存储过程源码如下: CREATE OR REPLACE PROCEDURE send_mail(p_recipient VARCHAR2, -- 邮件接收人 ...
- 使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务
借助ArcGIS桌面发布ArcGIS服务是一个很熟悉的过程了,发布服务的前提是需要拥有一个已连接的ArcGIS Server服务站点,经过对mxd进行制图配置,定义服务参数,才能实现服务的发布,那么这 ...
- spring boot web服务
[root@d java]# tree -I target .├── pom.xml└── src ├── main │ ├── java │ │ └── com │ │ └── ...
- 小米范工具系列之五:小米范WEB口令扫描器
最新版本1.2,下载地址:http://pan.baidu.com/s/1c1NDSVe 文件名 webcracker,请使用java1.8运行 小米范WEB口令扫描器的主要功能是批量扫描web口令 ...
- 用virtualenv建立多个Python独立开发环境(转)
add by zhj: 在virtualenv环境下,安装第三方包时,不要用sudo pip install xxx,要直接用pip install xxx,如果用sudo时,那会安装在原来的系统Py ...
- RedHat 6.6下安装nginx,配置HTTPS
1.安装依赖包 yum -y install pcre-devel openssl-devel zlib-devel 2.下载nginx安装包到服务器上,当前使用版本nginx-1.15.5.tar. ...