centos安装redis

本文介绍如何从源码安装Redis,并详细配置其服务启动脚本及配置文件,包括设置日志级别、位置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文:http://www.verydemo.com/demo_c170_i11857.html

# wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz
# tar xf tcl8.6.0-src.tar.gz 
# cd tcl8.6.0/unix/
./configure --prefix=/usr \
            --mandir=/usr/share/man \
            --without-tzdata \
            $([ $(uname -m) = x86_64 ] && echo --enable-64bit) &&
make &&
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
    -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \
    -i tclConfig.sh
make install &&
make install-private-headers &&
ln -v -sf tclsh8.6 /usr/bin/tclsh &&
chmod -v 755 /usr/lib/libtcl8.6.so


# tar xf redis-2.6.13.tar.gz 
# cd redis-2.6.13
# make
# make test
# make install
# cp redis.conf /etc/
# vi /etc/sysctl.conf //如果已经配置过这里了,可以忽略,如果没有,一定要配置
vm.overcommit_memory = 1
# 然后执行sysctl -p
# redis-server /etc/redis.conf //启动服务
# netstat -nutlp | grep 6379 | grep -v grep //看到以下表示redis启动成功
6379          0.0.0.0:*               LISTEN      14845/xinetd


vi /etc/init.d/redis
#!/bin/bash 
# Init file for redis 
# chkconfig: - 80 12 
# description: redis daemon 
# processname: redis 
# TITLE END
# Source function library.
. /etc/rc.d/init.d/functions
BIN="/usr/local/bin" 
CONFIG="/etc/redis.conf" 
PIDFILE="/var/run/redis.pid" 
prog="redis-server" 
desc="Redis Server" 
start() { 
        if [ -e $PIDFILE ];then 
             echo "$desc already running...." 
             exit 1 
        fi 
        echo -n $"Starting $desc: " 
        daemon $BIN/$prog $CONFIG 
        RETVAL=$? 
        echo 
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
        return $RETVAL 
} 
stop() { 
        echo -n $"Stop $desc: " 
        killproc $prog 
        RETVAL=$? 
        echo 
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE 
        return $RETVAL 
} 
restart() { 
        stop 
        start 
} 
case "$1" in 
  start) 
        start 
        ;; 
  stop) 
        stop 
        ;; 
  restart) 
        restart 
        ;; 
  status) 
        status $prog 
        RETVAL=$? 
        ;; 
   *) 
        echo $"Usage: $0 {start|stop|restart|condrestart|status}" 
        RETVAL=1 
esac 
exit $RETVAL


# chmod 755 /etc/init.d/redis
# chkconfig --add redis
# chkconfig --level 345 redis on
# chkconfig --list redis


# vi /etc/redis.conf
#daemonize no   //默认为no,注释掉,新增一行改为yes
daemonize yes
# Set server verbosity to 'debug'
# it can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice   //这里定义日志的级别,默认为notice
#logfile stdout    //这里指定Redis的日志文件位置
logfile /var/log/redis.log


/etc/init.d/redis restart
[root@node3 ~]# cat /var/log/redis.log 
[3779] 07 Apr 12:23:42.340 * Max number of open files set to 10032
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.6.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
(    '      ,       .-`  | `,    )     Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 3779
  `-._    `-._  `-./  _.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
[3779] 07 Apr 12:23:42.344 # Server started, Redis version 2.6.2
[3779] 07 Apr 12:23:42.344 * The server is now ready to accept connections on port 6379
# netstat -lantp |grep 6379
tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      2973/redis-server



[root@10-6-8-200 ~]# redis-cli info
# Server
redis_version:2.6.13
redis_git_sha1:00000000
redis_git_dirty:0
redis_mode:standalone
os:Linux 2.6.32-279.22.1.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.6
process_id:2973
run_id:445c2e3b484b51a9de590d05b320d8358d576bdd
tcp_port:6379
uptime_in_seconds:1523
uptime_in_days:0
hz:10
lru_clock:1238587
# Clients
connected_clients:30
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:1936944
used_memory_human:1.85M
used_memory_rss:8880128
used_memory_peak:12389416
used_memory_peak_human:11.82M
used_memory_lua:31744
mem_fragmentation_ratio:4.58
mem_allocator:jemalloc-3.2.0
# Persistence
loading:0
rdb_changes_since_last_save:10
rdb_bgsave_in_progress:0
rdb_last_save_time:1375534593
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
# Stats
total_connections_received:3529
total_commands_processed:11949
instantaneous_ops_per_sec:0
rejected_connections:0
expired_keys:0
evicted_keys:0
keyspace_hits:1257
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:1007
# Replication
role:master
connected_slaves:0
# CPU
used_cpu_sys:1.11
used_cpu_user:0.73
used_cpu_sys_children:0.01
used_cpu_user_children:0.01
# Keyspace
db0:keys=3,expires=0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值