安装redis 配置 以及出现的问题
发布日期:2021-05-07 02:59:27 浏览次数:33 分类:精选文章

本文共 5599 字,大约阅读时间需要 18 分钟。

Linux安装redis 以及出现的问题

1,解压.tar.gz包

[root@localhost ~]# cd /opt[root@localhost opt]# lldrwxrwxr-x.  7 root root       4096 3月   2 14:13 redis-6.0.12-rw-r--r--.  1 root root    2276349 4月  10 10:57 redis-6.0.12.tar.gz

2.安装gcc-c++环境

[root@localhost redis-6.0.12]# yum install gcc-c++已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.neusoft.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.neusoft.edu.cn软件包 gcc-c++-4.8.5-44.el7.x86_64 已安装并且是最新版本无须任何处理[root@localhost redis-6.0.12]#

3.执行make命令(需要时间的)

配置上所有的文件

make

出现错误

[root@hadoop01 app]# make..........server.c:5127:29: 错误:‘struct redisServer’没有名为‘pidfile’的成员     if (background || server.pidfile) createPidFile();                             ^server.c:5132:16: 错误:‘struct redisServer’没有名为‘sentinel_mode’的成员     if (!server.sentinel_mode) {                   ^server.c:5142:19: 错误:‘struct redisServer’没有名为‘cluster_enabled’的成员         if (server.cluster_enabled) {                      ^server.c:5150:19: 错误:‘struct redisServer’没有名为‘ipfd_count’的   ^server.c:5155:24: 错误:‘struct redisServer’没有名为‘masterhost’的成员。。。。。。。。。。。。。server.c: 在函数‘allPersistenceDisabled’中:server.c:1482:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type] } ^server.c: 在函数‘writeCommandsDeniedByDiskError’中:server.c:3790:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type] } ^server.c: 在函数‘iAmMaster’中:server.c:4964:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type] } ^make[1]: *** [server.o] 错误 1make[1]: 离开目录“/opt/app/redis-6.0.5/src”make: *** [all] 错误 2

错误处在了版本不兼容的问题

我们的gcc是低版本,使用的redis为6的高版本,需要将gcc升级到9版本进行操作
在这里插入图片描述
我们进行gcc的升级

[root@hadoop01 redis-6.0.5]# gcc -v                             # 查看gcc版本[root@hadoop01 redis-6.0.5]# yum -y install centos-release-scl  # 升级到9.1版本[root@hadoop01 redis-6.0.5]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils[root@hadoop01 redis-6.0.5]# scl enable devtoolset-9 bash以上为临时启用,如果要长期使用gcc 9.1的话:[root@hadoop01 redis-6.0.5]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

然后我们再次执行

make

就可以成功了

再执行

make install

检查

Hint: It's a good idea to run 'make test' ;)make[1]: 离开目录“/opt/redis-6.0.12/src”[root@localhost redis-6.0.12]# make installcd src && make installmake[1]: 进入目录“/opt/redis-6.0.12/src”Hint: It's a good idea to run 'make test' ;)    INSTALL install    INSTALL install    INSTALL install    INSTALL install    INSTALL installmake[1]: 离开目录“/opt/redis-6.0.12/src”[root@localhost redis-6.0.12]#

我们检查redis的安装情况

[root@localhost redis-6.0.12]# cd /usr/local [root@localhost local]# ll总用量 0drwxr-xr-x. 2 root root 134 4月  10 11:22 bindrwxr-xr-x. 2 root root   6 4月  11 2018 etcdrwxr-xr-x. 2 root root   6 4月  11 2018 gamesdrwxr-xr-x. 2 root root   6 4月  11 2018 includedrwxr-xr-x. 2 root root   6 4月  11 2018 libdrwxr-xr-x. 2 root root   6 4月  11 2018 lib64drwxr-xr-x. 2 root root   6 4月  11 2018 libexecdrwxr-xr-x. 2 root root   6 4月  11 2018 sbindrwxr-xr-x. 5 root root  49 3月  27 11:26 sharedrwxr-xr-x. 2 root root   6 4月  11 2018 src[root@localhost local]# cd bin[root@localhost bin]# ll总用量 38120-rwxr-xr-x. 1 root root 4746184 4月  10 11:22 redis-benchmark-rwxr-xr-x. 1 root root 9738832 4月  10 11:22 redis-check-aof-rwxr-xr-x. 1 root root 9738832 4月  10 11:22 redis-check-rdb-rwxr-xr-x. 1 root root 5066512 4月  10 11:22 redis-clilrwxrwxrwx. 1 root root      12 4月  10 11:22 redis-sentinel -> redis-server-rwxr-xr-x. 1 root root 9738832 4月  10 11:22 redis-server[root@localhost bin]#

可以看到我们安装成功了

配置

将配置文件redis.conf复制一份到其他路径下,我们进行配置,例如

[root@localhost local]# cd wConfig/[root@localhost wConfig]# ll总用量 84-rw-r--r--. 1 root root 85560 4月  10 12:20 redis.conf[root@localhost wConfig]# vi redis.conf [root@localhost wConfig]#

我们在配置文件中可以看到

# Accept connections on the specified port, default is 6379 (IANA #815344).# If port 0 is specified Redis will not listen on a TCP socket.port 6379默认端口号6379

设置后台启动

# By default Redis does not run as a daemon. Use 'yes' if you need it.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.daemonize yes

启动redis服务

[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]# redis-server wConfig/redis.conf
[root@localhost bin]#

[root@localhost local]# cd bin[root@localhost bin]# ll总用量 38204-rwxr-xr-x. 1 root root 4746184 4月  10 11:22 redis-benchmark-rwxr-xr-x. 1 root root 9738832 4月  10 11:22 redis-check-aof-rwxr-xr-x. 1 root root 9738832 4月  10 11:22 redis-check-rdb-rwxr-xr-x. 1 root root 5066512 4月  10 11:22 redis-cli-rw-r--r--. 1 root root   85560 4月  10 12:18 redis.conflrwxrwxrwx. 1 root root      12 4月  10 11:22 redis-sentinel -> redis-server-rwxr-xr-x. 1 root root 9738832 4月  10 11:22 redis-serverdrwxr-xr-x. 2 root root      24 4月  10 12:28 wConfig//启动服务器端  指定用哪个配置文件进行启动[root@localhost bin]# redis-server wConfig/redis.conf [root@localhost bin]# //链接本机的redis服务 利用客户端进行链接 指定端口号[root@localhost bin]# redis-cli -p 6379127.0.0.1:6379> pingPONG#为启动服务成功127.0.0.1:6379> set name wangOK127.0.0.1:6379> get name"wang"127.0.0.1:6379>

查看进程redis是否启动

Last login: Sat Apr 10 12:10:27 2021 from 192.168.80.1[root@localhost ~]# ps -aux|grep redisroot      4913  0.1  0.4 162384  7660 ?        Ssl  12:30   0:00 redis-server 127.0.0.1:6379root      5370  0.0  0.4  25052  7768 pts/1    S+   12:37   0:00 redis-cli -p 6379root      5501  0.0  0.0 112828   988 pts/2    S+   12:39   0:00 grep --color=auto redis[root@localhost ~]#

关闭服务

[root@localhost bin]# redis-cli -p 6379127.0.0.1:6379> pingPONG127.0.0.1:6379> shutdownnot connected> exit[root@localhost bin]#

再查看服务已经关闭

[root@localhost ~]# ps -aux|grep redisroot      5618  0.0  0.0 112828   988 pts/2    S+   12:40   0:00 grep --color=auto redis[root@localhost ~]#
上一篇:redis-benchmark性能测试工具
下一篇:ubantu软件管理命令及远程登陆命令

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年03月30日 09时09分20秒