Redis入门

一、安装

目前,官方最新稳定版本为3.0.7

# wget http://download.redis.io/releases/redis-3.0.7.tar.gz

# cd /usr/local/

# tar xvf /root/redis-3.0.7.tar.gz

# cd redis-3.0.7/

# make

 

二、启动

安装完成后,在src目录下会生成启动执行程序,包括redis-server,redis-sentinel, redis-benchmark,redis-cli等

# src/redis-server 

该启动方式是前台启动,如果关闭当前终端,则redis会自动关闭

正如登录信息开头Warning所显示的,这种方式启动没有使用配置文件,所以并不推荐。默认监听6379端口

24649:C 03 Feb 16:32:30.242 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
24649:M 03 Feb 16:32:30.243 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 24649
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

24649:M 03 Feb 16:32:30.246 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
24649:M 03 Feb 16:32:30.246 # Server started, Redis version 3.0.7
24649:M 03 Feb 16:32:30.246 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
24649:M 03 Feb 16:32:30.246 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
24649:M 03 Feb 16:32:30.247 * The server is now ready to accept connections on port 6379

 

关于redis-server的更多用法,可通过redis-server -h查看

# src/redis-server -h

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

 

配置文件中常用参数如下:

daemonize:是否以后台daemon方式运行,默认是前台方式运行,即默认值为no

pidfile:pid文件位置,默认为:/run/redis.pid

port:监听的端口号,默认为6379

bind 127.0.0.1 配置监听网卡的ip,针对有多个网卡的场景

logfile:log文件位置,默认值为stdout,使用“标准输出”,默认后台模式会输出到/dev/null

loglevel notice ,指定日志记录级别,Redis总共支持四个级别:debug,verbose,notice,warning,默认为notice

     Debug:记录很多信息,用于开发和测试

     Verbose:很多精简的有用信息,不像debug会记录那么多

     Notice:普通的verbose,常用于生产环境

     Warning:只有非常重要或者严重的信息会记录到日志

 

三、设置开机自启动

 将启动脚本复制到/etc/init.d目录下

# cp /usr/local/redis-3.0.7/utils/redis_init_script /etc/init.d/redisd

编辑启动脚本

# vim /etc/init.d/redisd

#!/bin/sh
# chkconfig:2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis-3.0.7/src/redis-server
#EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/redis-3.0.7/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

 

主要做了两项修改,

一、添加了# chkconfig:2345 90 10

二、指定了redis-server和redis-cli的位置

EXEC=/usr/local/redis-3.0.7/src/redis-server

CLIEXEC=/usr/local/redis-3.0.7/src/redis-cli

注意:

PIDFILE=/var/run/redis_${REDISPORT}.pid指定了pid文件的位置

CONF="/etc/redis/${REDISPORT}.conf"指定了配置文件的位置

 

创建配置文件

# cd /etc/

# mkdir redis

# cp /usr/local/redis-3.0.7/redis.conf redis/6379.conf

 

修改配置文件

主要是设置redis以后台进程运行和pid文件的位置

daemonize yes
pidfile /var/run/redis_6379.pid

 

以服务方式启动redis

# /etc/init.d/redisd start

Starting Redis server...

# ps -ef |grep redis

root      29836      1  0 18:23 ?        00:00:00 /usr/local/redis-3.0.7/src/redis-server *:6379
root      29846   4110  0 18:23 pts/0    00:00:00 grep --color=auto redis

 

客户端连接测试

# cd /usr/local/redis-3.0.7/src/

# ./redis-cli 

127.0.0.1:6379> set 123 hello
OK
127.0.0.1:6379> get 123
"hello"

默认连接到localhost 6379,查看服务器信息,可通过info命令。

 

内容概要:本文介绍了一个基于多传感器融合的定位系统设计方案,采用GPS、里程计和电子罗盘作为定位传感器,利用扩展卡尔曼滤波(EKF)算法对多源传感器数据进行融合处理,最终输出目标的滤波后位置信息,并提供了完整的Matlab代码实现。该方法有效提升了定位精度与稳定性,尤其适用于存在单一传感器误差或信号丢失的复杂环境,如自动驾驶、移动采用GPS、里程计和电子罗盘作为定位传感器,EKF作为多传感器的融合算法,最终输出目标的滤波位置(Matlab代码实现)机器人导航等领域。文中详细阐述了各传感器的数据建模方式、状态转移与观测方程构建,以及EKF算法的具体实现步骤,具有较强的工程实践价值。; 适合人群:具备一定Matlab编程基础,熟悉传感器原理和滤波算法的高校研究生、科研人员及从事自动驾驶、机器人导航等相关领域的工程技术人员。; 使用场景及目标:①学习和掌握多传感器融合的基本理论与实现方法;②应用于移动机器人、无人车、无人机等系统的高精度定位与导航开发;③作为EKF算法在实际工程中应用的教学案例或项目参考; 阅读建议:建议读者结合Matlab代码逐行理解算法实现过程,重点关注状态预测与观测更新模块的设计逻辑,可尝试引入真实传感器数据或仿真噪声环境以验证算法鲁棒性,并进一步拓展至UKF、PF等更高级滤波算法的研究与对比。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值