我的redis安装的路径是在
/usr/local/redis
mkdir /etc/redis #创建文件夹
cp /usr/local/redis/redis.conf /etc/redis/6379.conf #将redis.conf拷贝到/etc/redis文件夹下
vim /etc/rc.d/init.d/redis #打开编辑器
插入以下内容
#!/bin/sh #chkconfig: 2345 80 90 # 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/src/redis-server CLIEXEC=/usr/local/redis/src/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/etc/redis/${REDISPORT}.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac
chkconfig --add redis #添加服务
service redis start #启动服务
将Redis的命令所在目录添加到系统参数PATH中
修改profile文件: vi /etc/profile
在最后行追加: export PATH="$PATH:/usr/local/redis/src"
然后马上应用这个文件: . /etc/profile
这样就可以直接调用redis-cli的命令了,如下所示:
$ redis-cli
redis 127.0.0.1:6379> auth superman
OK
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379>
时间: 2024-10-15 06:55:46