非docker
1、下載Redis
歷史版本:
http://download.redis.io/releases
我的:
http://download.redis.io/releases/redis-7.0.5.tar.gz
2.安裝教程
1.Redis是基于c語言編寫的需要安裝依賴,需要安裝gcc
yum install gcc-c++
2.查看gcc版本:
gcc -v
3.解壓:
tar -xvf redis-7.0.5.tar.gz
4.進入 redis-7.0.5 目錄執行:
make
5.執行成功后再次:
make
6.完成后執行:
make install
7.redis默認安裝路徑:/usr/local/bin
在/usr/local/bin新建目錄 redisconfig
cd /usr/local/binmkdir redisconfigcp /data/ybn/redis-7.0.5/redis.conf /usr/local/bin/redisconfig
8.修改redis.conf文件中的一些配置
#默認127.0.0.1,會導致只能在本地訪問。
#修改為0.0.0.0則可以在任意IP訪問,生產環境不要設置為0.0.0.0
bind 0.0.0.0
# 守護進程,修改為yes后即可后臺運行
daemonize yes
# 密碼,設置后訪問Redis必須輸入密碼
requirepass 123456######其他配置,可不設置##########
#端口
port 6379
#數據庫數量,設置為1,代表只使用1個庫,默認有16個庫
databases 1
#設置redis能夠使用的最大內存
maxmemory 512mb
#日志文件,默認為空,不記錄日志,可以指定日志文件名
logfile "redis.log"
9.指定配置文件啟動redis測試
redis-server redisconfig/redis.conf
啟動成功
3.設置Redis開機自啟動
首先,新建一個系統服務文件:
vim /etc/systemd/system/redis.service
內容如下:
[Unit]
Description=redis-server
After=network.target[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/bin/redisconfig/redis.conf
PrivateTmp=true[Install]
WantedBy=multi-user.target
然后重載系統服務:
systemctl daemon-reload
操作redis命令:
# 啟動
systemctl start redis
# 停止
systemctl stop redis
# 重啟
systemctl restart redis
# 查看狀態
systemctl status redis
設置開機自啟:
systemctl enable redis