Error[8]: Undefined offset: 234, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

Redis的编译安装

介绍

       redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)list(链表)set(集合)zset(sorted set --有序集合)hash(哈希类型)。这些数据类型都支持push/popadd/remove及取交集并集和差集及更丰富的 *** 作,而且这些 *** 作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改 *** 作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。

编译安装 下载redis
############目前最新稳定版##########
[root@redis ~]# wget http://download.redis.io/releases/redis-2.8.19.tar.gz
解压缩redis
[root@redis ~]# tar xzf redis-2.8.19.tar.gz
编译redis

redis的编译非常简单,已经有现成的Makefile文件,直接运行make命令即可

[root@redis redis-2.8.19]# cd redis-2.8.19
[root@redis redis-2.8.19]# make

make命令执行完成后,会在src目录下生成6个可执行文件,分别是redis-serverredis-cliredis-benchmarkredis-check-aofredis-check-dumpredis-sentinel,它们的作用如下:

redis-server:             Redis服务器的daemon启动程序
redis-cli:                Redis命令行 *** 作工具。当然,你也可以用telnet根据其纯文本协议来 *** 作
redis-benchmark:          Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-check-aof:          更新日志检查
redis-check-dump:         用于本地数据库检查
redis-sentinel:           Redis实例的监控管理、通知和实例失效备援服务,是Redis集群的管理工具
安装redis
[root@redis src]# make install
配置redis的配置文件
[root@redis redis-2.8.19]# cp redis.conf /etc/
##########编辑Redis配置文件###################
[root@redis redis-2.8.19]# vim /etc/redis.conf
    daemonize yes                       #37行    #是否以后台daemon方式运行,默认不是后台运行
    pidfile /var/run/redis/redis.pid    #41行    #redis的PID文件路径
    bind 10.168.85.25                   #64行    #绑定主机IP,默认值为127.0.0.1,我们是跨机器运行,所以需要更改
    logfile /var/log/redis/redis.log    #104行   #定义log文件位置,模式log信息定向到stdout,输出到/dev/null
    save 60 1000                        #145行   #重新定义快照的频率
    dir /usr/local/rdbfile              #188行   #本地数据库存放路径,默认为./,编译安装默认存在在/usr/local/bin下
启动测试Redis服务器
#############启动Redis服务器############
[root@redis redis-2.8.19]# redis-server /etc/redis.conf
#############查看是否启动成功###########
[root@redis redis-2.8.19]# ss -tanlp | grep redis
LISTEN     0      128            10.168.85.25:6379                     *:*      users:(("redis-server",17379,4))
#############测试Redis##################
[root@redis redis-2.8.19]# redis-cli -h 10.168.85.25 -p 6379
10.168.85.25:6379> set test hello
OK
10.168.85.25:6379> get test
"hello"
更改内核信息
#############查看日志信息###############
[root@redis redis-2.8.19]# tail -f /var/log/redis/redis.log
[5033] 04 Jan 15:47:05.378 # Server started, Redis version 2.8.19
[5033] 04 Jan 15:47:05.379 # 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.
[5033] 04 Jan 15:47:05.379 # 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.
[5033] 04 Jan 15:47:05.380 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[5033] 04 Jan 15:47:05.380 * DB loaded from disk: 0.000 seconds
[5033] 04 Jan 15:47:05.380 * The server is now ready to accept connections on port 6379
日志显示有两个关于内核设置的警告信息!
##############sysctl文件###############
[root@redis ~]# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
[root@redis ~]# sysctl -p
#############kerbel####################
[root@redis ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
 
重新启动Redis服务器
#######将缓存保存到硬盘上#####
[root@redis ~]# redis-cli -h 10.168.85.25 -p 6379 BGSAVE
Background saving started
#######关闭Redis#############
[root@redis ~]# redis-cli -h 10.168.85.25 -p 6379 SHUTDOWN
########启动Redis############
[root@redis ~]# redis-server /etc/redis.conf
编辑Redis启动脚本
[root@redis ~]# vi /etc/init.d/redis
#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:   - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
. /etc/rc.d/init.d/functions
name="redis-server"
exec="/usr/local/bin/$name"                                   # 指定redis-server命令的位置(whereis redis-server)
pidfile="/var/run/redis/redis.pid"                            # 指定redis的pid文件路径(和配置文件里保持一致)
REDIS_CONFIG="/etc/redis.conf"                                # 指定redis的配置文件路径
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
    [ -f $REDIS_CONFIG ] || exit 6
    [ -x $exec ] || exit 5
    echo -n $"Starting $name: "
    daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $name: "
    killproc -p $pidfile $name
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    stop
    start
}
reload() {
    false
}
rh_status() {
    status -p $pidfile $name
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "" in
    start)
        rh_status_q && exit 0
        
        ;;
    stop)
        rh_status_q || exit 0
        
        ;;
    restart)
        
        ;;
    reload)
        rh_status_q || exit 7
        
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: 
        exit 2
 {start|stop|status|restart|condrestart|try-restart}"
esac
exit $?
[root@redis ~]# chmod 700 /etc/init.d/redis
[root@redis ~]# servcie redis restart
附加信息 Redis 无法编译安装报错处理?
###########make时错误信息#########
[root@redis redis-2.8.19]# make
cd src && make all
make[1]: Entering directory `/root/redis-2.8.19/src'
    CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-2.8.19/src'
make: *** [all] Error 2
############解决方法#############
make MALLOC=libc
vm.overcommit_memory 参数解析overcommit_memory

如果内存情况比较紧张的话,需要设定内核参数0,指定内核针对内存分配的策略,其值可以是12       0
,表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。       1
,表示内核允许分配所有的物理内存,而不管当前的内存状态如何。       2
,表示内核允许分配超过所有物理内存和交换空间总和的内存Redis
dumpfork数据的时候,会child出一个子进程,理论上parent进程所占用的内存和parent是一样的,比如 8G占用的内存为8G,这个时候也要同样分配child, 的内存给redis如果内存无法负担,往往会造成down服务器IO机或者 1(负载过高,效率下降。所以这里比较优化的内存分配策略应该设置为)表示内核允许分配所有的物理内存,而不管当前的内存状态如何root
设置方式有两种,需确定当前用户的权限活使用     1用户修改:
 echo 1 > /proc/sys/vm/overcommit_memory(:重设文件0)默认为     2
 echo "vm.overcommit_memory=1" >> /etc/sysctl.conf  && sysctl -p 

[+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
编译安装是什么意思_服务器_内存溢出

编译安装是什么意思

编译安装是什么意思,第1张

Redis的编译安装

介绍

       redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)list(链表)set(集合)zset(sorted set --有序集合)hash(哈希类型)。这些数据类型都支持push/popadd/remove及取交集并集和差集及更丰富的 *** 作,而且这些 *** 作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改 *** 作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。

编译安装 下载redis
############目前最新稳定版##########
[root@redis ~]# wget http://download.redis.io/releases/redis-2.8.19.tar.gz
解压缩redis
[root@redis ~]# tar xzf redis-2.8.19.tar.gz
编译redis

redis的编译非常简单,已经有现成的Makefile文件,直接运行make命令即可

[root@redis redis-2.8.19]# cd redis-2.8.19
[root@redis redis-2.8.19]# make

make命令执行完成后,会在src目录下生成6个可执行文件,分别是redis-serverredis-cliredis-benchmarkredis-check-aofredis-check-dumpredis-sentinel,它们的作用如下:

redis-server:             Redis服务器的daemon启动程序
redis-cli:                Redis命令行 *** 作工具。当然,你也可以用telnet根据其纯文本协议来 *** 作
redis-benchmark:          Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-check-aof:          更新日志检查
redis-check-dump:         用于本地数据库检查
redis-sentinel:           Redis实例的监控管理、通知和实例失效备援服务,是Redis集群的管理工具
安装redis
[root@redis src]# make install
配置redis的配置文件
[root@redis redis-2.8.19]# cp redis.conf /etc/
##########编辑Redis配置文件###################
[root@redis redis-2.8.19]# vim /etc/redis.conf
    daemonize yes                       #37行    #是否以后台daemon方式运行,默认不是后台运行
    pidfile /var/run/redis/redis.pid    #41行    #redis的PID文件路径
    bind 10.168.85.25                   #64行    #绑定主机IP,默认值为127.0.0.1,我们是跨机器运行,所以需要更改
    logfile /var/log/redis/redis.log    #104行   #定义log文件位置,模式log信息定向到stdout,输出到/dev/null
    save 60 1000                        #145行   #重新定义快照的频率
    dir /usr/local/rdbfile              #188行   #本地数据库存放路径,默认为./,编译安装默认存在在/usr/local/bin下
启动测试Redis服务器
#############启动Redis服务器############
[root@redis redis-2.8.19]# redis-server /etc/redis.conf
#############查看是否启动成功###########
[root@redis redis-2.8.19]# ss -tanlp | grep redis
LISTEN     0      128            10.168.85.25:6379                     *:*      users:(("redis-server",17379,4))
#############测试Redis##################
[root@redis redis-2.8.19]# redis-cli -h 10.168.85.25 -p 6379
10.168.85.25:6379> set test hello
OK
10.168.85.25:6379> get test
"hello"
更改内核信息
#############查看日志信息###############
[root@redis redis-2.8.19]# tail -f /var/log/redis/redis.log
[5033] 04 Jan 15:47:05.378 # Server started, Redis version 2.8.19
[5033] 04 Jan 15:47:05.379 # 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.
[5033] 04 Jan 15:47:05.379 # 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.
[5033] 04 Jan 15:47:05.380 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[5033] 04 Jan 15:47:05.380 * DB loaded from disk: 0.000 seconds
[5033] 04 Jan 15:47:05.380 * The server is now ready to accept connections on port 6379
日志显示有两个关于内核设置的警告信息!
##############sysctl文件###############
[root@redis ~]# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
[root@redis ~]# sysctl -p
#############kerbel####################
[root@redis ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
 
重新启动Redis服务器
#######将缓存保存到硬盘上#####
[root@redis ~]# redis-cli -h 10.168.85.25 -p 6379 BGSAVE
Background saving started
#######关闭Redis#############
[root@redis ~]# redis-cli -h 10.168.85.25 -p 6379 SHUTDOWN
########启动Redis############
[root@redis ~]# redis-server /etc/redis.conf
编辑Redis启动脚本
[root@redis ~]# vi /etc/init.d/redis
#!/bin/sh
#
# redis        init file for starting up the redis daemon
#
# chkconfig:   - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
. /etc/rc.d/init.d/functions
name="redis-server"
exec="/usr/local/bin/$name"                                   # 指定redis-server命令的位置(whereis redis-server)
pidfile="/var/run/redis/redis.pid"                            # 指定redis的pid文件路径(和配置文件里保持一致)
REDIS_CONFIG="/etc/redis.conf"                                # 指定redis的配置文件路径
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
    [ -f $REDIS_CONFIG ] || exit 6
    [ -x $exec ] || exit 5
    echo -n $"Starting $name: "
    daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $name: "
    killproc -p $pidfile $name
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    stop
    start
}
reload() {
    false
}
rh_status() {
    status -p $pidfile $name
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "" in
    start)
        rh_status_q && exit 0
        
        ;;
    stop)
        rh_status_q || exit 0
        
        ;;
    restart)
        
        ;;
    reload)
        rh_status_q || exit 7
        
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: 
        exit 2
 {start|stop|status|restart|condrestart|try-restart}"
esac
exit $?
[root@redis ~]# chmod 700 /etc/init.d/redis
[root@redis ~]# servcie redis restart
附加信息 Redis 无法编译安装报错处理?
###########make时错误信息#########
[root@redis redis-2.8.19]# make
cd src && make all
make[1]: Entering directory `/root/redis-2.8.19/src'
    CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-2.8.19/src'
make: *** [all] Error 2
############解决方法#############
make MALLOC=libc
vm.overcommit_memory 参数解析overcommit_memory

如果内存情况比较紧张的话,需要设定内核参数0,指定内核针对内存分配的策略,其值可以是12       0
,表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。       1
,表示内核允许分配所有的物理内存,而不管当前的内存状态如何。       2
,表示内核允许分配超过所有物理内存和交换空间总和的内存Redis
dumpfork数据的时候,会child出一个子进程,理论上parent进程所占用的内存和parent是一样的,比如 8G占用的内存为8G,这个时候也要同样分配child, 的内存给redis如果内存无法负担,往往会造成down服务器IO机或者 1(负载过高,效率下降。所以这里比较优化的内存分配策略应该设置为)表示内核允许分配所有的物理内存,而不管当前的内存状态如何root
设置方式有两种,需确定当前用户的权限活使用     1用户修改:
 echo 1 > /proc/sys/vm/overcommit_memory(:重设文件0)默认为     2
 echo "vm.overcommit_memory=1" >> /etc/sysctl.conf  && sysctl -p 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/783849.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-04
下一篇 2022-05-04

发表评论

登录后才能评论

评论列表(0条)

保存