redis安装

1 下载和安装

从https://redis.io/下载最新版,解压tar xvfz redis-4.0.11.tar.gz,进入解压目录,执行make,就可以看到二进制文件。

$ ls src/redis-server 
src/redis-server

执行make install,默认会安装到/usr/local/bin/redis-server,问题怎么更改安装目录?对于linux系统来说,复制/usr/local/bin/redis-server到你想要的目录就可以。

2 基本配置

默认可以执行src/redis-server,建议带配置文件,可以通过redis-server -h查看支持的参数。

$ redis-server -h
Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory 

Examples:
       ./redis-server (run the server with default conf)
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --slaveof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel

配置文件

在源码目录里有redis.conf文件,拷贝至期望的目录,关于每个配置项的介绍可以参看redis.conf里的介绍,也可以参看官网https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf。

基本配置项

  • bind 127.0.0.1
  • protected-mode yes
  • port 6379
  • tcp-backlog 511
  • daemonize yes
  • pidfile /var/run/redis_6379.pid
  • loglevel notice
  • logfile "" 默认是空,最好配置

除此之外,

  • 还需要对持久化进行一些配置,毕竟redis是内存数据库,系统重启或者软件重启数据丢失
  • REPLICATION配置,在生产环境建议配置,测试环境不需要配置

启动redis-server

启动非常简单,看到日志

redis-server /usr/local/redis/redis.conf
7120:C 21 Sep 20:54:31.739 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7120:C 21 Sep 20:54:31.739 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7120, just started
7120:C 21 Sep 20:54:31.739 # Configuration loaded
7120:M 21 Sep 20:54:31.740 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7120:M 21 Sep 20:54:31.741 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7120:M 21 Sep 20:54:31.741 # Server initialized
7120:M 21 Sep 20:54:31.741 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7120:M 21 Sep 20:54:31.741 # 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.
7120:M 21 Sep 20:54:31.741 * Ready to accept connections

说明启动成功,redis还是非常易于使用。

你可能感兴趣的:(redis安装)