一、安裝redis
# 安裝wget
yum install -y wget
# 建立並進入目錄
mkdir /home/softs &&
cd /home/softs
wget
# 解壓
tar -xzvf redis-5.0.8.tar.gz
# 進入redis目錄
cd redis-5.0.8
# 安裝依賴
yum -y install gcc gcc-c++
# 執行編譯安裝 目錄/usr/local/redis
make prefix=/usr/local/redis install
# 建立配置檔案目錄
mkdir -p /usr/local/redis/etc/
# 複製預設配置檔案到目錄
cp redis.conf /usr/local/redis/etc/
# 編輯配置檔案
vi /usr/local/redis/etc/redis.conf
/usr/local/redis/etc/redis.conf檔案修改以下幾行
# 取消ip繫結
bind 127.0.0.1 =
>
# bind 127.0.0.1
# 關閉保護模式
protected-mode yes
=> protected-mode no
# 修改埠
port 6379
# 開啟後台守護模式
daemonize no =
> daemonize yes
# 設定遠端密碼
requirepass foobared =
> requirepass 密碼
二、建立啟動指令碼# 建立init.d檔案
vi /etc/init.d/redis
init.d檔案內容:
#! /bin/bash
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: 2345 80 90
# description: redis is a persistent key-value database
#
### begin init info
# provides: redis
# required-start: $syslog
# required-stop: $syslog
# should-start: $local_fs
# should-stop: $local_fs
# default-start: 2 3 4 5
# default-stop: 0 1 6
# short-description: redis-server daemon
# description: redis-server daemon
### end init info
redisport=8005
exec=/usr/local/redis/bin/redis-server
redis_cli=/usr/local/redis/bin/redis-cli
pidfile=/var/run/redis_6379.pid
conf=
"/usr/local/redis/etc/redis.conf"
case
"$1"
in start)
if[ -f "$pidfile"];
then
echo
"$pidfile exists, process is already running or crashed"
else
echo -n "starting redis server..."
$exec
$confif[
"$?"
="0"];
then
echo
" done"
else
echo
" failed"
fifi;;
stop)if[
! -f "$pidfile"];
then
echo
"$pidfile does not exist, process is not running"
else
pid=
$(cat $pidfile)
echo
"stopping redis server..."
$redis_cli -p $redisport
shutdownif[
"$?"
="0"];
then
echo
" done"
else
echo
" failed"
fifi;;
restart)
$ stop
$ start
;; kill)
echo
"force kill redis server..."
killall redis-server
if["$?"
="0"];
then
echo
" done"
else
echo
" failed"fi;
; status)
if[ -f "$pidfile"];
then
echo
"redis server is running."
else
echo
"redis server is stopped."fi;
; *)
echo
"usage: /etc/init.d/redis "
>
&2 exit 1
esac
# 修改許可權
chmod +x /etc/init.d/redis
# 啟動
/etc/init.d/redis start
# 設定開機自動啟動
chkconfig redis on
三、設定防火牆# 啟動服務
systemctl start firewalld.service
# 放行埠
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 過載配置
firewall-cmd --reload
# 檢視配置
firewall-cmd --list-all
# 開啟自動啟動
systemctl enable firewalld.service
centos7 安裝redis和redis擴充套件
安裝redis make 如果make失敗,請安裝gcc yum install gcc 重新解壓安裝 使用 二進位制檔案是編譯完成後在src目錄下.執行如下 src redis server 你能使用redis的內建客戶端進行進行redis 的編寫 src redis cli redis setf...
centos7 安裝redis和redis擴充套件
安裝redis make 如果make失敗,請安裝gcc yum install gcc 重新解壓安裝 使用 二進位制檔案是編譯完成後在src目錄下.執行如下 src redis server 你能使用redis的內建客戶端進行進行redis 的編寫 src redis cli redis setf...
Centos7 安裝redis服務
1.先安裝gcc編譯器,否則make的時候會報錯 yum y install gcc wget io releases redis 4.0 1.tar gz tar xzf redis 4.0 1.tar gz cd redis 4.0 1 make3.二進位制檔案是編譯完成後在src目錄下,通過下...