root@xcjyc:~# apt update ; apt info redis Package: redis Version: 5:6.0.16-1ubuntu1 Priority: optional Section: universe/database Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Chris Lamb <lamby@debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 67.6 kB Depends: redis-server (<< 5:6.0.16-1ubuntu1.1~), redis-server (>= 5:6.0.16-1ubuntu1) Homepage: https://redis.io/ Download-Size: 2930 B APT-Sources: https://mirrors.aliyun.com/ubuntu jammy/universe amd64 Packages Description: Persistent key-value database with network interface (metapackage) Redis is a key-value database in a similar vein to memcache but the dataset is non-volatile. Redis additionally provides native support for atomically manipulating and querying data structures such as lists and sets. . The dataset is stored entirely in memory and periodically flushed to disk. . This package installs the main redis-server package.
# 检查环境安装状态 root@ubuntu2204:~# apt install -y gcc make libjemalloc-dev libsystemd-dev Reading package lists... Done Building dependency tree... Done Reading state information... Done gcc is already the newest version (4:11.2.0-1ubuntu1). make is already the newest version (4.3-4.1build1). libjemalloc-dev is already the newest version (5.2.1-4ubuntu1). libsystemd-dev is already the newest version (249.11-0ubuntu3.12). 0 upgraded, 0 newly installed, 0 to remove and 56 not upgraded.
Sentinel mode: ./redis-server /etc/sentinel.conf --sentinel # 前台启动测试 root@ubuntu2204:~# redis-server /apps/redis/etc/redis.conf 8030:C 14 May 2024 07:54:18.370 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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. 8030:C 14 May 2024 07:54:18.370 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 8030:C 14 May 2024 07:54:18.370 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=8030, just started 8030:C 14 May 2024 07:54:18.370 * Configuration loaded 8030:M 14 May 2024 07:54:18.371 * Increased maximum number of open files to 10032 (it was originally set to 1024). 8030:M 14 May 2024 07:54:18.371 * monotonic clock: POSIX clock_gettime _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 7.2.4 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 8030 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
8030:M 14 May 2024 07:54:18.373 * Server initialized 8030:M 14 May 2024 07:54:18.373 * Ready to accept connections tcp
# 消除启动警告信息,添加内核参数 WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
# 重新测试启动(警告信息消除) root@ubuntu2204:~# redis-server /apps/redis/etc/redis.conf 1024:C 15 May 2024 06:11:01.266 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 1024:C 15 May 2024 06:11:01.266 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=1024, just started 1024:C 15 May 2024 06:11:01.266 * Configuration loaded 1024:M 15 May 2024 06:11:01.266 * Increased maximum number of open files to 10032 (it was originally set to 1024). 1024:M 15 May 2024 06:11:01.266 * monotonic clock: POSIX clock_gettime _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 7.2.4 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1024 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
1024:M 15 May 2024 06:11:01.269 * Server initialized 1024:M 15 May 2024 06:11:01.270 * Loading RDB produced by version 7.2.4 1024:M 15 May 2024 06:11:01.270 * RDB age 77247 seconds 1024:M 15 May 2024 06:11:01.270 * RDB memory usage when created 0.83 Mb 1024:M 15 May 2024 06:11:01.270 * Done loading RDB, keys loaded: 0, keys expired: 0. 1024:M 15 May 2024 06:11:01.270 * DB loaded from disk: 0.001 seconds 1024:M 15 May 2024 06:11:01.270 * Ready to accept connections tcp
root@ubuntu2204:~# ls ./redis-7.2.4/utils/systemd-redis_server.service ./redis-7.2.4/utils/systemd-redis_server.service
# 修改好的redis.service文件内容 root@ubuntu2204:~# vim /etc/systemd/system/redis.service [Unit] Description=Redis data structure server Documentation=https://redis.io/documentation Wants=network-online.target After=network-online.target
root@ubuntu2204:~# systemctl status redis.service ● redis.service - Redis data structure server Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2024-05-15 07:21:59 UTC; 25s ago Docs: https://redis.io/documentation Main PID: 23950 (redis-server) Status: "Ready to accept connections" Tasks: 5 (limit: 4515) Memory: 2.1M CPU: 97ms CGroup: /system.slice/redis.service └─23950 "/apps/redis/bin/redis-server 0.0.0.0:6379""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""
May 15 07:21:59 ubuntu2204 systemd[1]: Starting Redis data structure server... May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:C 15 May 2024 07:21:59.143 * Supervised by systemd. Please make sure you set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit. May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:C 15 May 2024 07:21:59.143 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:C 15 May 2024 07:21:59.143 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=23950, just started May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:C 15 May 2024 07:21:59.143 * Configuration loaded May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:M 15 May 2024 07:21:59.144 * monotonic clock: POSIX clock_gettime May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:M 15 May 2024 07:21:59.145 * Running mode=standalone, port=6379. May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:M 15 May 2024 07:21:59.146 * Server initialized May 15 07:21:59 ubuntu2204 redis-server[23950]: 23950:M 15 May 2024 07:21:59.146 * Ready to accept connections tcp May 15 07:21:59 ubuntu2204 systemd[1]: Started Redis data structure server.
root@ubuntu2204:~# ss -ntlp State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 511 0.0.0.0:6379 0.0.0.0:* users:(("redis-server",pid=23950,fd=6)) LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=809,fd=3)) LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=761,fd=14)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=809,fd=4))
# 使用redis-cli测试 # 格式:redis-cli -h <redis服务器> -p <PORT> -a <PASSWORD>
root@ubuntu2204:~# redis-cli -h 10.0.0.7 -p 6379 -a 12345678 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 10.0.0.7:6379> ping PONG 10.0.0.7:6379> info # Server redis_version:7.2.4 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:cfa841a5bc8661c5 redis_mode:standalone os:Linux 5.15.0-102-generic x86_64 arch_bits:64 monotonic_clock:POSIX clock_gettime multiplexing_api:epoll atomicvar_api:c11-builtin gcc_version:11.4.0 process_id:23986 process_supervised:systemd run_id:a1f26808d76b9e2b984e46979c55d9af2bd8a161 tcp_port:6379 server_time_usec:1715758640316473 uptime_in_seconds:132 uptime_in_days:0 hz:10 configured_hz:10 lru_clock:4482608 executable:/apps/redis/bin/redis-server config_file:/apps/redis/etc/redis.conf io_threads_active:0 listener0:name=tcp,bind=0.0.0.0,port=6379