redis运维(三)redis6.0.8安装

①  官网下载稳定版本

wget http://download.redis.io/releases/redis-6.0.8.tar.gz

redis运维(三)redis6.0.8安装_第1张图片

安装文档

②  yum安装gcc

redis运维(三)redis6.0.8安装_第2张图片

redis6.0.0+ '需要' gcc到'5.3及以上版本'

通过'安装devtoolset的方式'间接升级gcc'指定'版本

------  '安装指定版本gcc'  ------

yum -y install centos-release-scl

# 安装指定版本  yum -y install devtoolset-{7,8,9}-gcc*

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

注意:scl命令启用只是'临时的',退出shell或重启'就会恢复原系统gcc版本'

需求:如果要长期使用对应版本的gcc,写入系统脚本,'永久生效' -->'注意这里的数字9'

echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

③  编译安装redis

tar -zxf redis-6.0.8.tar.gz

cd redis-6.0.8

'安装systemd的开发包'
yum install -y systemd-devel

'编译' -->'systemd管理'

make USE_SYSTEMD=yes

'编译安装'到'指定目录' -->移动文件到'指定目录'

make  install   

'进入工具目录'

cd utils/

cp systemd-redis_server.service /etc/systemd/system/

-------'redis-trib.rb'-------

redis-6.0.8/src/redis-trib.rb

redis-trib.rb命令详解

redis运维(三)redis6.0.8安装_第3张图片

make PREFIX=/usr/local/redis install

redis运维(三)redis6.0.8安装_第4张图片

④   redis systemd管理

redis运维(三)redis6.0.8安装_第5张图片

make install  --> '默认是移动到' --> '/usr/local/bin/' -->'跟service文件适配'

redis运维(三)redis6.0.8安装_第6张图片

普通用户的身份启动

'判断是否有该用户'

id redis || (groupadd redis && useradd redis -M -g redis -s /sbin/nologin)

解释 :

 1、-M '不创建主目录' 

 2、-s '不允许登录' /sbin/nologin redis 

 3、-g '加入redis组'

⑤   修改配置文件

sed -i  /etc/systemd/system/systemd-redis_server.service --> '修改'

'/usr/lib/systemd/system目录'

'注意' notify 会失败,'换成 forking 方式启动',让主进程'复制一个子进程'的方式执行

27  

34  Type=forking

38  User=redis

39  Group=redis

------ 'redis.conf'的位置  ------ 

vim redis-6.0.8/redis.conf  

备注: 最好移动到/etc目录 -->'chown redis /etc/redis.conf'

# 将 no 改为 yes,表示以'后台方式启动'服务

225 daemonize yes

# 将 no 改为 systemd,表示以 'CentOS systemd' 系统服务方式启动

236 supervised systemd

------ 'sentinel.conf'的位置  ------ 

redis-6.0.8/sentinel.conf  

备注: 最好也移动到'/etc'目录 -->'chown redis /etc/sentinel.conf'

⑥   service文件

  1 # example systemd service unit file for redis-server
  2 #
  3 # In order to use this as a template for providing a redis service in your
  4 # environment, _at the very least_ make sure to adapt the redis configuration
  5 # file you intend to use as needed (make sure to set "supervised systemd"), and
  6 # to set sane TimeoutStartSec and TimeoutStopSec property values in the unit's
  7 # "[Service]" section to fit your needs.
  8 #
  9 # Some properties, such as User= and Group=, are highly desirable for virtually
 10 # all deployments of redis, but cannot be provided in a manner that fits all
 11 # expectable environments. Some of these properties have been commented out in
 12 # this example service unit file, but you are highly encouraged to set them to
 13 # fit your needs.
 14 #
 15 # Please refer to systemd.unit(5), systemd.service(5), and systemd.exec(5) for
 16 # more information.
 17 
 18 [Unit]
 19 Description=Redis data structure server
 20 Documentation=https://redis.io/documentation
 21 #Before=your_application.service another_example_application.service
 22 #AssertPathExists=/var/lib/redis
 23 Wants=network-online.target
 24 After=network-online.target
 25 
 26 [Service]
 27 ExecStart=/usr/local/bin/redis-server  /etc/redis.conf --supervised systemd
 28 ## Alternatively, have redis-server load a configuration file:
 29 #ExecStart=/usr/local/bin/redis-server /path/to/your/redis.conf
 30 LimitNOFILE=10032
 31 NoNewPrivileges=yes
 32 #OOMScoreAdjust=-900
 33 #PrivateTmp=yes
 34 Type=forking
 # TimeoutStartSec=infinity
 # TimeoutStopSec=infinity
 37 UMask=0077
 38 User=redis
 39 Group=redis                                                                                                                                                                                                    
 # WorkingDirectory=/var/lib/redis
 41 
 42 [Install]
 43 WantedBy=multi-user.target

redis运维(三)redis6.0.8安装_第7张图片

redis报错解决

其它报错,参数覆盖

'日志文件需要自己创建' -->并且'修改属性'

chown redis.redis /var/log/redis-server.log

三个告警

相关报错的处理

⑦   日志和rdb文件

'默认是' --> logfile "" -->导入到'/dev/null'

logfile "/var/log/redis-servre.log"

touch /var/log/redis-servre.log

chown redis.redis /var/log/redis-servre.log

------------ 'rdb文件' ------------

'默认' --> dir ./

dir /var/lib/redis/

mkdir -p /var/lib/redis/

chown redis.redis /var/lib/redis


------------ '之后重启' ------------

参考1

参考2

你可能感兴趣的:(redis,redis,运维,NoSql)