linux下redis的安装

本文详细介绍了Redis数据库的安装过程,包括下载源码包、编译安装、配置后台运行及开机启动,最后设置了密码保护,确保了Redis的安全运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载redis wget http://download.redis.io/releases/redis-4.0.11.tar.gz

[root@iZbp1h44pugu1vg9x5b2jjZ ~]# wget http://download.redis.io/releases/redis-4.0.11.tar.gz
--2018-11-12 08:27:52--  http://download.redis.io/releases/redis-4.0.11.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: 1739656 (1.7M) [application/x-gzip]
Saving to: ‘redis-4.0.11.tar.gz’

100%[===================================================================================================================================================>] 1,739,656   1.17MB/s   in 1.4s

2018-11-12 08:27:54 (1.17 MB/s) - ‘redis-4.0.11.tar.gz’ saved [1739656/1739656]

 

2.  tar -zxvf /root/redis-4.0.11.tar.gz
[root@iZbp1h44pugu1vg9x5b2jjZ local]# tar -zxvf /root/redis-4.0.11.tar.gz
redis-4.0.11/
redis-4.0.11/.gitignore
redis-4.0.11/00-RELEASENOTES
redis-4.0.11/BUGS
redis-4.0.11/CONTRIBUTING
redis-4.0.11/COPYING
redis-4.0.11/INSTALL
redis-4.0.11/MANIFESTO
redis-4.0.11/Makefile
redis-4.0.11/README.md

3. 查看系统是否安装了gcc

 gcc --version


[root@iZbp1h44pugu1vg9x5b2jjZ local]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 

 如果没安装可安装

 yum install gcc

4. cd redis-4.0.11/

make MALLOC=libc

[root@iZbp1h44pugu1vg9x5b2jjZ redis-4.0.11]# make MALLOC=libc
cd src && make all
make[1]: Entering directory `/usr/local/redis-4.0.11/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis-4.0.11/src'
make[1]: Entering directory `/usr/local/redis-4.0.11/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
 

5.cd src && make install

将/usr/local/redis-4.0.11/src目录下的文件加到/usr/local/bin目录

6. 测试安装是否成功

./redis-server

[root@iZbp1h44pugu1vg9x5b2jjZ src]# ./redis-server
16646:C 12 Nov 08:45:13.990 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16646:C 12 Nov 08:45:13.990 # Redis version=4.0.11, bits=64, commit=00000000, mo                                                                                                             dified=0, pid=16646, just started
16646:C 12 Nov 08:45:13.990 # Warning: no config file specified, using the defau                                                                                                             lt config. In order to specify a config file use ./redis-server /path/to/redis.c                                                                                                             onf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 16646
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

16646:M 12 Nov 08:45:13.991 # WARNING: The TCP backlog setting of 511 cannot be                                                                                                              enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
16646:M 12 Nov 08:45:13.991 # Server initialized
16646:M 12 Nov 08:45:13.991 # WARNING overcommit_memory is set to 0! Background                                                                                                              save may fail under low memory condition. To fix this issue add 'vm.overcommit_m                                                                                                             emory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.ove                                                                                                             rcommit_memory=1' for this to take effect.
16646:M 12 Nov 08:45:13.991 # WARNING you have Transparent Huge Pages (THP) supp                                                                                                             ort enabled in your kernel. This will create latency and memory usage issues wit                                                                                                             h Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transpar                                                                                                             ent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to reta                                                                                                             in the setting after a reboot. Redis must be restarted after THP is disabled.
16646:M 12 Nov 08:45:13.991 * Ready to accept connections
但这钟方式redis随窗口关闭而关闭

7.修改配置为后台服务

[root@iZbp1h44pugu1vg9x5b2jjZ redis-4.0.11]# ls
00-RELEASENOTES  BUGS  CONTRIBUTING  COPYING  deps  INSTALL  Makefile  MANIFESTO  README.md  redis.conf  runtest  runtest-cluster  runtest-sentinel  sentinel.conf  src  tests  utils
[root@iZbp1h44pugu1vg9x5b2jjZ redis-4.0.11]# vi redis.conf

将daemonize no 改为yes

[root@iZbp1h44pugu1vg9x5b2jjZ src]# ./redis-server ../redis.conf
16658:C 12 Nov 08:56:56.371 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16658:C 12 Nov 08:56:56.371 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=16658, just started
16658:C 12 Nov 08:56:56.371 # Configuration loaded
[root@iZbp1h44pugu1vg9x5b2jjZ src]#
查看redis进程

[root@iZbp1h44pugu1vg9x5b2jjZ src]# ps -aux | grep redis
root     16659  0.0  0.0 141776  2024 ?        Ssl  08:56   0:00 ./redis-server 127.0.0.1:6379
root     16665  0.0  0.0 112644   968 pts/0    S+   08:58   0:00 grep --color=auto redis
8.设置开机启动

在/etc目录下新建redis目录

[root@iZbp1h44pugu1vg9x5b2jjZ src]# cd /etc/
[root@iZbp1h44pugu1vg9x5b2jjZ etc]# mkdir redis
将/usr/local/redis-4.0.11/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf  

[root@iZbp1h44pugu1vg9x5b2jjZ etc]# cp /usr/local/redis-4.0.11/redis.conf /etc/redis/6379.conf
[root@iZbp1h44pugu1vg9x5b2jjZ etc]#
将redis的启动脚本复制一份放到/etc/init.d目录下

[root@iZbp1h44pugu1vg9x5b2jjZ init.d]# cp /usr/local/redis-4.0.11/utils/redis_init_script /etc/init.d/redisd
[root@iZbp1h44pugu1vg9x5b2jjZ init.d]#
检查开机启动服务

[root@iZbp1h44pugu1vg9x5b2jjZ init.d]# chkconfig redisd on
[root@iZbp1h44pugu1vg9x5b2jjZ init.d]#

shutdown -r now 软重启让系统,然后重新连接查看服务

login as: root
root@47.99.169.209's password:
Last login: Mon Nov 12 08:27:23 2018 from 1.202.149.2

Welcome to Alibaba Cloud Elastic Compute Service !

[root@izbp1h44pugu1vg9x5b2jjz ~]# ps -ef|grep redis
root       788     1  0 09:10 ?        00:00:00 /usr/local/bin/redis-server 127.                                                                                                             0.0.1:6379
root      2164  2140  0 09:10 pts/0    00:00:00 grep --color=auto redis
[root@izbp1h44pugu1vg9x5b2jjz ~]#
关闭再查看

[root@izbp1h44pugu1vg9x5b2jjz ~]# service redisd stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
[root@izbp1h44pugu1vg9x5b2jjz ~]# ps -ef|grep redis
root      2178  2140  0 09:14 pts/0    00:00:00 grep --color=auto redis
[root@izbp1h44pugu1vg9x5b2jjz ~]#
测试

[root@izbp1h44pugu1vg9x5b2jjz ~]#cd /usr/local/bin

[root@izbp1h44pugu1vg9x5b2jjz bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[root@izbp1h44pugu1vg9x5b2jjz bin]# redis-cli
127.0.0.1:6379> keys
(error) ERR wrong number of arguments for 'keys' command
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>

9. 设置密码

[root@izbp1h44pugu1vg9x5b2jjz bin]# cd /etc/redis/
[root@izbp1h44pugu1vg9x5b2jjz redis]# ls
6379.conf
[root@izbp1h44pugu1vg9x5b2jjz redis]# vi 6379.conf

把requirepass 123456

代替requirepass foobared

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值