文章目录
- 前言
- 步骤
- 1、下载redis并解压到指定路径
- 2、make 和 make install
- 3、配置redis.conf
- 4、制作启动脚本
- 5、授权并启动
前言
我安装了很多次redis,包括redis安装、redis安装、或者使用ansible等自动化构建安装,但是直接用安装包安装还是比较少。
今天突然想从官网下载linux安装包来进行安装,故写此文进行分享
案例我也是从网上查的,感谢之前的网友的贡献,具体我也不清楚是谁。但是我写的,一定比网上的更加详细,为各位新手做指导。
步骤
1、下载redis并解压到指定路径
2、make 和 make install
3、配置redis.conf
4、制作启动脚本
5、授权并启动
如果不按文中路径放置,需自行修改路径
1、下载redis并解压到指定路径
mkdir -p /opt/softwarePackage
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
# 解压
tar -xvf redis-5.0.8.tar.gz
# 移动到安装路径
mv redis-5.0.8 /usr/local/
2、make 和 make install
cd /usr/local/redis-5.0.8/
# 安装gc
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
# 执行make
make MALLOC=libc
make install
3、配置redis.conf
# 创建redis放置文件
mkdir -p /data/redis/data
cd /data/redis
vi redis.conf
填写入以下内容
#bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/redis/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
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-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
4、制作启动脚本
cd /data/redis
vi redis-run.sh
填写入以下内容
#!/bin/bash
# chkconfig: 2345 10 90
# description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis-5.0.8/src/redis-server #redis服务端的命令
REDIS_CLI=/usr/local/redis-5.0.8/src/redis-cli #redis客户端的命令 这两个一般都在 PATH目录下
PIDFILE=/data/redis/redis_6379.pid #reids的进程文件生成的位置
CONF=/data/redis/redis.conf #redis的配置文件所在的目录
case "$1" instart)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed." elseecho "Starting Redis server..."$EXEC $CONFfiif [ "$?"="0" ]thenecho "Redis is running..."fi;;stop)if [ ! -f $PIDFILE ] thenecho "$PIDFILE exists, process is not running." else PID=$(cat $PIDFILE) echo "Stopping..." $REDIS_CLI -p $REDISPORT SHUTDOWN sleep 2 while [ -x $PIDFILE ] do echo "Waiting for Redis to shutdown..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1
esac
5、授权并启动
cd /data/redis
chmod +x redis-run.sh
启动
./redis-run.sh start
停止
./redis-run.sh stop