redis5.0 原始碼安裝手冊(適用於任何linux系統 本文以ubuntu16 做為例子)
阿新 • • 發佈:2021-07-30
redis5.0 原始碼安裝手冊(適用於任何linux系統)
一 安裝並配置開機自啟動
建立安裝目錄 /usr/local/redis5 解壓 tar -zxvf redis-5.0.13.tar.gz cd redis-5.0.13 make cd redis-5.0.13/src sudo make install PREFIX=/usr/local/redis5 配置環境變數 sudo vim /etc/profile export REDIS_HOME=/usr/local/redis5 export PATH=$PATH:$REDIS_HOME/bin 切換root使用者讓配置立即生效 source /etc/profile 安裝redis服務 切換到工具資料夾 cd redis-5.0.13/utils root@ubuntu:/home/zmh/redis-5.0.13/utils# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/redis5/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/redis5/bin/redis-server Cli Executable : /usr/local/redis5/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Success! Starting Redis server... 測試 root@ubuntu:/home/zmh/redis-5.0.13/utils# redis-cli 127.0.0.1:6379> set test test OK 127.0.0.1:6379> 服務關閉 service redis_6379 stop 服務啟動 service redis_6379 start 檢視服務狀態 service redis_6379 status ● redis_6379.service - LSB: start and stop redis_6379 Loaded: loaded (/etc/init.d/redis_6379; bad; vendor preset: enabled) Active: active (running) since Fri 2021-07-30 15:33:00 CST; 1min 25s ago Docs: man:systemd-sysv-generator(8) Process: 1513 ExecStop=/etc/init.d/redis_6379 stop (code=exited, status=0/SUCCESS) Process: 1551 ExecStart=/etc/init.d/redis_6379 start (code=exited, status=0/SUCCESS) Tasks: 4 Memory: 2.1M CPU: 113ms CGroup: /system.slice/redis_6379.service └─1555 /usr/local/redis5/bin/redis-server 127.0.0.1:6379 Jul 30 15:33:00 ubuntu systemd[1]: Starting LSB: start and stop redis_6379... Jul 30 15:33:00 ubuntu redis_6379[1551]: Starting Redis server... Jul 30 15:33:00 ubuntu systemd[1]: Started LSB: start and stop redis_6379 設定遠端訪問(正式環境儘量不要開啟遠端訪問,如果要開啟則要設定遠端訪問密碼) 先關閉服務 service redis_6379 stop vim /etc/redis/6379.conf 找到 :/bind bind 0.0.0.0 protected-mode no 修改好後重新啟動 service redis_6379 start
二 持久化配置
redis4.0 開始支援RDB-AOF混合持久化 vim /etc/redis/6379.conf 開啟混合模式 aof-use-rdb-preamble yes rdb是預設開啟的 # The filename where to dump the DB dbfilename dump.rdb # The working directory. # # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. # # The Append Only File will also be created inside this directory. # # Note that you must specify a directory here, not a file name. dir /var/lib/redis/6379 這裡我們開啟AOF appendonly yes # The name of the append only file (default: "appendonly.aof") appendfilename "appendonly.aof" 儲存後重啟 服務關閉 service redis_6379 stop 服務啟動 service redis_6379 start