Redhat5.8 环境下编译安装 Redis 并将其注册为系统服务
系统环境:
$ cat /etc/issue
Red Hat Enterprise Linux Server release 5.8 (Tikanga)
Kernel \r on an \m
1. 下载安装
1.1 下载
官方下载地址:http://redis.io/download
下载最新稳定版 redis-3.0.4.tar.gz,大小仅 1.3 MB。
1.2 安装
将下载的安装包放在用户目录下,如 /home/webapp,打算将其安装到 /opt/redis:
$ sudo mkdir /opt/redis
$ cd /home/webapp
$ tar xzf redis-3.0.4.tar.gz
$ cd redis-3.0.4
$ sudo make PREFIX=/opt/redis install
之后查看 /opt/redis,下边只生成了一个目录,该目录下只有六个文件:
redis-benchmark redis-check-dump redis-sentinel
redis-check-aof redis-cli redis-server
安装完成。
2. 注册为系统服务
2.1 编辑服务脚本
查看安装包自带服务脚本:
$ cat /home/webapp/redis-3.0.4/utils/redis_init_script
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/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
将其拷贝到 /etc/rc.d/init.d 目录并重命名为 redis:
$ sudo cp /home/webapp/redis-3.0.4/utils/redis_init_script /etc/rc.d/init.d/redis
然后依据 redis 的安装路径修改 /etc/rc.d/init.d/redis 为:
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/opt/redis/bin/redis-server
CLIEXEC=/opt/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/opt/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、description 两行注释必须,缺一不可,否则 service redis does not support chkconfig;
- $EXEC $CONF &,后边的 &,表示将服务转到后台运行;
- EXEC、CLIEXEC、CONF 等三处路径都要改。
2.2 复制配置文件
将 /home/webapp/redis-3.0.4 下提供的 redis.conf 默认配置文件拷贝到 redis 安装根目录下并重命名为 6379.conf:
$ cp /home/webapp/redis-3.0.4/redis.conf /opt/redis/6379.conf
2.3 环境变量设置
追加以下内容到 /etc/profile 文件:
/opt/redis/bin:/sbin:$PATH
执行 . /etc/profile 以使配置立即生效并使用 echo $PATH 验证之。
2.4 服务注册
$ chkconfig --add redis
No news is good news,没有任何输出证明服务注册成功。
如果提示 chkconfig command not found,首先 rpm -q chkconfig 检查是否安装了 chkconfig,已安装的话检查 PATH 里是否有 /sbin。
3. 服务启动及验证
$ sudo service redis start
服务启动,执行
$ redis-cli ping
PONG
表明服务已启动。
参考资料
本文转自:http://blog.csdn.net/defonds/article/details/48525663
Redhat5.8 环境下编译安装 Redis 并将其注册为系统服务的更多相关文章
- libCURL开源库在VS2010环境下编译安装,配置详解
libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 http://blog.csdn.net/su ...
- Redhat环境下编译安装Google Bazel
Redhat环境下编译安装bazel 作者:Jack47 目前Google Bazel没有提供各个操作系统下的二进制安装包,只提供源代码,需要我们自己编译安装,详情可以见我翻译的中文版Google B ...
- centos7.6环境下编译安装tengine-2.2.2的编译安装
centos7.6环境下编译安装tengine-2.2.2的编译安装 .获取tengine2..2的源码包 http://tengine.taobao.org/download/tengine-2.2 ...
- Ubuntu16.04LTS 环境下编译安装Xen
一.编译安装xen4.6过程 操作系统使用ubuntu16.04,通过下载xen4.6的源代码并编译安装来创建xen4.6环境. 一.依赖包的安装 sudo apt-get install gcc m ...
- Linux Centos下编译安装Redis
需要安装 tcl 8.5 wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz //直接下载 sudo tar xzvf tcl8 ...
- windows环境下wamp安装redis拓展
环境: wamp集成环境 安装分为两部 1.安装redis客户端 https://github.com/ServiceStack/redis-windows/raw/master/download ...
- 超详细 Linux 下编译安装Redis 以及php配套使用
一.Linux 下安装Redis 下载地址:http://redis.io/download,下载最新文档版本. 把鼠标移到上图的绿色框上,就会显示下图提示:(直接右键复制链接就好) 本教程使用的旧版 ...
- Ubuntu1604环境下编译安装mariadb10.2.26
环境准备:阿里云ecs Ubuntu1604下,编译安装mariadb10-2.26 1.先安装一些初试环境所需要的工具软件包 apt install -y iproute2 ntpdate tcpd ...
- wamp环境下如何安装redis扩展
Redis安装 wamp环境安装redis扩展 首先在自己本地项目中phpinfo(); 查看php版本; (php版本是5.5, ts-vcll表示MSVC11 (Visual C++ 2012), ...
随机推荐
- 6-03使用SQL语句一次型向表中插入多行数据
通过将现有表中的数据添加到已存在的表中: INSERT INTO <表名><列名> SELECT<列名> FROM<源表名> 将UserInfo的数据添 ...
- Android在listview添加checkbox实现单选多选操作问题(转)
转自:http://yangshen998.iteye.com/blog/1310183 在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上 ...
- 背景虚化 Google Camera App Nokia Refocus HTC One M8 的 Duo景深相机
背景虚化是单反中一种比较常见的拍照形式,参看 http://www.techbang.com/posts/%2017842 https://refocus.nokia.com/
- iOS 钥匙串 指纹识别 get和Post请求的区别
01-钥匙串 1. 通过系统提供的钥匙串功能可以在本地保存密码,系统使用AES的方式对密码加密 a. 查看Safari中保存的密码 2. 使用第三方框架SSKeychain把密码保存到钥匙串和获取钥匙 ...
- Java学习笔记(一)——HelloWorld
一.安装JDK 1.下载链接: http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.直接安装,不能有中文路径 3. ...
- 记一次小团队Git实践(上)
公司规模不大,成立之初,选择了svn作为版本控制系统.这对于用惯了git的我来说,将就了一段时间后,极为不爽,切换到git-svn勉强能用.随后,因为产品需要发布不同的版本,而git-svn对远程分支 ...
- Android学习系列(42)--Android Studio实战技巧
使用android studio开发项目的一些问题,功能和技巧. 1. 环境 Mac OSX 10.9.5 + Android Studio 0.8.9 2. gradle项目加载超慢 这是因为gra ...
- js运动框架tween
<!DOCTYPE html> <html> <head> <title>myAnimate</title> <style> * ...
- poj 2774 Long Long Message 后缀数组基础题
Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 24756 Accepted: 10130 Case Time Limi ...
- http://m.blog.csdn.net/article/details?id=8237698
http://m.blog.csdn.net/article/details?id=8237698