`

CentOS7安装redis

 
阅读更多

CentOS7安装redis和mongodb

本文介绍在CentOS7上安装redis数据库。

系统配置信息如下:

 

[linus@localhost ~]$ uname -r
3.10.0-229.20.1.el7.x86_64
[linus@localhost ~]$ more /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 
[linus@localhost ~]$ 

 

 

Redis

1、下载Redis,当前最新版本是3.0.5,然后安装。

 

[linus@localhost redis]$ wget http://download.redis.io/releases/redis-3.0.5.tar.gz
--2015-11-24 13:33:32--  http://download.redis.io/releases/redis-3.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1366160 (1.3M) [application/x-gzip]
Saving to: ‘redis-3.0.5.tar.gz’

100%[==============================================>] 1,366,160   40.0KB/s   in 25s    

2015-11-24 13:33:58 (54.1 KB/s) - ‘redis-3.0.5.tar.gz’ saved [1366160/1366160]

[linus@localhost redis]$ 
[linus@localhost redis]$ ls
redis-3.0.5.tar.gz
[linus@localhost redis]$ tar -zxf redis-3.0.5.tar.gz 
[linus@localhost redis]$ cd redis-3.0.5/
[linus@localhost redis-3.0.5]$ make
cd src && make all
make[1]: Entering directory `/home/linus/redis/redis-3.0.5/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: Entering directory `/home/linus/redis/redis-3.0.5/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/home/linus/redis/redis-3.0.5/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic >> .make-settings
echo WARN=-Wall -W >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -Wall -W -O2 -g -ggdb   -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS=  -g -ggdb -rdynamic >> .make-settings
。。。
。。。
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    CC redis-check-dump.o
    LINK redis-check-dump
    CC redis-check-aof.o
    LINK redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/home/linus/redis/redis-3.0.5/src'

 然后执行make test进行验证,报如下错误,安装tcl之后就可以正常执行了:

 

 

[linus@localhost redis-3.0.5]$ make test
cd src && make test
make[1]: Entering directory `/home/linus/redis/redis-3.0.5/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/home/linus/redis/redis-3.0.5/src'
make: *** [test] Error 2
[linus@localhost redis-3.0.5]$ make test
...
...
                   The End

Execution time of different units:
  1 seconds - unit/printver
  2 seconds - unit/scan
  2 seconds - unit/quit
  3 seconds - unit/auth
  3 seconds - unit/multi
  5 seconds - unit/protocol
  11 seconds - unit/expire
  21 seconds - unit/type/list
  35 seconds - unit/other
  40 seconds - unit/type/list-2
  19 seconds - integration/aof
  41 seconds - unit/type/hash
  42 seconds - unit/dump
  3 seconds - integration/logging
  2 seconds - unit/pubsub
  8 seconds - integration/rdb
  3 seconds - unit/slowlog
  2 seconds - unit/introspection
  6 seconds - integration/convert-zipmap-hash-on-load
  2 seconds - unit/limits
  12 seconds - unit/scripting
  19 seconds - unit/bitops
  67 seconds - unit/type/set
  72 seconds - integration/replication-2
  30 seconds - unit/memefficiency
  77 seconds - unit/type/zset
  79 seconds - unit/sort
  79 seconds - unit/aofrw
  84 seconds - unit/basic
  42 seconds - unit/maxmemory
  91 seconds - unit/type/list-3
  117 seconds - integration/replication-4
  67 seconds - unit/hyperloglog
  122 seconds - integration/replication-3
  137 seconds - integration/replication
  134 seconds - integration/replication-psync
  114 seconds - unit/obuf-limits

\o/ All tests passed without errors!

Cleanup: may take some time... OK
make[1]: Leaving directory `/home/linus/redis/redis-3.0.5/src'
[linus@localhost redis-3.0.5]$ 

 安装完成后,可以切换src目录下,执行redis-server命令启动redis服务器:

 

 

[linus@localhost src]$ ./redis-server &
[1] 8921
[linus@localhost src]$ 8921:C 24 Nov 13:44:17.995 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
8921:M 24 Nov 13:44:17.997 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
8921:M 24 Nov 13:44:17.997 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
8921:M 24 Nov 13:44:17.997 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 8921
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

8921:M 24 Nov 13:44:17.998 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8921:M 24 Nov 13:44:17.999 # Server started, Redis version 3.0.5
8921:M 24 Nov 13:44:17.999 # 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.
8921:M 24 Nov 13:44:17.999 # 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.
8921:M 24 Nov 13:44:17.999 * DB loaded from disk: 0.000 seconds
8921:M 24 Nov 13:44:17.999 * The server is now ready to accept connections on port 6379

 

 

此时可以通过redis-cli命令连接该redis服务器,并且可以通过SHUTDOWN命令关闭服务器:

 

[linus@localhost src]$ ./redis-cli 
127.0.0.1:6379> INFO
# Server
redis_version:3.0.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:cdf25f7608cc4cbe
redis_mode:standalone
os:Linux 3.10.0-229.20.1.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.3
process_id:8921
run_id:c4bf78bec7e54a517634bb62430406946c91733d
tcp_port:6379
uptime_in_seconds:104
uptime_in_days:0
hz:10
lru_clock:5503385
config_file:

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:508712
used_memory_human:496.79K
used_memory_rss:8024064
used_memory_peak:508712
used_memory_peak_human:496.79K
used_memory_lua:36864
mem_fragmentation_ratio:15.77
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1448343857
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:1
total_commands_processed:0
instantaneous_ops_per_sec:0
total_net_input_bytes:14
total_net_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.10
used_cpu_user:0.04
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
127.0.0.1:6379> 
127.0.0.1:6379> SHUTDOWN
not connected> 

服务器端会打印:
8921:M 24 Nov 13:46:52.838 # User requested shutdown...
8921:M 24 Nov 13:46:52.838 * Saving the final RDB snapshot before exiting.
8921:M 24 Nov 13:46:52.844 * DB saved on disk
8921:M 24 Nov 13:46:52.844 # Redis is now ready to exit, bye bye...

 服务器端配置:

 

最关键的配置以下选项:

 

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /var/log/redis.log
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

 

添加启动脚本/etc/init.d/redis:

 

#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 90 10
# description: Redis is an open source, advanced key-value store. 
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
 
REDISPORT=6379
# 下面的目录要看编译的目录,这两个文件会在编译目录的src目录下。
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
 
PIDFILE=/var/run/redis.pid
# 下面的目录要看编译的目录,这个文件会在编译目录下。
CONF="/usr/src/redis-2.8.13/redis.conf"
 
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ] 
        then 
              echo "Redis is running..."
        fi 
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac

 

添加redis为系统的服务:

[root@localhost redis]# ll /etc/init.d/redis 
-rw-r--r--. 1 root root 1394 Nov 24 14:06 /etc/init.d/redis
[root@localhost redis]# chmod +x /etc/init.d/redis 
[root@localhost redis]# ll /etc/init.d/redis 
-rwxr-xr-x. 1 root root 1394 Nov 24 14:06 /etc/init.d/redis
[root@localhost redis]# 
[root@localhost redis]# chkconfig --add redis
[root@localhost redis]# chkconfig redis on
[root@localhost redis]# chkconfig 

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
redis          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@localhost redis]# 

 ok,现在就安装好了。启动redis使用service redis start 或者/etc/init.d/redis start ,停止redis的命令service redis stop 或者/etc/init.d/redis stop。

 

 MongoDB

待续

分享到:
评论

相关推荐

    centos7安装redis5.0依赖GCC离线安装文件

    RHEL或centos7安装redis5.0所依赖的所有工具: cpp-4.8.2-16.el7.x86_64.rpm gcc-4.8.2-16.el7.x86_64.rpm glibc-2.17-55.el7.x86_64.rpm glibc-common-2.17-55.el7.x86_64.rpm glibc-devel-2.17-55.el7.x86_64.rpm ...

    Centos7安装Redis的文档和安装包(redis单例、哨兵、集群).rar

    Centos7安装Redis的文档和安装包,包含redis单例模式、哨兵模式和集群的配置,Redis的版本是5.0.7。

    Linux centos7安装redis

    Linux centos7安装redis,并开启aof持久化模式

    centos7 安装Redis 与 Redis解决session共享

    centos7 安装Redis 与 Redis解决session共享,可根据文档进行安装和使用,本人调试过,没问题

    Centos7安装Redis安装说明

    Centos7安装Redis安装说明

    centos7 yum安装redis配置密码及简单使用

    1、安装epel-release (建议使用国内阿里云源) #下载wget,备份当前源 yum install wget -y mv /etc/yum.repo.d/*.repo /tmp #下载阿里云源和epel源 wget -O /etc/yum.repos.d/CentOS-Base.repo ...

    centos源码安装redis-3.2.11

    centos源码安装redis-3.2.11

    CentOS6.6安装Redis3.0教程

    ### CentOS 6.6安装Redis 3.0教程详解 #### 一、前言 本文旨在详细介绍如何在CentOS 6.6上安装并配置Redis 3.0,包括从下载到安装再到设置开机自启的全过程。Redis是一款开源的高性能键值存储系统,它支持多种数据...

    百度云服务器系列:centos7安装redis记录

    在本文中,我们将深入探讨如何在CentOS 7操作系统上安装和启动Redis,这是一个流行的开源内存数据结构存储系统,常用于数据库、缓存和消息中间件。Redis支持多种数据结构,如字符串、哈希表、列表、集合和有序集合。...

    CentOS7.5安装Redis集群.docx

    CentOS7.5 安装 Redis 集群 CentOS7.5 安装 Redis 集群是指在 CentOS 7.5 操作系统上安装和配置 Redis 集群的过程。Redis 是一个开源的、基于内存的数据结构存储系统,可以用作数据库、消息队列、缓存等。下面是...

    Centos7安装redis所需压缩包

    在Linux系统,特别是CentOS 7上安装Redis是一项常见的任务,因为Redis是一个高效、开源的内存数据结构存储系统,常用于数据库、缓存和消息中间件。本压缩包"redis-6.2.11"包含了最新稳定版本的Redis源码,下面是详细...

    CentOS 7 下安装 Redis 2.8.7

    在Linux系统,特别是CentOS 7中安装Redis服务器是一个常见的任务,这主要因为Redis是一个高效、灵活的内存数据存储系统,常被用作数据库、缓存和消息中间件。在这个过程中,我们将详细讨论如何从源代码编译安装Redis...

    Centos7安装Redis4.0.docx

    本文将详细介绍如何在 CentOS 7 环境下安装 Redis 4.0 版本。 ### 1. 安装 Redis #### 1.1 下载 Redis 源码包 首先,你需要访问 Redis 官方网站(http://download.redis.io/releases/)或使用 `wget` 命令从...

    centos7部署redis脚本

    centos7部署redis脚本///centos7部署redis脚本///centos7部署redis脚本///centos7部署redis脚本///centos7部署redis脚本///centos7部署redis脚本///centos7部署redis脚本///centos7部署redis脚本

    centos 6.5 安装redis3.0.7

    ### CentOS 6.5 下 Redis 3.0.7 的安装与配置 #### 一、安装准备 在开始安装 Redis 之前,确保你的 CentOS 6.5 系统已更新到最新状态,并且具备必要的依赖包。以下是安装过程中需要用到的一些基本步骤: 1. **...

    Centos7环境下redis-6.2.4安装部署.md

    redis6.2.4部署安装

    redis安装离线版免编译版及离线安装需要的所有包文件

    本资源可结合我的文章《详解CentOS7下编译安装Redis5.x设置开机启动及修改端口(含redis需编译安装包和redis免编译安装包)》配合使用,同时也可单独去使用。包含redis3.0.7免编译版安装包,redis5.0.7离线安装包,...

Global site tag (gtag.js) - Google Analytics