首先需要下载Redis的安装包
- 进入官网找到下载地址 redis.io/download 直接下载就行
通过xftp工具上传到linux服务器上
通过xshell连接服务器进入上传的目录
[root@order app]# ll
-rw-r--r--. 1 root root 2454893 Apr 22 06:02 redis-6.2.2.tar.gz
复制代码
- 解压,输入 tar -xvf redis-6.2.2.tar.gz
drwxrwxr-x. 7 root root 4096 Apr 20 01:03 redis-6.2.2
-rw-r--r--. 1 root root 2454893 Apr 22 06:02 redis-6.2.2.tar.gz
复制代码
- 重复名一下(可以省略)输入 mv redis-6.2.2 redis
drwxrwxr-x. 7 root root 4096 Apr 20 01:03 redis
-rw-r--r--. 1 root root 2454893 Apr 22 06:02 redis-6.2.2.tar.gz
复制代码
- 进入Redis目录
[root@order app]# cd redis
[root@order redis]# ll
total 228
-rw-rw-r--. 1 root root 25124 Apr 20 01:03 00-RELEASENOTES
-rw-rw-r--. 1 root root 51 Apr 20 01:03 BUGS
-rw-rw-r--. 1 root root 5026 Apr 20 01:03 CONDUCT
-rw-rw-r--. 1 root root 3384 Apr 20 01:03 CONTRIBUTING
-rw-rw-r--. 1 root root 1487 Apr 20 01:03 COPYING
drwxrwxr-x. 7 root root 145 Apr 20 01:03 deps
-rw-rw-r--. 1 root root 11 Apr 20 01:03 INSTALL
-rw-rw-r--. 1 root root 151 Apr 20 01:03 Makefile
-rw-rw-r--. 1 root root 6888 Apr 20 01:03 MANIFESTO
-rw-rw-r--. 1 root root 21567 Apr 20 01:03 README.md
-rw-rw-r--. 1 root root 93724 Apr 20 01:03 redis.conf
-rwxrwxr-x. 1 root root 275 Apr 20 01:03 runtest
-rwxrwxr-x. 1 root root 279 Apr 20 01:03 runtest-cluster
-rwxrwxr-x. 1 root root 1046 Apr 20 01:03 runtest-moduleapi
-rwxrwxr-x. 1 root root 281 Apr 20 01:03 runtest-sentinel
-rw-rw-r--. 1 root root 13768 Apr 20 01:03 sentinel.conf
drwxrwxr-x. 3 root root 4096 Apr 20 01:03 src
drwxrwxr-x. 11 root root 182 Apr 20 01:03 tests
-rw-rw-r--. 1 root root 3055 Apr 20 01:03 TLS.md
drwxrwxr-x. 9 root root 4096 Apr 20 01:03 utils
复制代码
- 执行 make开始对Redis进行编译,输入 make
[root@order redis]# make
cd src && make all
make[1]: Entering directory `/home/app/redis/src'
CC Makefile.dep
make[1]: Leaving directory `/home/app/redis/src'
make[1]: Entering directory `/home/app/redis/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep
rm -f adlist.d quicklist.d ae.d anet.d dict.d server.d sds.d zmalloc.d lzf_c.d lzf_d.d pqsort.d zipmap.d sha1.d ziplist.d release.d networking.d util.d object.d db.d replication.d rdb.d t_string.d t_list.d t_set.d t_zset.d t_hash.d config.d aof.d pubsub.d multi.d debug.d sort.d intset.d syncio.d cluster.d crc16.d endianconv.d slowlog.d scripting.d bio.d rio.d rand.d memtest.d crcspeed.d crc64.d bitops.d sentinel.d notify.d setproctitle.d blocked.d hyperloglog.d latency.d sparkline.d redis-check-rdb.d redis-check-aof.d geo.d lazyfree.d module.d evict.d expire.d geohash.d geohash_helper.d childinfo.d defrag.d siphash.d rax.d t_stream.d listpack.d localtime.d lolwut.d lolwut5.d lolwut6.d acl.d gopher.d tracking.d connection.d tls.d sha256.d timeout.d setcpuaffinity.d monotonic.d mt19937-64.d anet.d adlist.d dict.d redis-cli.d zmalloc.d release.d ae.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d ae.d anet.d redis-benchmark.d adlist.d dict.d zmalloc.d release.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d
(cd ../deps && make distclean)
make[2]: Entering directory `/home/app/redis/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(cd hdr_histogram && make clean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/home/app/redis/deps'
(rm -f .make-*)
echo STD=-pedantic -DREDIS_STATIC='' -std=c99 >> .make-settings
echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo BUILD_TLS= >> .make-settings
echo USE_SYSTEMD= >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-pedantic -DREDIS_STATIC='' -std=c99 -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua hdr_histogram jemalloc)
make[2]: Entering directory `/home/app/redis/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(cd hdr_histogram && make clean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-cflags)
(echo "" > .make-ldflags)
MAKE hiredis
cd hiredis && make static
make[3]: Entering directory `/home/app/redis/deps/hiredis'
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb alloc.c
make[3]: cc: Command not found
make[3]: *** [alloc.o] Error 127
make[3]: Leaving directory `/home/app/redis/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/home/app/redis/deps'
make[1]: [persist-settings] Error 2 (ignored)
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/app/redis/src'
make: *** [all] Error 2
复制代码
- 如果虚拟机没有安装make命令会编译失败,安装一下make命令,输入 yum install gcc-c++
[root@order redis]# yum install gcc-c++
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: ftp.sjtu.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 232 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 7.1 MB 00:00:05
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Processing Dependency: libstdc++ = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Processing Dependency: gcc = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-c++-4.8.5-44.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-c++-4.8.5-44.el7.x86_64
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libgomp = 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: cpp = 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: libgcc >= 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-44.el7.x86_64
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package libstdc++.x86_64 0:4.8.5-39.el7 will be updated
---> Package libstdc++.x86_64 0:4.8.5-44.el7 will be an update
---> Package libstdc++-devel.x86_64 0:4.8.5-44.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-44.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-323.el7_9 will be installed
--> Processing Dependency: glibc-headers = 2.17-323.el7_9 for package: glibc-devel-2.17-323.el7_9.x86_64
--> Processing Dependency: glibc = 2.17-323.el7_9 for package: glibc-devel-2.17-323.el7_9.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-323.el7_9.x86_64
---> Package libgcc.x86_64 0:4.8.5-39.el7 will be updated
---> Package libgcc.x86_64 0:4.8.5-44.el7 will be an update
---> Package libgomp.x86_64 0:4.8.5-39.el7 will be updated
---> Package libgomp.x86_64 0:4.8.5-44.el7 will be an update
--> Running transaction check
---> Package glibc.x86_64 0:2.17-307.el7.1 will be updated
--> Processing Dependency: glibc = 2.17-307.el7.1 for package: glibc-common-2.17-307.el7.1.x86_64
---> Package glibc.x86_64 0:2.17-323.el7_9 will be an update
---> Package glibc-headers.x86_64 0:2.17-323.el7_9 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-323.el7_9.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-323.el7_9.x86_64
--> Running transaction check
---> Package glibc-common.x86_64 0:2.17-307.el7.1 will be updated
---> Package glibc-common.x86_64 0:2.17-323.el7_9 will be an update
---> Package kernel-headers.x86_64 0:3.10.0-1160.24.1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================================================================================
Installing:
gcc-c++ x86_64 4.8.5-44.el7 base 7.2 M
Installing for dependencies:
cpp x86_64 4.8.5-44.el7 base 5.9 M
gcc x86_64 4.8.5-44.el7 base 16 M
glibc-devel x86_64 2.17-323.el7_9 updates 1.1 M
glibc-headers x86_64 2.17-323.el7_9 updates 691 k
kernel-headers x86_64 3.10.0-1160.24.1.el7 updates 9.0 M
libmpc x86_64 1.0.1-3.el7 base 51 k
libstdc++-devel x86_64 4.8.5-44.el7 base 1.5 M
mpfr x86_64 3.1.1-4.el7 base 203 k
Updating for dependencies:
glibc x86_64 2.17-323.el7_9 updates 3.6 M
glibc-common x86_64 2.17-323.el7_9 updates 12 M
libgcc x86_64 4.8.5-44.el7 base 103 k
libgomp x86_64 4.8.5-44.el7 base 159 k
libstdc++ x86_64 4.8.5-44.el7 base 306 k
Transaction Summary
=================================================================================================================================================================================================================================================
Install 1 Package (+8 Dependent packages)
Upgrade ( 5 Dependent packages)
Total download size: 58 M
Is this ok [y/d/N]: y
复制代码
- 这个地方输入 y 继续安装,看见 Complete! 说明安装完成
Installed:
gcc-c++.x86_64 0:4.8.5-44.el7
Dependency Installed:
cpp.x86_64 0:4.8.5-44.el7 gcc.x86_64 0:4.8.5-44.el7 glibc-devel.x86_64 0:2.17-323.el7_9 glibc-headers.x86_64 0:2.17-323.el7_9 kernel-headers.x86_64 0:3.10.0-1160.24.1.el7 libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.5-44.el7
mpfr.x86_64 0:3.1.1-4.el7
Dependency Updated:
glibc.x86_64 0:2.17-323.el7_9 glibc-common.x86_64 0:2.17-323.el7_9 libgcc.x86_64 0:4.8.5-44.el7 libgomp.x86_64 0:4.8.5-44.el7 libstdc++.x86_64 0:4.8.5-44.el7
Complete!
[root@order redis]#
复制代码
- 清理一下之前编译Redis失败的文件,输入 make distclean
[root@order redis]# make distclean
cd src && make distclean
make[1]: Entering directory `/home/app/redis/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep
rm -f adlist.d quicklist.d ae.d anet.d dict.d server.d sds.d zmalloc.d lzf_c.d lzf_d.d pqsort.d zipmap.d sha1.d ziplist.d release.d networking.d util.d object.d db.d replication.d rdb.d t_string.d t_list.d t_set.d t_zset.d t_hash.d config.d aof.d pubsub.d multi.d debug.d sort.d intset.d syncio.d cluster.d crc16.d endianconv.d slowlog.d scripting.d bio.d rio.d rand.d memtest.d crcspeed.d crc64.d bitops.d sentinel.d notify.d setproctitle.d blocked.d hyperloglog.d latency.d sparkline.d redis-check-rdb.d redis-check-aof.d geo.d lazyfree.d module.d evict.d expire.d geohash.d geohash_helper.d childinfo.d defrag.d siphash.d rax.d t_stream.d listpack.d localtime.d lolwut.d lolwut5.d lolwut6.d acl.d gopher.d tracking.d connection.d tls.d sha256.d timeout.d setcpuaffinity.d monotonic.d mt19937-64.d anet.d adlist.d dict.d redis-cli.d zmalloc.d release.d ae.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d ae.d anet.d redis-benchmark.d adlist.d dict.d zmalloc.d release.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d
(cd ../deps && make distclean)
make[2]: Entering directory `/home/app/redis/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(cd hdr_histogram && make clean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/home/app/redis/deps'
(rm -f .make-*)
make[1]: Leaving directory `/home/app/redis/src'
[root@order redis]#
复制代码
- 继续编译Redis 输入 make 看见一下内容表示编译成功
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/home/app/redis/src'
复制代码
- 编译之后进行安装,输入 make install 看见一下内容表示安装成功
[root@order redis]# make install
cd src && make install
make[1]: Entering directory `/home/app/redis/src'
CC Makefile.dep
make[1]: Leaving directory `/home/app/redis/src'
make[1]: Entering directory `/home/app/redis/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL redis-server
INSTALL redis-benchmark
INSTALL redis-cli
make[1]: Leaving directory `/home/app/redis/src'
复制代码
-
直接启动 ,输入 redis-server 成功如下:
-
输入 redis-server 加载默认 redis.conf 因为Redis 可以设置多个配置文件,可以在redis-sercer 后面跟上自己定义的配置文件 如 redis-server /home/apps/redis/redis.conf
[root@order redis]# redis-server
7057:C 22 Apr 2021 21:22:38.892 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7057:C 22 Apr 2021 21:22:38.892 # Redis version=6.2.2, bits=64, commit=00000000, modified=0, pid=7057, just started
7057:C 22 Apr 2021 21:22:38.892 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
7057:M 22 Apr 2021 21:22:38.894 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7057:M 22 Apr 2021 21:22:38.894 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7057
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7057:M 22 Apr 2021 21:22:38.895 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7057:M 22 Apr 2021 21:22:38.895 # Server initialized
7057:M 22 Apr 2021 21:22:38.895 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7057:M 22 Apr 2021 21:22:38.895 * Ready to accept connections
复制代码
- redis服务启动后,如果退出会自动结束服务,这样启动 redis-server& 这种是启动
[root@order redis]# redis-server
7099:C 22 Apr 2021 21:33:59.178 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7099:C 22 Apr 2021 21:33:59.178 # Redis version=6.2.2, bits=64, commit=00000000, modified=0, pid=7099, just started
7099:C 22 Apr 2021 21:33:59.178 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
7099:M 22 Apr 2021 21:33:59.178 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7099:M 22 Apr 2021 21:33:59.178 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7099
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7099:M 22 Apr 2021 21:33:59.178 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7099:M 22 Apr 2021 21:33:59.178 # Server initialized
7099:M 22 Apr 2021 21:33:59.178 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7099:M 22 Apr 2021 21:33:59.179 * Loading RDB produced by version 6.2.2
7099:M 22 Apr 2021 21:33:59.179 * RDB age 193 seconds
7099:M 22 Apr 2021 21:33:59.179 * RDB memory usage when created 0.77 Mb
7099:M 22 Apr 2021 21:33:59.179 * DB loaded from disk: 0.000 seconds
7099:M 22 Apr 2021 21:33:59.179 * Ready to accept connections
^C7099:signal-handler (1619141809) Received SIGINT scheduling shutdown...
7099:M 22 Apr 2021 21:36:49.083 # User requested shutdown...
7099:M 22 Apr 2021 21:36:49.083 * Saving the final RDB snapshot before exiting.
7099:M 22 Apr 2021 21:36:49.100 * DB saved on disk
7099:M 22 Apr 2021 21:36:49.100 # Redis is now ready to exit, bye bye...
复制代码
- 输入 vim redis.conf 打开配置文件 找到 daemonize no 把no改为yes, 同时也将bind注释,将protected-mode设置为no,保存后退出,这样启动后我就可以在外网访问了,重新启动一下服务,并且重新加载一下配置文件 输入 redis-server /home/apps/redis/redis.conf
[root@order redis]# redis-server /home/app/redis/redis.conf
复制代码
- 连接一下redis 服务,输入 redis-cli , 进入redis 操作界面,我们可以进行,存值,取值,删除的简单操作了
[root@order redis]# redis-cli
127.0.0.1:6379> set ccn 123
OK
127.0.0.1:6379> get ccn
"123"
127.0.0.1:6379> del ccn
(integer) 1
127.0.0.1:6379> get ccn
(nil)
127.0.0.1:6379>
复制代码
- redis 默认有0-15个库我们可以进行存储库的选择,来进行存储,我们可以选择不通库存储不通类型的数据
127.0.0.1:6379> select 4
OK
127.0.0.1:6379[4]> select 10
OK
127.0.0.1:6379[10]> select 13
OK
127.0.0.1:6379[13]> select 16
(error) ERR DB index is out of range
127.0.0.1:6379[13]> select 14
OK
127.0.0.1:6379[14]> select 15
OK
127.0.0.1:6379[15]>
复制代码
- 输入 exit 退出 看下一下我们的进程 ps -ef|grep redis
127.0.0.1:6379[4]> exit
[root@order redis]# ps -ef|grep redis
root 7188 1 0 21:50 ? 00:00:00 redis-server *:6379
root 7226 2284 0 22:00 pts/1 00:00:00 grep --color=auto redis
复制代码
- 关闭服务 进入操作板进行,也可以直接杀死进程 kill -9 7188
[root@order redis]# redis-cli
127.0.0.1:6379> shutdown
not connected>
复制代码
- 重新启动之后进入redis的操作板,设置一下 外网连接的redis验证密码 config set requirepass 123456 显示ok,设置成功。
[root@order redis]# redis-server /home/app/redis/redis.conf
[root@order redis]# redis-cli
127.0.0.1:6379> config set requirepass 123456
OK
复制代码
- 我们打开redis的连接工具redis manager 进行连接
- 连接成功
- 进入操作板
- 在redis manager 进行操作,我们在redis manger 4库中存入数据 我们在服务器上取一下是不能取出来
123:4>select 4
"OK"
123:4>set ccn 123
"OK"
123:4>get ccn
"123"
123:4>
复制代码
- 服务器上我们进入4库报错 (error) NOAUTH Authentication required. 因为我们之前设置了连接密码,所以这个地方要输入你刚才输入的密码
[root@order redis]# redis-cli
127.0.0.1:6379> select 4
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> select 4
OK
127.0.0.1:6379[4]> get ccn
"123"
127.0.0.1:6379[4]>
复制代码
- redis 是默认开启持久化数据的,如果直接在服务器上杀死redis的进程,数据是不会持久化的,如果想关闭redis,并且持久化存入的数据。需要在关闭时保存 shutdown sava
- 看一下进程,ps -ef|grep redis
- 重启 redis-server& 入4库 select 4 查看数据
[root@order redis]# redis-cli
127.0.0.1:6379> select 4
OK
127.0.0.1:6379[4]> get ccn
"123"
127.0.0.1:6379[4]> get wxy
"2021"
127.0.0.1:6379[4]> shutdown save
not connected>
[root@order redis]# ps -ef|grep redis
root 1861 1751 0 01:42 pts/0 00:00:00 grep --color=auto redis
[root@order redis]# redis-server&
[root@order redis]# redis-cli
127.0.0.1:6379> select 4
OK
127.0.0.1:6379[4]> get wxy
"2021"
复制代码
这里列举下比较重要的配置项
配置项名称 配置项值范围 说明
daemonize yes、no yes表示启用守护进程,默认是no即不以守护进程方式运行。其中Windows系统下不支持启用守护进程方式运行
port 指定 Redis 监听端口,默认端口为 6379
bind 绑定的主机地址,如果需要设置远程访问则直接将这个属性备注下或者改为bind * 即可,这个属性和下面的protected-mode控制了是否可以远程访问 。
protected-mode yes 、no 保护模式,该模式控制外部网是否可以连接redis服务,默认是yes,所以默认我们外网是无法访问的,如需外网连接rendis服务则需要将此属性改为no。
timeout 300 当客户端闲置多长时间后关闭连接,如果指定为 0,表示关闭该功能
loglevel debug、verbose、notice、warning 日志级别,默认为 notice
databases 16 设置数据库的数量,默认的数据库是0。整个通过客户端工具可以看得到
rdbcompression yes、no 指定存储至本地数据库时是否压缩数据,默认为 yes,Redis 采用 LZF 压缩,如果为了节省 CPU 时间,可以关闭该选项,但会导致数据库文件变的巨大。
dbfilename dump.rdb 指定本地数据库文件名,默认值为 dump.rdb
dir 指定本地数据库存放目录
requirepass 设置 Redis 连接密码,如果配置了连接密码,客户端在连接 Redis 时需要通过 AUTH <password> 命令提供密码,默认关闭
maxclients 0 设置同一时间最大客户端连接数,默认无限制,Redis 可以同时打开的客户端连接数为 Redis 进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis 会关闭新的连接并向客户端返回 max number of clients reached 错误信息。
maxmemory XXX <bytes> 指定 Redis 最大内存限制,Redis 在启动时会把数据加载到内存中,达到最大内存后,Redis 会先尝试清除已到期或即将到期的 Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis 新的 vm 机制,会把 Key 存放内存,Value 会存放在 swap 区。配置项值范围列里XXX为数值。
复制代码
- 好的以上就是我总结的linux部署redis并且用redis连接工具进行连接,刚接触了解的不是很深,有不对的地方欢迎各位大佬指正。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END