centos7 php安装redis以及redis扩展

24 篇文章 0 订阅

安装Redis

Redis官方下载地址:http://redis.io/download,下载最新稳定版本。

当前稳定版本是4.0.9,下载并安装:

安装之前请

安装软件的时候,提示make: command not found
Centos中无法使用make,make install,命令 make: command not found

make是gcc的编译器,VPS买来必定要安装

安装:

yum -y install gcc automake autoconf libtool make

安装g++:

yum install gcc gcc-c++

yum install tcl

$ wget http://download.redis.io/releases/redis-4.0.9.tar.gz
$ tar -zxvf redis-4.0.9.tar.gz
$ mv redis-4.0.9 /usr/local/redis
$ cd /usr/local/redis
$ make 或者make MALLOC=libc
$ make install
进入src执行./redis-server redis.conf
511错误解决
内核参数默认128,对于负载很大的服务是不够的。改为2048或者更大

echo 2048 >   /proc/sys/net/core/somaxconn    系统重启后失效

vi /etc/sysctl.conf

net.core.somaxconn = 2048

保存,然后

sysctl -p


编辑/etc/sysctl.conf ,改vm.overcommit_memory=1,然后sysctl -p 使配置文件生效


 Redis启动报错:

    WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. 
    This will create latency and memory usage issues with Redis. 
    To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root,
    and add it to your /etc/rc.local in order to retain the setting after a reboot. 
    Redis must be restarted after THP is disabled

问题原因

内核启用THP可能会导致内存使用问题
解决方案

[root@customer src]# vi /etc/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

if test -f /sys/kernel/mm/redhat_transparent_hugepage/enabled; then

   echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled

fi

~
~
~
[root@customer src]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@customer src]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@customer src]# 

接下来修改redis.conf,设置密码和后台运行方式。

vim /usr/local/redis/redis.conf

找到

requirepass foobared 去掉注释 替换foobared 为自己的密码

找到

daemonize no 改为yes退出保存

配置redis服务管理脚本:

$ cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis

修改redis,vim /etc/init.d/redis

CONF="/usr/local/redis/redis.conf"

启动redis服务

$ /etc/init.d/redis start
Starting Redis server...
12797:C 30 May 22:53:34.030 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12797:C 30 May 22:53:34.030 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=12797, just started
12797:C 30 May 22:53:34.031 # Configuration loaded

安装PHP redis扩展

开始在 PHP 中使用 Redis 前,我们需要确保已经安装了redis服务,且你的机器上能正常使用PHP。 接下来让我们安装 PHP redis 驱动,下载地址为:https://github.com/phpredis/phpredis/releases

下载并安装最新版:

$ wget https://github.com/phpredis/phpredis/archive/4.0.2.tar.gz
$ tar -zxvf phpredis-4.0.2.tar.gz
$ cd phpredis-4.0.2
$ /usr/bin/phpize              # php安装后的路径
$ ./configure --with-php-config=/usr/bin/php-config
$ make && make install
extension=redis.so添加php.ini中重启php-fpm
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值