以centos7.9.2009离线安装reids6.2.9为例
redis的tar包下载平台
http://download.redis.io/releases/
1.安装准备
redis是c语⾔开发的,安装redis需要c语⾔的编译环境,需要安装gcc(默认安装)
redis的源码中,有一些测试和脚本是使用tcl编写的,需要安装tcl(默认不安装)
yum -y install gcc tcl
2.gcc版本切换
centos7默认安装的gcc版本是4.8.5,而redis6.0只支持5.3以上版本,因此将gcc升级到9
安装centos-release-scl
软件包,即在系统上启用了scl(Software Collections)存储库,允许在系统上安装不同版本的软件,相互独立,不会干扰。
安装Devtoolset-9的GCC编译器devtoolset-9-gcc
安装Devtoolset-9的GCC编译器devtoolset-9-gcc-c++
安装Devtoolset-9的Binutils工具集devtoolset-9-binutils
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
通过scl,暂时性地启用devtoolset-9
的软件集合,而不会影响到系统中默认的工具链,退出当前终端,激活将会被取消。
scl enable devtoolset-9 bash
设置环境变量和路径,启用 devtoolset-9
软件集合,指令追加到 /etc/profile
文件的末尾,被永久激活。
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
#回退方法:删除/etc/profile中的内容
[root@localhost ~]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
#切换版本后
[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)
3.安装过程
创建安装目标路径及子目录
mkdir -p /data/redis/{conf,logs,run}
下载目标版本redis的tar包,解压
wget https://download.redis.io/releases/redis-6.2.9.tar.gz
tar -zxvf redis-6.2.9.tar.gz
编译安装
make
make install PREFIX=/data/redis/
配置文件粘贴
cp /data/redis-6.2.9/redis.conf /data/redis/conf
4.服务启动
启动命令
/data/redis/bin/redis-server /data/redis/conf/redis.conf
创建启动、停止脚本
#服务启动脚本
touch /data/redis/start.sh
#!/bin/bash
/data/redis/bin/redis-server /data/redis/conf/redis.conf
#服务停止脚本
touch /data/redis/stop.sh
#!/bin/bash
pid=\`ps -ef|grep "/data/redis/bin/redis-server"|grep -v "grep"| awk '{print \$2}'\`
if [ "\${pid}" ];then
echo "kill \${pid}"
kill \${pid}
fi
chmod +x /data/redis/*.sh
5.配置修改
复制示例配置并剔除注释内容
cp /data/redis-6.2.9/redis.conf /data/redis/conf/redisbaseconf
cd /data/redis/conf/
cat redisbaseconf |grep -Ev "^#|^$" >> redis.conf
需要修改配置如下
1.Redis取消IP绑定,注释bind 127.0.0.1这行,只能本地连接redis,不然无法使用远程连接。
# bind 127.0.0.1
2.Redis关闭保护模式,将protected-mode的yes改为no,也是开启远程连接。
protected-mode no
3.修改redis的默认日志存放位置
logfile /data/redis/logs/redis.log
4.修改redis的服务路径
dir /data/redis/
5.添加redis密码:requirepass + 密码(不需要可省略)
requirepass 123456
可选修改配置(示例未添加)
1.pid存储路径
pidfile /data/redis/run/redis_6379.pid
2.监听端口
port 6379
最终配置呈现
#bind 127.0.0.1 -::1
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /data/redis/logs/redis.log
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /data/redis/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
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 yes
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
6.服务管理
创建redis的systemctl
管理文件
vim /usr/lib/systemd/system/redis.service
文件内容为:
[Unit]
Description=redis
After=network.target
[Service]
Type=forking
ExecStart=/data/redis/bin/redis-server /data/redis/conf/redis.conf
ExecReload=/data/redis/bin/redis-server -s reload
ExecStop=/data/redis/bin/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
当Systemd系统服务的配置文件修改后,需要重新加载Systemd守护进程管理器的配置文件,用以生效配置。
systemctl daemon-reload
systemctl start redis
标签:gcc,enable,no,--,离线,redis,centos7,data,reids6
From: https://www.cnblogs.com/Hughes87/p/18110277