Centos Redis源码安装

Centos Redis源码安装

  • gcc 编译环境安装
  • 创建安装目录
  • 下载稳定版([下载地址传送门](http://download.redis.io/releases))
  • 解压
  • 移动到安装目录
  • 编译
  • 安装
  • 创建日志目录
  • 修改配置文件
  • 指定配置文件启动
  • 查看Redis进程
  • 密码关闭redis
  • 客户端链接
  • 查看全部的key
  • 内置脚本执行安装

gcc 编译环境安装

源码安装 redis需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装。

yum install gcc-c++

创建安装目录

mkdir -p /usr/local/redis && cd /usr/local/redis/

下载稳定版(下载地址传送门)

wget http://download.redis.io/releases/redis-stable.tar.gz

解压

tar -zxvf redis-stable.tar.gz

移动到安装目录

 cd redis-stable && mv * .. && cd .. && rm -rf redis-stable

编译

make MALLOC=libc

Mac下使用

make MALLOC=jemalloc

安装

cd /usr/local/redis/src/  &&  make install PREFIX=/usr/local/redis

创建日志目录

mkdir -p /data/logs/redis/

修改配置文件

vim /usr/local/redis/redis.conf

修改一下几项:

# 设置绑定IP(可任意访问,可以和iptables配合限制访问)
bind 0.0.0.0

#端口
port 6379

#配置保护模式
protected-mode yes

#Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
daemonize yes

#指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose
loglevel notice

#指定日志目录
logfile /data/logs/redis/redis.log

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
dir /data/data/redis/

#设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH 命令提供密码,默认关闭
requirepass foobared

指定配置文件启动

/usr/local/redis/bin/redis-server  /usr/local/redis/redis.conf

查看Redis进程

# ps -ef |grep redis
root     24851     1  0 18:48 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379
root     24856 24009  0 18:49 pts/1    00:00:00 grep --color=auto redis

密码关闭redis

/usr/local/redis/bin/redis-cli -a pwd shutdown

查看进程

# ps -ef |grep redis
root     24923 24893  0 19:36 pts/1    00:00:00 grep --color=auto redis

客户端链接

/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 -a pwd

查看全部的key

127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> 

内置脚本执行安装

Make install will just install binaries in your system, but will not configure
init scripts and configuration files in the appropriate place. This is not
needed if you want just to play a bit with Redis, but if you are installing
it the proper way for a production system, we have a script doing this
for Ubuntu and Debian systems:

    % cd utils
    % ./install_server.sh

The script will ask you a few questions and will setup everything you need
to run Redis properly as a background daemon that will start again on
system reboots.

你可能感兴趣的:(Redis)