在linux安装redis

浅浅的花香味﹌ 2024-03-29 15:57 155阅读 0赞

1:将下载的redis-5.0.2.tar.gz拉到/opt文件夹下

2:解压文件到当前目录下

  1. tar -zvxf redis-5.0.2.tar.gz

3:将解压出来的文件名修改为redis

4:由于redis是c语言编写的,所以我们需要先安装gcc,安装的命令如下:

  1. yum -y install gcc

5:安装成功后输入 :

  1. gcc -v

查看版本

6:然后进入到redis目录,进入redis,然后输入:

  1. make

控制台会输出一些编译的信息

7:编译成功后,输入:

  1. make install

自此redis就安装成功了

8:输入:redis-server 启动redis,启动成功。

启动redis服务:(三种启动方式)
1)前台启动:在任何目录下执行 redis-server
2)后台启动:在任何目录下执行 redis-server &
3)启动redis服务时,指定配置文件:redis-server redis.conf & ,这种主要用于你改了配置文件的情况,比如你把默认端口号改了,你就用这个,正常也用这个

9:修改redis密码,注意requirepass前面不能有空格

  1. ################################## SECURITY ###################################
  2. # Require clients to issue AUTH <PASSWORD> before processing any other
  3. # commands. This might be useful in environments in which you do not trust
  4. # others with access to the host running redis-server.
  5. #
  6. # This should stay commented out for backward compatibility and because most
  7. # people do not need auth (e.g. they run their own servers).
  8. #
  9. # Warning: since Redis is pretty fast an outside user can try up to
  10. # 150k passwords per second against a good box. This means that you should
  11. # use a very strong password otherwise it will be very easy to break.
  12. #
  13. requirepass 123456
  14. # Command renaming.
  15. #

redis的客户端,链接是redis-cli,有密码的需要输入auth 密码,显示OK才表示链接上,退出是exit

  1. [root@localhost redis]# redis-cli
  2. 127.0.0.1:6379> auth 123456
  3. OK
  4. 127.0.0.1:6379> exit
  5. [root@localhost redis]#

10:编写sh启动脚本,保存为sh

  1. #/bin/bash
  2. redis-server redis.conf &

10:编写sh关闭脚本(通过密码),保存为sh

  1. #/bin/bash
  2. redis-cli -a 123456 shuntdown

11:设置redis开机自启动

11-1:在/etc目录下新建redis目录
11-2:将/usr/local/redis/redis.conf文件复制一份到/etc/redis目录下,并命名为6379.conf
11-3:将redis的启动脚本复制一份放到/etc/init.d目录下

  1. [root@localhost ~]# cp /opt/app/redis/utils/redis_init_script /etc/init.d/redisd
  2. [root@localhost ~]#

11-4:设置redis开机自启动, 先切换到/etc/init.d目录下, 然后执行自启命令

  1. [root@localhost ~]# cd /etc/init.d
  2. [root@localhost init.d]# chkconfig redisd on
  3. [root@localhost init.d]#

发表评论

表情:
评论列表 (有 0 条评论,155人围观)

还没有评论,来说两句吧...

相关阅读

    相关 linux安装redis

    学习过程中的一些总结和记录,如有不正确的地方,还请指出。 1.下载 可以从官网[https://redis.io/][https_redis.io]下载redis的安装