安装redis(3.2.9)
专注于为中小企业提供成都做网站、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业邛崃免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
1.redis 官网地址:https://redis.io/
2.部署安装redis3.2.9 实验环境:centos 6.5
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
yum install automake autoconf ruby rubygems -y #安装依赖插件
make && make install #这里使用的是默认安装
3.创建相对应的目录
mkdir -p /usr/local/redis/bin/
mkdir /usr/local/redis/ && mkdir -p /data/redis/
4.执行安装脚本进行安装
[root@caosm103 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] 6379
Please select the redis config file name [/etc/redis/redis.conf] /usr/local/redis/redis_6378.conf
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/redis_6378.log
Please select the data directory for this instance [/var/lib/redis/6379] /data/redis/
Please select the redis executable path [/usr/local/bin/redis-server] /usr/local/redis_6379/bin
Selected config:
Port : 6379
Config file : /usr/local/redis/redis.conf
Log file : /usr/local/redis/redis_6379.log
Data dir : /data/redis/
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
5.服务开启状态
[root@caosm103 redis]# redis-server redis.conf
#程序 配置文件配置文件这里bind ip 地址改成了本机的ip地址
6.修改启动脚本
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
# Description: redis-server - Persistent key-value db
### END INIT INFO
### 注意 需要创建 redis 用户 redis.conf redis_6379.pid redis_6379.log /data/redis 所有者要改为redis,并赋予执行权限755
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/redis-server
DAEMON_ARGS=/usr/local/redis/redis.conf
NAME=redis-server
DESC=redis-server
PIDFILE=/var/run/redis_6379.pid
test -x $DAEMON || exit 0
test -x $DAEMONBOOTSTRAP || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
touch $PIDFILE
chown redis:redis $PIDFILE
if start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
then
echo "[OK]"
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry 10 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
then
echo "[OK]"
else
echo "failed"
fi
rm -f $PIDFILE
;;
status)
if [ ! -r $PIDFILE ] ; then
echo "redis-server is stopped"
exit 0
fi
PID=`cat $PIDFILE`
if ps -p $PID | grep -q $PID; then
echo "redis-server (pid $PID) is running..."
else
echo "redis-server dead but pid file exists"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status|force-reload}" >&2
exit 1
;;
esac
exit 0
7.安装start-stop-daemon
[root@caosm103 src]# wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
[root@caosm103 src]# tar zxf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
[root@caosm103 src]# mv apps/sys-utils/start-stop-daemon-IR1_9_18-2/ ./
[root@caosm103 src]# ls
apps apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz nginx-1.8.0 redis-3.2.9 redis-3.2.9.tar.gz start-stop-daemon-IR1_9_18-2
[root@caosm103 src]# rm -rf apps
[root@caosm103 src]# cd start-stop-daemon-IR1_9_18-2/
[root@caosm103 start-stop-daemon-IR1_9_18-2]# cc start-stop-daemon.c -o start-stop-daemon
[root@caosm103 start-stop-daemon-IR1_9_18-2]# cp start-stop-daemon /usr/local/bin/start-stop-daemon
start-stop-demo 参数介绍
root@caosm103 redis]# start-stop-daemon --help
start-stop-daemon 1.9.18 for Debian - small and fast C version written by
Marek Michalkiewicz, public domain.
Usage:
start-stop-daemon -S|--start options ... -- arguments ...
start-stop-daemon -K|--stop options ...
start-stop-daemon -H|--help
start-stop-daemon -V|--version
Options (at least one of --exec|--pidfile|--user is required):
-x|--execprogram to start/check if it is running
-p|--pidfilepid file to check
-c|--chuid
change to this user/group before starting process
-u|--user| stop processes owned by this user
-n|--namestop processes with this name
-s|--signalsignal to send (default TERM)
-a|--startasprogram to start (default is )
-N|--niceleveladd incr to the process's nice level
-b|--background force the process to detach
-m|--make-pidfile create the pidfile before starting
-R|--retrycheck whether processes die, and retry
-t|--test test mode, don't do anything
-o|--oknodo exit status 0 (not 1) if nothing done
-q|--quiet be more quiet
-v|--verbose be more verbose
Retryis - |/
- /... where
- is one of
-|[-] send that signal
wait that many seconds
forever repeat remainder forever
ormay be just , meaning / /KILL/
Exit status: 0 = done 1 = nothing done (=> 0 if --oknodo)
3 = trouble 2 = with --retry, processes wouldn't die
8.启动测试:
[root@caosm103 redis]# /etc/init.d/redis-server stop
Stopping redis-server: [OK]
[root@caosm103 redis]# /etc/init.d/redis-server start
Starting redis-server: [OK]
[root@caosm103 redis]#
[root@caosm103 redis]# /etc/init.d/redis-server restart
Stopping redis-server: [OK]
Starting redis-server: [OK]
现在都能够正常进行运行!
9.redis工具介绍
redis-benchmark 性能测试工具
redis-check-aof 日志文件检测工(比如断电造成日志损坏,可以检测并修复)
redis-check-dump 快照文件检测工具,效果类上
redis-cli 客户端
redis-server 服务端