01.linux下安装redis并做成服务

官网

Redis官网

Redis官方中文网

中文版的的弊端你懂得。要是看官网能解决的就不要看别人写的文章,哈哈

安装

首先获取redis安装包

yum install wget
wget http://download.redis.io/releases/redis-5.0.3.tar.gz

解压压缩包

tar xf redis-5.0.3.tar.gz

进入redis目录中

cd redis-5.0.3

任何开源软件都有仔细阅读README.md后再动手,开始make,缺啥少啥就install

make

yum install gcc-c++

yum install gcc

如果第一次make失败要清理一下

make disclean

可以直接install,可执行文件就会在当前目录下生产,防止混乱,install的时候用PREFIX指定目录

make install PREFIX=/opt/redis5

加入到环境变量中,在任何位置都可以实行redis的可执行文件了。

vi /etc/profile

在最后两行加入

export REDIS_HOME=/opt/redis5
export PATH=$PATH:$REDIS_HOME/bin

:wq保存后source一下

source /etc/profile

这样可执行文件就单独存放了,也将redis的命令加入到了环境变量中

[root@basic bin]# ll
total 32672
-rwxr-xr-x. 1 root root 4366592 Jan 27 23:17 redis-benchmark
-rwxr-xr-x. 1 root root 8090064 Jan 27 23:17 redis-check-aof
-rwxr-xr-x. 1 root root 8090064 Jan 27 23:17 redis-check-rdb
-rwxr-xr-x. 1 root root 4801840 Jan 27 23:17 redis-cli
lrwxrwxrwx. 1 root root      12 Jan 27 23:17 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8090064 Jan 27 23:17 redis-server
[root@basic bin]# pwd
/opt/redis5/bin

将redis制作成service

源码中就提供了将redis制作成service的可执行文件了

[root@basic redis-5.0.3]# cd utils/
[root@basic utils]# ll
total 52
-rw-rw-r--. 1 root root  593 Dec 12  2018 build-static-symbols.tcl
-rw-rw-r--. 1 root root 1303 Dec 12  2018 cluster_fail_time.tcl
-rw-rw-r--. 1 root root 1070 Dec 12  2018 corrupt_rdb.c
drwxrwxr-x. 2 root root   60 Dec 12  2018 create-cluster
-rwxrwxr-x. 1 root root 2149 Dec 12  2018 generate-command-help.rb
drwxrwxr-x. 3 root root   31 Dec 12  2018 graphs
drwxrwxr-x. 2 root root   39 Dec 12  2018 hashtable
drwxrwxr-x. 2 root root   70 Dec 12  2018 hyperloglog
-rwxrwxr-x. 1 root root 9567 Dec 12  2018 install_server.sh
drwxrwxr-x. 2 root root   63 Dec 12  2018 lru
-rw-rw-r--. 1 root root 1277 Dec 12  2018 redis-copy.rb
-rwxrwxr-x. 1 root root 1352 Dec 12  2018 redis_init_script
-rwxrwxr-x. 1 root root 1047 Dec 12  2018 redis_init_script.tpl
-rw-rw-r--. 1 root root 1762 Dec 12  2018 redis-sha1.rb
drwxrwxr-x. 2 root root  135 Dec 12  2018 releasetools
-rwxrwxr-x. 1 root root 3787 Dec 12  2018 speed-regression.tcl
-rwxrwxr-x. 1 root root  693 Dec 12  2018 whatisdoing.sh
[root@basic utils]# pwd
/opt/redis-5.0.3/utils

在utils目录下,install_server.sh

[root@basic utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.

根据提示可以配置redis,也可以使用默认的,只要使用的端口号不一样,配置就不会出现覆盖的情况。

如果是初次安装的话一路回车就可以了。

最后会将redis加入到service中并且启动,/etc/init.d 目录下也多了redis_6379这个可执行文件。

通过chkconfig查看,也是运行在2、3、4、5级别上了

[root@basic ~]# chkconfig --list redis_6379

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]'.

redis_6379      0:off   1:off   2:on    3:on    4:on    5:on    6:off

启动

service redis_6379 start

停止

service redis_6379 stop

            在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

起个破名真费劲..

可赏可不赏,没脸要,哈哈

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值