设为首页 收藏本站
查看: 596|回复: 0

[经验分享] redis安装-启动

[复制链接]

尚未签到

发表于 2016-12-17 09:18:25 | 显示全部楼层 |阅读模式
 
安装:
  从官网(http://download.redis.io/)下载redis 包 redis-stable.tar.gz,
  解压安装:
   tar -xzvf redis-stable.tar.gz
    cd redis-stable
    make
  编译之后:
  
  执行程序在redis-stable/src下:
  redis-server:redis服务器启动程序
  redis-cli :redis 命令行客户端
  ( 可以将这两个程序copy 出来,这两个程序对源文件redis-stable没有依赖。)
  默认配置文件redis-stable/src下:
  redis.conf 可以配置 redis 启动端口 数据库文件存储路径等
  
  redis启动:
  redis-server //(直接启动 默认端口6379 数据库文件在当前路径下dump.rab)
  redis-server --port 6838 //(指定端口启动 数据库文件在当前路径下dump.rab)
  redis-server /路径/redis.conf   //指定配置文件方式启动
 
  redis停止:
   方式一: redis-cli shutdown //连接 127.0.0.1 端口为6379的redis server ,并发送shutdown请求
   
   方式二: redis-cli -h ip -p port 通过ip和port 连接redis server ,连接成功后,在提示符下输出 shutdown   
    
    redis server 接收到停止信息,先断掉连接,再持久化数据到数据库文件,最后退出
  
  配置redis:
  配置方式:
  方式一:redis-cli 连接到redis-server后,在命令提示符下执行 config set field value ,不必重启redis-server
  方式二:启动redis-server时指定配置文件 如:redis-server /redis_home/etc/redis.conf
 
 redis.conf   基本配置项:
  daemonize 默认值 no 是否为守护进程
  pidfile         默认值 /var/run/redis.pid  pid文件路径
  port            默认值  6379 redis-server 端口号
  databases  默认值  16 redis 数据库个数
  dbfilename 默认值 dump.rdb 持久化文件名
  dir               默认值  ./  持久化文件路径
 
 配置redis目录结构:
 
 /app/redis> ls -lR
 
drwxr-xr-x 2   13:58 bin 
drwxr-xr-x 2   13:47 data
drwxr-xr-x 2   09:31 etc
drwxr-xr-x 2   09:31 logs
drwxr-xr-x 2   09:31 pid
 
./bin://redis 可执行程序及启动脚本
-rwxr-xr-x 1  15:56 redis-6379 //启动脚本
-rwxr-xr-x 1   13:52 redis-cli //redis命令行客户端
-rwxr-xr-x 1   13:52 redis-server//redis 服务器
 
./data:
-rw-r--r-- 1   13:47 dump_6379.rdb //redis 持久化文件
 
./etc:
-rw-r--r-- 1   redis_6379.conf //redis 配置文件
  -rw------- 1    redis.conf //redis包中自带的redis配置文件
   
./pid:
-rw-r--r-- 1 vgop vgop 6 2014-12-02 09:31 redis_6379.pid //redis pidfile
   ./logs:
  -rw-r--r-- 1 vgop vgop 2072 2014-12-11 14:54 redis_6379.log //日志文件
 
 
redis-6379脚本:

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDIS_HOME=/app/redis
REDISPORT=6379
EXEC=${REDIS_HOME}/bin/redis-server
CLIEXEC=${REDIS_HOME}/bin/redis-cli
PIDFILE=${REDIS_HOME}/pid/redis_${REDISPORT}.pid
CONF=${REDIS_HOME}/etc/redis_${REDISPORT}.conf
LOGFILE=${REDIS_HOME}/logs/redis_${REDISPORT}.log
DBFILE=${REDIS_HOME}/data/dump_${REDISPORT}.rdb
echo "pid file :${PIDFILE}"
echo "conf file:${CONF}"
echo "log file:${LOGFILE}"
echo "rdb file:${DBFILE}"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
client)
echo "connect to reids server :host=localhost ,port=$REDISPORT"
$CLIEXEC -h localhost -p $REDISPORT
;;
*)
echo "Please use start or stop as first argument"
;;
esac

 启动方式:redis-6379 start
 停止方式:redis-6379 stop
 redis客户端连接服务端:redis-6379 client
 
 配置文件redis_6379.conf中:
#引入默认配置
  include /app/redis/etc/redis.conf 
  #以下覆盖默认配置
  daemonize yes
  port 6379
  dir  /app/redis/data/
  dbfilename dump_6379.rdb
  pidfile  /app/redis/pid/redis_6379.pid
  logfile  /app/redis/logs/redis_6379.log
   
注意:配置文件要与redis-6379中pid、logfile、dbfile路径相对应
 
 
 

1.启动 redis服务器
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>
Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose
Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel
2.redis命令行客户端
Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h <hostname>      Server hostname (default: 127.0.0.1).
-p <port>          Server port (default: 6379).
-s <socket>        Server socket (overrides hostname and port).
-a <password>      Password to use when connecting to the server.
-r <repeat>        Execute specified command N times.
-i <interval>      When -r is used, waits <interval> seconds per command.
It is possible to specify sub-second times like -i 0.1.
-n <db>            Database number.
-x                 Read last argument from STDIN.
-d <delimiter>     Multi-bulk delimiter in for raw formatting (default: \n).
-c                 Enable cluster mode (follow -ASK and -MOVED redirections).
--raw              Use raw formatting for replies (default when STDOUT is
not a tty).
--no-raw           Force formatted output even when STDOUT is not a tty.
--csv              Output in CSV format.
--latency          Enter a special mode continuously sampling latency.
--latency-history  Like --latency but tracking latency changes over time.
Default time interval is 15 sec. Change it using -i.
--slave            Simulate a slave showing commands received from the master.
--rdb <filename>   Transfer an RDB dump from remote server to local file.
--pipe             Transfer raw Redis protocol from stdin to server.
--pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
no reply is received within <n> seconds.
Default timeout: 30. Use 0 to wait forever.
--bigkeys          Sample Redis keys looking for big keys.
--scan             List all keys using the SCAN command.
--pattern <pat>    Useful with --scan to specify a SCAN pattern.
--intrinsic-latency <sec> Run a test to measure intrinsic system latency.
The test will run for the specified amount of seconds.
--eval <file>      Send an EVAL command using the Lua script at <file>.
--help             Output this help and exit.
--version          Output version and exit.
Examples:
cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:
redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
redis-cli --scan --pattern '*:12345*'
(Note: when using --eval the comma separates KEYS[] from ARGV[] items)
When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands.

 
     
   
  
 
  
  
   
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-315385-1-1.html 上篇帖子: Redis:九、redis使用场景 下篇帖子: Redis学习指南
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表