欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > CentOS7源码安装Redis

CentOS7源码安装Redis

2024/10/25 13:21:05 来源:https://blog.csdn.net/qq_42881421/article/details/139974009  浏览:    关键词: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!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com