CentOS7源码安装Redis

目录

gcc环境

Redis安装包的下载及解压

编译

安装

配置Redis

Redis启动

设置环境变量

关闭Redis


gcc环境

Redis是由C语言开发,因此安装之前必须要确保服务器已经安装了gcc

查看gcc环境,查看到版本号输出,说明已经安装gcc

[hadoop@node2 installfile]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
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.
​

1)安装或更新C语言的编译环境

[hadoop@node2 installfile]$ sudo yum install -y centos-release-scl scl-utils-build 
[hadoop@node2 installfile]$ sudo yum install -y devtoolset-8-toolchain

[hadoop@node2 installfile]$ sudo scl enable devtoolset-8 bash

注意: 执行sudo scl enable devtoolset-8 bash会自动切换到 root 用户

效果如下

[hadoop@node2 installfile]$ sudo scl enable devtoolset-8 bash
[root@node2 installfile]# 

2)测试 gcc版本

[root@node2 installfile]# su hadoop
[hadoop@node2 installfile]# gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 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.

发现执行第1)步命令后,gcc版本更新了。

Redis安装包的下载及解压

下载安装包redis-6.0.8.tar.gz

[hadoop@node2 installfile]# wget https://download.redis.io/releases/redis-6.0.8.tar.gz

解压

[hadoop@node2 installfile]$ tar -zxvf redis-6.0.8.tar.gz -C ~/soft/

进入解压后目录

[hadoop@node2 installfile]$ cd ~/soft/redis-6.0.8/
[hadoop@node2 redis-6.0.8]$ 

编译

[hadoop@node2 redis-6.0.8]$ make

安装

[hadoop@node2 redis-6.0.8]$ sudo make install

默认安装目录:/usr/local/bin

[hadoop@node2 redis-6.0.8]$ ls /usr/local/bin/
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

如果想更换安装目录,可使用如下命令

sudo make install PREFIX=/usr/local/redis

这里的操作使用默认的安装目录

配置Redis

拷贝一份redis.conf到其他目录

[hadoop@node2 redis-6.0.8]$ cp redis.conf ~/my_redis.conf

修改my_redis.conf

vim ~/my_redis.conf

修改如下内容:

1)添加在bind 127.0.0.1一行行首添加#,允许外部机器连接访问。

#bind 127.0.0.1

2)protected-mode yes改为no

protected-mode no

3)后台启动设置daemonize no 改成 yes

protected-mode no

4)将 daemonize no 改为 yes,让服务在后台启动

daemonize yes

Redis启动

[hadoop@node2 redis-6.0.8]$ /usr/local/bin/redis-server ~/my_redis.conf 
[hadoop@node2 redis-6.0.8]$ /usr/local/bin/redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
[hadoop@node2 redis-6.0.8]$ 
​

设置环境变量

修改my_env.sh

[hadoop@node2 redis-6.0.8]$ sudo vim /etc/profile.d/my_env.sh

添加如下环境变量

#REDIS
export PATH=$PATH:/usr/local/bin

让环境变量生效

[hadoop@node2 redis-6.0.8]$ source /etc/profile

关闭Redis

查看redis进程

[hadoop@node2 redis-6.0.8]$ ps -ef | grep redis
hadoop     6335      1  0 00:04 ?        00:00:00 /usr/local/bin/redis-server *:6379
hadoop     6403   1898  0 00:10 pts/0    00:00:00 grep --color=auto redis
​

Redis关闭

[hadoop@node2 redis-6.0.8]$ redis-cli shutdown
[hadoop@node2 redis-6.0.8]$ ps -ef | grep redis
hadoop     6406   1898  0 00:12 pts/0    00:00:00 grep --color=auto redis

也可以进入终端后执行shutdown命令关闭

[hadoop@node2 redis-6.0.8]$ redis-server ~/my_redis.conf 
[hadoop@node2 redis-6.0.8]$ ps -ef | grep redis
hadoop     6408      1  0 00:14 ?        00:00:00 redis-server *:6379
hadoop     6414   1898  0 00:14 pts/0    00:00:00 grep --color=auto redis
[hadoop@node2 redis-6.0.8]$ redis-cli 
127.0.0.1:6379> shutdown
not connected> 
not connected> 
not connected> quit
[hadoop@node2 redis-6.0.8]$ ps -ef | grep redis
hadoop     6417   1898  0 00:14 pts/0    00:00:00 grep --color=auto redis
​

指定端口关闭

[hadoop@node2 redis-6.0.8]$ redis-server ~/my_redis.conf 
[hadoop@node2 redis-6.0.8]$ ps -ef | grep redis
hadoop     6420      1  0 00:17 ?        00:00:00 redis-server *:6379
hadoop     6432   1898  0 00:17 pts/0    00:00:00 grep --color=auto redis
[hadoop@node2 redis-6.0.8]$ redis-cli -p 6379 shutdown
[hadoop@node2 redis-6.0.8]$ ps -ef | grep redis
hadoop     6435   1898  0 00:17 pts/0    00:00:00 grep --color=auto redis

完成!enjoy it!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值