┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$make cd src && make all which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) make[1]: 进入目录“/root/redis-stable/src” CC Makefile.dep make[1]: 离开目录“/root/redis-stable/src” which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) make[1]: 进入目录“/root/redis-stable/src” CC adlist.o /bin/sh: cc: 未找到命令 make[1]: *** [adlist.o] 错误 127 make[1]: 离开目录“/root/redis-stable/src” make: *** [all] 错误 2 ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$rpm -q gcc || yum -y install gcc
没有 gcc 包,需要安装一下
1 2 3 4 5 6 7 8 9 10 11
┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$make && make install ........ Hint: It's a good idea to run 'make test' '';) INSTALL redis-server INSTALL redis-benchmark INSTALL redis-cli make[1]: 离开目录“/root/redis-stable/src” ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$
初始化配置
配置服务运行参数 ./utils/install_server.sh 执行源码目录下的初始化脚本
1 2 3 4 5 6 7
┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$./utils/install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server
This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
使用推荐的 systemd 来管理 redis 服务,做成 Service unit ,通过 systemctl 来管理
当前,作为 Service unit 之后更方便管理,这里我们分别看下
二进制方式
1 2 3 4 5 6 7 8 9
┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$vim ./utils/install_server.sh #bail if this system is managed by systemd _pid_1_exe="$(readlink -f /proc/1/exe)" if [ "${_pid_1_exe##*/}" = systemd ] then echo"This systems seems to use systemd." echo"Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!" #exit 1
┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$./utils/install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server
This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry! Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$
┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$systemctl cat redis # /etc/systemd/system/redis.service # example systemd service unit file for redis-server # # In order to use this as a template for providing a redis service in your # environment, _at the very least_ make sure to adapt the redis configuration # file you intend to use as needed (make sure to set "supervised systemd"), and # to set sane TimeoutStartSec and TimeoutStopSec property values in the unit's # "[Service]" section to fit your needs. # # Some properties, such as User= and Group=, are highly desirable for virtually # all deployments of redis, but cannot be provided in a manner that fits all # expectable environments. Some of these properties have been commented out in # this example service unit file, but you are highly encouraged to set them to # fit your needs. # # Please refer to systemd.unit(5), systemd.service(5), and systemd.exec(5) for # more information.
[Unit] Description=Redis data structure server Documentation=https://redis.io/documentation #Before=your_application.service another_example_application.service #AssertPathExists=/var/lib/redis Wants=network-online.target After=network-online.target
┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$systemctlenable redis --now Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service. ┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$
停止服务
1 2 3 4 5 6 7 8 9 10 11 12
┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$systemctl stop redis.service ┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$systemctl status redis.service ● redis.service - Redis data structure server Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled) Active: inactive (dead) since 日 2022-10-30 23:35:57 CST; 14s ago Docs: https://redis.io/documentation Process: 15816 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize yes (code=exited, status=0/SUCCESS) Main PID: 15816 (code=exited, status=0/SUCCESS) Status: "Saving the final RDB snapshot" .....
┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$redis-cli -h 192.168.26.153 -p 6350 -a liruilong Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 192.168.26.153:6350> GET * (nil) 192.168.26.153:6350>
┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$/etc/init.d/redis_6379 stop Stopping ... Redis stopped ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$sed's/bind 127.0.0.1/bind 192.168.26.153/g' /etc/redis/6379.conf | grep bind # By default, if no "bind" configuration directive is specified, Redis listens # the "bind" configuration directive, followed by one or more IP addresses. # bind 192.168.1.100 10.0.0.1 # listens on two specific IPv4 addresses # bind 192.168.26.153 ::1 # listens on loopback IPv4 and IPv6 # bind * -::* # like the default, all available interfaces # internet, binding to all the interfaces is dangerous and will expose the # following bind directive, that will force Redis to listen only on the bind 192.168.26.153 -::1 # Using bind-source-addr it is possible to configure a specific address to bind # bind-source-addr 10.0.0.1 ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$sed's/bind 127.0.0.1/bind 192.168.26.153/g' /etc/redis/6379.conf -i ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$
┌──[root@vms153.liruilongs.github.io]-[~] └─$sed'/^# requirepass/c requirepass liruilong' /etc/redis/6350.conf | grep -i 'requirepass' # If the master is password protected (using the "requirepass" configuration # IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility # The requirepass is not compatible with aclfile option and the ACL LOAD # command, these will cause requirepass to be ignored. requirepass liruilong ┌──[root@vms153.liruilongs.github.io]-[~] └─$sed -i '/^# requirepass/c requirepass liruilong' /etc/redis/6350.conf | grep -i 'requirepass' ┌──[root@vms153.liruilongs.github.io]-[~] └─$
┌──[root@vms153.liruilongs.github.io]-[~] └─$/etc/init.d/redis_6379 start /var/run/redis_6379.pid exists, process is already running or crashed ┌──[root@vms153.liruilongs.github.io]-[~] └─$cat /var/run/redis_6379.pid 10941 ┌──[root@vms153.liruilongs.github.io]-[~] └─$rm -rf /var/run/redis_6379.pid
需要删除进程IP文件之后重新启动
1 2 3 4 5 6 7 8
┌──[root@vms153.liruilongs.github.io]-[~] └─$/etc/init.d/redis_6379 start Starting Redis server... ┌──[root@vms153.liruilongs.github.io]-[~] └─$/etc/init.d/redis_6379 status Redis is running (11179) ┌──[root@vms153.liruilongs.github.io]-[~] └─$
在156 机器上测试
1 2 3 4 5 6
┌──[root@vms156.liruilongs.github.io]-[~/redis-stable] └─$redis-cli -h 192.168.26.153 -p 6350 -a liruilong Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 192.168.26.153:6350> GET * (nil) 192.168.26.153:6350>
┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$cat -n /etc/redis/6379.conf | grep -v ^$ | grep -A 10 MAXMEMORY 1122 # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory 1123 # is reached. You can select one from the following behaviors: 1124 # 1125 # volatile-lru -> Evict using approximated LRU, only keys with an expire set. 1126 # allkeys-lru -> Evict any key using approximated LRU. 1127 # volatile-lfu -> Evict using approximated LFU, only keys with an expire set. 1128 # allkeys-lfu -> Evict any key using approximated LFU. 1129 # volatile-random -> Remove a random key having an expire set. 1130 # allkeys-random -> Remove a random key, any key. 1131 # volatile-ttl -> Remove the key with the nearest expire time (minor TTL) 1132 # noeviction -> Don't evict anything, just return an error on write operations. ┌──[root@vms153.liruilongs.github.io]-[~/redis-stable] └─$
# To enable logging to the system logger, just set 'syslog-enabled' to yes, # and optionally update the other syslog parameters to suit your needs. # syslog-enabled no # syslog-ident redis # syslog-facility local0
# 数据库个数 databases {{ redis_databases }}
# 写入磁盘配置 {% for save in redis_save %} save {{ save }} {% endfor %}