2021-05-12 14:32:11
CentOS 7 安裝Redis
2020-06-16 17:05:11
系統環境和版本說明
Linux依然使用的是CentOS 7,安裝的redis是官網的最新的版本4.0.2
安裝步驟
下載安裝包:
https://redis.io/download
建立檔案目錄:
# mkdir /usr/local/redis
解壓檔案
# tar xvfz redis-4.0.2.tar.gz
進入解壓檔案
# cd /usr/local/redis/redis-4.0.2/
# ls
總用量 280
-rw-rw-r--. 1 root root 131381 9月 21 22:12 00-RELEASENOTES
-rw-rw-r--. 1 root root 53 9月 21 22:12 BUGS
-rw-rw-r--. 1 root root 1815 9月 21 22:12 CONTRIBUTING
-rw-rw-r--. 1 root root 1487 9月 21 22:12 COPYING
drwxrwxr-x. 6 root root 4096 9月 21 22:12 deps
-rw-rw-r--. 1 root root 11 9月 21 22:12 INSTALL
-rw-rw-r--. 1 root root 151 9月 21 22:12 Makefile
-rw-rw-r--. 1 root root 4223 9月 21 22:12 MANIFESTO
-rw-rw-r--. 1 root root 20530 9月 21 22:12 README.md
-rw-rw-r--. 1 root root 57764 9月 21 22:12 redis.conf
-rwxrwxr-x. 1 root root 271 9月 21 22:12 runtest
-rwxrwxr-x. 1 root root 280 9月 21 22:12 runtest-cluster
-rwxrwxr-x. 1 root root 281 9月 21 22:12 runtest-sentinel
-rw-rw-r--. 1 root root 7606 9月 21 22:12 sentinel.conf
drwxrwxr-x. 3 root root 4096 9月 21 22:12 src
drwxrwxr-x. 10 root root 4096 9月 21 22:12 tests
drwxrwxr-x. 8 root root 4096 9月 21 22:12 utils
設定編譯環境
# yum install gcc-c++
編譯
# make
如果報錯:jemalloc/jemalloc.h:沒有那個檔案或目錄
使用:
make MALLOC=libc
# make install
cd src && make install
make[1]: 進入目錄“/usr/local/redis/redis-4.0.2/src”
CC Makefile.dep
make[1]: 離開目錄“/usr/local/redis/redis-4.0.2/src”
make[1]: 進入目錄“/usr/local/redis/redis-4.0.2/src”
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: 離開目錄“/usr/local/redis/redis-4.0.2/src”
啟動Redis-server
# redis-server
Ctrl+shift+t 重開一個終端tab
檢視Redis
$ ps -ef | grep redis
root 5188 3749 0 22:46 pts/0 00:00:00 redis-server *:6379
xcx 5235 5200 0 22:46 pts/1 00:00:00 grep --color=auto redis
啟動Redis-client
$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
基本安裝完成
此時重新啟動系統,發現redis並沒有啟動,所以需要設定redis自啟,
這裡我們進入utils資料夾
# cd /usr/local/redis/redis-4.0.2/utils
切換root使用者,執行裡面的install_server.sh該檔案會幫助我們將redis服務新增到系統自啟服務中
# ./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/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/bin/redis-server
Cli Executable : /usr/local/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...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
這是再重新啟動系統,就會發現redis跟隨系統自動啟動了
如果需要外部存取,需要修改組態檔:
# vim /etc/redis/6379.conf
#bind 127.0.0.1
bind 0.0.0.0
#daemonize no
daemonize yes
防火牆開放6379埠
# firewall-cmd --permanent --zone=public --add-port=6379/tcp
# firewall-cmd --reload
重新啟動redis服務後就可以外部存取了
下面關於Redis的文章您也可能喜歡,不妨參考下:
相關文章