Linux 安裝 Redis

Linux 安裝 Redis

本例子在 redis-5.0.5.tar.gz 中測試成功

安裝

# 下載
wget http://download.redis.io/releases/redis-5.0.5.tar.gz

# 解壓
tar -zxvf redis-5.0.5.tar.gz 

# 進入解壓目錄
cd redis-5.0.5/

# 指定目錄並安裝,服務被安裝在 /home/shaw/server/redis5 中
make PREFIX=/home/shaw/server/redis5 install

# 測試是否安裝成功
make test

# 刪除解壓縮文件
cd ../
rm -rf redis-5.0.5/

啓動運行

# 使用指定的 Redis 配置文件進行運行
/home/shaw/server/redis5/bin/redis-server /home/shaw/server/redis5/redis.conf

常用配置(redis.conf)

允許外網訪問

註釋掉 bind 127.0.0.1 即可

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
# 
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

開啓守護進程(後臺運行)

設置 daemonize yes 即可

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

設置密碼

取消 requirepass foobared 註釋,並將 foobared 修改爲自己期望的密碼即可;

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
# 
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
# 
# requirepass foobared

使用 redis 自帶工具配置 Redis

shaw@shaw-pc:~/server/redis-install/utils$ cd /home/shaw/server/redis-install/
shaw@shaw-pc:~/server/redis-install$ cd utils/
shaw@shaw-pc:~/server/redis-install/utils$ sudo su
root@shaw-pc:/home/shaw/server/redis-install/utils#
root@shaw-pc:/home/shaw/server/redis-install/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] /home/shaw/server/redis5/635^C
root@shaw-pc:/home/shaw/server/redis-install/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] /home/shaw/server/redis5/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /home/shaw/server/redis5/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /home/shaw/server/redis5/6379
Please select the redis executable path [] /home/shaw/server/redis5/bin/redis-server
Selected config:
Port : 6379
Config file : /home/shaw/server/redis5/6379.conf
Log file : /home/shaw/server/redis5/redis_6379.log
Data dir : /home/shaw/server/redis5/6379
Executable : /home/shaw/server/redis5/bin/redis-server
Cli Executable : /home/shaw/server/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...
Installation successful!

redis-cli

連接服務

redis-cli -h localhost -p 6379 -a myredispassword
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章