redis運維(三)redis6.0.8安裝

wzj_110發表於2020-09-25

(1)官網下載穩定版本

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

(2)安裝文件

1)yum安裝gcc

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

2)編譯安裝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命令詳解 

make PREFIX=/usr/local/redis install

make install  --> '預設是移動到' --> '/usr/local/bin/' -->'跟service檔案適配'

普通使用者的身份啟動

'判斷是否有該使用者'

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

'解釋':useradd -M '不建立主目錄' -s '不允許登入' /sbin/nologin redis -g '加入redis組' 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報錯解決

其它報錯,引數覆蓋

'日誌檔案需要自己建立' -->並且'修改屬性'

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

三個告警

參考1

參考2

 

 

相關文章