星空网 > 软件开发 > 数据库

redis的简单安装配置

一、简介

  • Redis是一种高级key-value数据库,数据可以持久化,支持的数据类型很丰富,有字符串,哈希,链表,集合和有序集合5种数据类型

  • Redis支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能,所以Redis也可以被看成是一个数据结构服务器

  • Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(半持久化模式);也可以把每一次数据变化都写入到一个append only file(aof)里面(全持久化模式)

二、Redis安装

安装tclsh

Redis在make test有使用到tclsh对Redis进行测试,所有需要想将tclsh安装好,如果没有安装的话,在make test过程中会出现如下错误:

# wget http://hivelocity.dl.sourceforge.net/project/tcl/Tcl/8.5.14/tcl8.5.14-src.tar.gz# tar xzvf tcl8.5.14-src.tar.gz# cd tcl8.5.14-src/unix   #windows进入tcl8.5.14-src/win# ./configure --prefix=/app/soft/tcl8.5.11 --enable-64bit #enable-64bit对64系统生效# make && make installan 

安装完成之后需要将tclsh添加到PATH中,并使其生效

# vim /etc/profile···PATH=/app/soft/tcl8.5.11/bin:$PATHexport PATH···# source /etc/profile

安装Redis

# cd /usr/loca/src# wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz# tar xzvf redis-2.6.14.tar.gz# cd redis-2.6.14# make# make test  #检查Redis是否已经make成功,这个步骤可以省略,不过建议还是使用# make PREFIX=/usr/local/redis install #默认安装路径:/usr/local

三、配置Redis

Redis.conf

# cat redis.conf|grep -v ^#daemonize yes      #开启守护进程pidfile /var/run/redis.pid  #设置PID文件port 6579        #设置Redis端口timeout 300tcp-keepalive 0loglevel verbose    #设置日志级别syslog-enabled yes   #开启syslogsyslog-ident redis   #设置Redis在syslog里面的标识符syslog-facility local6 #设置Redis在syslog使用的设备databases 5save 900 1       #Redis硬盘数据保存设置save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdb  #Redis数据保存文件dir ./  #Redis数据保存目录slaveof 183.232.10.64 6579    #开启主从同步,设置Master的IP及端口masterauth Dmx#xYkJ0Z8      #设置主从同步密码slave-serve-stale-data yesslave-read-only yesrepl-disable-tcp-nodelay noslave-priority 100requirepass Dmx#xYkJ0Z8      #设置Redis认证密码maxclients 10000          #设置客户端连接数maxmemory 512M           #设置内容大小appendonly no           #设置是否开启AOF模式appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mblua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes

日志设置

通过Redis日志的配置可以知道,这次设置Redis日志是通过syslog来统一管理的,然后再通过logrotate来进行日志轮循,具体配置如下:

##syslog配置# cat /etc/syslog.conf···# Log anything (except mail) of level info or higher.# Don't log private authentication messages!*.info;mail.none;authpriv.none;cron.none;redis.none  /var/log/messages#redis.none去除Redis的日志输出到message···# Save redis messages also to redis.loglocal6.*                       /var/log/redis.log#设置Redis日志输入到/var/log/redis.log文件···##logrotate配置# cat /etc/logrotate.d/redis/var/log/redis.log {  missingok  weekly  notifempty  rotate 15  size 200M  sharedscripts  postrotate    /usr/bin/killall -HUP syslogd  endscript}

logrotate配置文档的意思为:每周检查一次Redis日志文件,大小超过200M就轮循一次,保存15个轮循日志文件。

内核设置

因为Redis需要使用到内存,所有最好配置一个内核参数,否则有可能会报警,具体如下:

# cat /etc/sysctl.conf···vm.overcommit_memory = 1 #指定内核针对内存分配的策略,其值可以是0,1,2···# 0 → 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。# 1 → 表示内核允许分配所有的物理内存,而不管当前的内存状态如何# 2 → 表示内核允许分配超过所有物理内存和交换空间总和的内存# sysctl -p

四、Redis启动与关闭

启动脚本

#!/bin/sh## redis - this script starts and stops the redis-server daemon## chkconfig:  - 85 15# description: Redis is a persistent key-value database# processname: redis-server# config:   /etc/redis/redis.conf# config:   /etc/sysconfig/redis# pidfile:   /var/run/redis.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ".NETWORKING" = "no" ] && exit 0source /etc/init.d/functionsredis="/usr/local/redis/src/redis-server"prog=$(basename $redis)REDIS_CONF_FILE="/usr/local/redis/redis.conf"PIDFILE="/var/run/redis.pid"[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redislockfile=/var/lock/subsys/redisstart() {    if [ -e $PIDFILE ];then       echo "$desc already running...."       exit 1    fi    echo -n $"Starting $prog: "    daemon $redis $REDIS_CONF_FILE    RETVAL=$?    echo    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog    return $RETVAL}stop() {  echo -n $"Stopping $prog: "  killproc $prog -QUIT  retval=$?  echo  [ $retval -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE  return $retval}restart() {  stop  start}reload() {  echo -n $"Reloading $prog: "  killproc $redis -HUP  RETVAL=$?  echo}force_reload() {  restart}rh_status() {  status $prog}rh_status_q() {  rh_status >/dev/null 2>&1}case "$1" in  start)    rh_status_q && exit 0    $1    ;;  stop)    rh_status_q || exit 0    $1    ;;  restart|configtest)    $1    ;;  reload)    rh_status_q || exit 7    $1    ;;  force-reload)    force_reload    ;;  status)    rh_status    ;;  condrestart|try-restart)    rh_status_q || exit 0    ;;  *)    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"    exit 2esac

五、Redis服务验证

./redis-cli 登录,然后再通过ping、info、命令查看redis情况,具体示例如下:

# ./redis-cli -h localhost -p 6579 -a passwordredis localhost:6579> info

 






原标题:redis的简单安装配置

关键词:Redis

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

GS SHOP:https://www.goluckyvip.com/tag/21068.html
GSPAY:https://www.goluckyvip.com/tag/21069.html
PPC策略:https://www.goluckyvip.com/tag/2107.html
GST 消费税 :https://www.goluckyvip.com/tag/21070.html
GSTIN:https://www.goluckyvip.com/tag/21071.html
GSupremacy:https://www.goluckyvip.com/tag/21072.html
三亚有哪些酒店值得入住?:https://www.vstour.cn/a/366173.html
零售晚报:丽人丽妆2023年扭亏为盈 玉容初、美壹堂等自有品牌增速超40% :https://www.kjdsnews.com/a/1836649.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流