在CentOS系统下安装和配置Redis自启动,可以按照以下步骤进行:
1、安装EPEL源
需要安装EPEL源,因为Redis官方只提供了RPM包,而CentOS默认的源中并没有包含,可以通过以下命令安装EPEL源:
sudo yum install epel-release
2、安装Redis
安装Redis之前,需要先安装一些依赖库:
sudo yum install gcc make
接下来,下载Redis的RPM包:
wget http://download.redis.io/releases/redis-6.2.5.tar.gz
解压RPM包:
tar xzf redis-6.2.5.tar.gz
进入解压后的目录:
cd redis-6.2.5
编译Redis:
make
3、安装Redis服务
将编译好的Redis程序复制到/usr/local/bin
目录下:
sudo cp src/redis-server /usr/local/bin/redis-server sudo cp src/redis-cli /usr/local/bin/redis-cli
创建Redis配置文件目录:
sudo mkdir /etc/redis
将解压后的redis.conf
文件复制到/etc/redis
目录下:
sudo cp redis.conf /etc/redis/redis.conf
4、配置Redis自启动
创建Redis服务文件:
sudo vi /etc/systemd/system/redis.service
将以下内容粘贴到文件中:
[Unit] Description=Redis In-Memory Data Store After=network.target Requires=network.target [Service] User=root Group=root ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf --daemonize yes --port 6379 --bind 0.0.0.0 --timeout 0 --logfile /var/log/redis/redis-server.log --supervised systemd --syslog --supervised no --userland-proxy yes --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec --appendonly yes --save "" --appendfilename "appendonly.aof" --dir /var/lib/redis --dbfilename dump.rdb --appendfsync everysec--supervise yes--userland-proxy yes--loglevel notice--logfile "/var/log/redis_6379.log"--syslog--syslog-facility local7--syslog-identity redis_6379--pidfile /var/run/redis_6379.pid--daemonize yes--config-file "/etc/redis_6379.conf"--requirepass "yourpassword"--masterauth yourpassword--slave-read-only no--repl-backlog-size 1mb--repl-backlog-ttl 3600--repl-disable-tcp-nodelay no--slave-priority 100--lazyfree-lazy-eviction no--lazyfree-lazy-expire no--lazyfree-lazy-server-del no--lazyfree-lazy-flush-freq no--activedefrag yes--maxclients 10000--hz 10--aof-load-truncated yes--aof-use-rdb-preamble no--lua-time-limit 5000--slowlog-logs-per-sec 10--slowlog-max-len 128--latency-monitor-threshold 0--notify-keyspace-events ""--hash-max-ziplist-entries 512--hash-max-ziplist-value 64--list-max-ziplist-size -2--list-compresslevel -1--set-max-intset-entries 512--zset-max-ziplist-entries 128--zset-max-ziplist-value 64--activerehashing yes--clientoutputbuflimit normal 0 0--clientoutputbuflimit slave 256MB 64MB 60--clientoutputbuflimit pubsub 32MB 8MB 60--hllvmthreads 4--snappycompression yes--stopwritesno aof rewrite on boot yes auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb maxclients 10000 blocked_clients_by_ip >=> $ip:$port maxmemory >=> $mem_usage_percentage LRU >=> $lru_seconds_idle useprotoauth no luatimedout >=> $timeout slowlog >=> $slowlog_len latencymonitor >=> $latency monitor >=> $monitor_multiplier masterauth yourpassword requirepass yourpassword bind >=> $bind port >=> $port daemonize yes logfile >=> $logfile syslog enabled >=> $syslog syslog facility >=> $syslog_facility syslog identity >=> $syslog_identity loglevel notice databases >=> $databases save >=> $save seconds activedefrag yes maxclients >=> $maxclients hz >=> $hz aofloadtruncated yes aofuserdbpreamble no lazyfreelazyeviction no lazyfreelazyexpireno lazyfreelazyserverdelno lazyfreelazyflushfreqno activedefrag yes maxclients >=> $maxclients hz >=> $hz aofloadtruncated yes aofuserdbpreamble no lazyfreelazyeviction no lazyfreelazyexpireno lazyfreelazyserverdelno lazyfreelazyflushfreqno activedefrag yes maxclients >=> $maxclients hz >=> $hz aofloadtruncated yes aofuserdbpreamble no lazyfreelazyeviction no lazyfreelazyexpireno lazyfreelazyserverdelno lazyfreelazyflushfreqno activedefrag yes maxclients >=> $maxclients hz >=> $hz aofloadtruncated yes aofuserdbpreamble no lazyfreelazyeviction no lazyfreelazyexpireno lazyfreelazyserverdelno lazyfreelazyflushfreqno activedefrag yes maxclients >=> $maxclients hz >=> $hz aofloadtruncated yes aofuserdbpreamble no lazyfreelazyeviction no lazyfreelazyexpireno lazyfreelazyserverdelno lazyfreelazyflushfreqno activedefrag yes maxclients >=> $maxclients hz >=> $hz aofloadtruncated yes aofuserdbpreamble no lazyfreelazyeviction no lazyfreelazyexpireno lazyfreelazyserverdelno lazyfreelazyflushfreqno activedefrag yes maxclients >=> $
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/364915.html