图虫的服务器长期是单机运行。估计除了mysql之外,php-fpm和redis还可以在单机上共存很长时间。(多说服务器早就达成了单机每日2000万+动态请求,所以我对单机搞定图虫的大流量非常乐观)

如果是单机服务,其实就不需要用IP哪怕是127.0.0.1这样的IP去连接mysql/redis/php了,因为即使是127.0.0.1也是要走TCP/IP层的。

unix提供的unix socket来实现单机的端口访问,很多文章提到用unix socket可以提升连接速度。

我简单测试了一下,200次redis请求的耗时38ms,如果改成unix socket方式,立刻降到27ms。这简直是立竿见影啊,10ms的差距足以让我们有动力把IP方式改成unix socket方式。

Mysql(PDO)启用unix socket的方法

1.在PDO的DSN里面:原来写host:xxx,改成unix_socket:/var/run/mysqld/mysqld.sock (当然你可以在my.cnf里面设置成别的)

2.给mysql的用户名@localhost,设置访问权限。由于unix_socket并不是主机,所以用unix socket方式连接mysql,mysql会强制认为用户是来自于localhost,所以一定要给username@localhost设置权限,而不是username@’%’

redis(phpredis)启用unix socket的方法

1.redis 默认没有开启unix socket,需要在/etc/redis/redis.conf中修改。注意unixsocketperm 777

unixsocket /var/run/redis/redis.sock
unixsocketperm 777

2.用phpredis连接:

$redis->connect('/var/run/redis/redis.sock')

nginx + php-fpm启用unix socket的方法

1.php-fpm 的pool配置文件中:

listen = /var/run/php5-fpm.sock;

2.nginx sites的配置文件中:

fastcgi_pass   unix:/var/run/php5-fpm.sock;

由于redis连接次数很多,因此redis使用unix socket的效果最明显,mysql其次,php基本上没有用不用sock都差不多

转:用unix socket加速php-fpm、mysql、redis的连接的更多相关文章

  1. MySQL错误Another MySQL daemon already running with the same unix socket.v

    etc/init.d/mysqld start 结果显示 Another MySQL daemon already running with the same unix socket.显示另一个MyS ...

  2. Another MySQL daemon already running with the same unix socket的解决

    问题出现: 每周一需要备份一次数据库,即从服务器MySQL导出sql文件,再导入到我机器上虚拟机的MySQL里.但是今天早上连不上,我进入控制台用#service mysqld start强行启动,报 ...

  3. Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket

    Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket 特征 ...

  4. 启动Mysql报错:Another MySQL daemon already running with the same unix socket.

    启动Mysql报错: Another MySQL daemon already running with the same unix socket. 删除如下文件即可解决 /var/lib/mysql ...

  5. MySQL“Another MySQL daemon already running with the same unix socket” 报错信息处理

    Mysql "Another Mysql daemon already running with the same unix socket" 解决办法:rm var/lib/mys ...

  6. MySQL不能启动 Can't start server : Bind on unix socket: Permission denied

    转载博客地址:http://www.linuxidc.com/Linux/2010-04/25709.htm MySQL服务器突然不能启动,查看最后的启动日志如下: 080825 09:38:04 m ...

  7. MySQL故障处理一例_Another MySQL daemon already running with the same unix socket

    MySQL故障处理一例:"Another MySQL daemon already running with the same unix socket". [root@test- ...

  8. Starting MySQL ** mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists

    本地虚拟机(CentOS6.8)启动MySQL(MySQL5.6.35)服务失败 [root@VMUest ~]# service mysql status ERROR! MySQL is not r ...

  9. MySQL5.7报错[ERROR] Unix socket lock file is empty /tmp/mysql.sock.lock的解决方法

    发现MySQL服务器因系统磁盘写满导致服务停了,清理磁盘后启动服务时无法正常启动,查看localhost.err日志发现如下报错: [ERROR] Unix socket lock file is e ...

随机推荐

  1. 交叉编译移植openssl

    交叉编译openssl静态库步骤: 1.解压源码 tar xf openssl-1.1.1a.tar.gz 2.进入到解压后的源码目录 cd openssl-1.1.1a/ 3.配置Makefile ...

  2. 再来一个expect脚本

    [root@jenkins scripts]# cat expect_test1205.sh #!/usr/bin/expect ################################### ...

  3. vim -- 查找和替换

    %s/foo/bar/g 在所有行中寻找‘foo’,并且用‘bar’替换 :s/foo/bar/g 在当前行寻找‘foo’,并且用‘foo’替换 :%s/foo/bar/gc 将每一个‘foo',并用 ...

  4. [Buzz Today]2013.08.18

    # Go 语言实现memcached:groupcache memcached作者Brad Fitzpatrick用Go语言重新实现了memcached. groupcache继承了memcached ...

  5. vc6项目-vc8项目 转换日志

    此随笔参考了http://blog.163.com/feng_qihang/blog/static/7129199120093422722430/ 把VC6的项目转换成VS2005项目,经过VS200 ...

  6. 71、Android上对Cookie的读写操作

    Cookie是为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据,在Android中也经常用到,接下来我们介绍Cookie在Android里是如何进行读写的.   Cookie其实就 ...

  7. IOS控件:WebView移动网站导航

    #import <UIKit/UIKit.h> // 模板默认引入包含程序需要使用“类”的框架,即 Foundation.h头文件,使它包含在程序中 #import <Foundat ...

  8. RadioButton ---- 样式效果切换

    \res\drawable\radio_button_bg.xml <?xml version="1.0" encoding="utf-8"?> & ...

  9. 【BZOJ3673/3674】可持久化并查集/可持久化并查集加强版 可持久化线段树

    [BZOJ3674]可持久化并查集加强版 Description Description:自从zkysb出了可持久化并查集后……hzwer:乱写能AC,暴力踩标程KuribohG:我不路径压缩就过了! ...

  10. [LintCode] 全排列

    递归实现: class Solution { public: /** * @param nums: A list of integers. * @return: A list of permutati ...