分享

Ubuntu16.04 Redis的安装及设置redis开机启动

 天天向上wish 2018-02-01

1、  从http:/// 下载redis-3.2.4.tar.gz

2、 上传到linux后移动到/opt/redis目录下

3、 解压 sudo tar -zxvf redis-3.2.4.tar.gz

4、 进入解压后的文件夹进行编译 make

5、 安装 make install

6、 测试一下 make test

             报错缺少tcl (tcl 是一种解译语言,也是一套 C 的函式库)

                       安装tcl  apt-get install tcl

             报错Executing test client: NOREPLICAS Not enoughgood slaves to write..

                       修改文件tests/integration/replication-2.tcl,将after 1000改为after 10000以延长等待时间。

            报错[err]: Server is able to generate a stack trace on selected systems in tests/integration/logging.
                      只是某个测试没有通过,可以忽略。

7、创建Redis配置目录 /etc/redis
                mkdir /etc/redis
8、拷贝配置文件:
                cp /opt/redis/redis-3.2.4/redis.conf/ /etc/redis
9、编辑配置文件(暂未编辑)
              修改端口、配置数据库保存目录、其它
10、(1)通过指定配置文件启动;
                       redis-server /etc/redis/redis.conf
        (2)通过命令redis-server 启动,可在命令后加上`&`号使redis以后台程序方式运行;
                        redis-server &
11、客户端登陆 redis-cli
12、关闭Redis服务 redis-cli shutdown

 设置redis开机启动

修改redis.conf(/etc/redis下)

          #打开后台运行选项
         daemonize yes
         #设置日志文件路径
         logfile "/var/log/redis/redis.log"

编写脚本

        vim /etc/init.d/redis

  1. #!/bin/sh  
  2. # chkconfig: 2345 10 90  
  3. # description: Start and Stop redis  
  4.   
  5. PATH=/usr/local/bin  
  6. REDISPORT=6379  
  7. EXEC=/usr/local/bin/redis-server  
  8. REDIS_CLI=/usr/local/bin/redis-cli  
  9. PIDFILE=/var/run/redis.pid  
  10. CONF="/etc/redis/redis.conf"  
  11.   
  12. case "$1" in  
  13.     start)  
  14.         if [ -f $PIDFILE ]  
  15.         then  
  16.             echo "$PIDFILE exists, process is already running or crashed."  
  17.         else  
  18.             echo "Starting Redis server..."  
  19.             $EXEC $CONF  
  20.         fi  
  21.         if [ "$?"="0" ]  
  22.         then  
  23.             echo "Redis is running..."  
  24.         fi  
  25.         ;;  
  26.     stop)  
  27.         if [ ! -f $PIDFILE ]  
  28.         then  
  29.             echo "$PIDFILE exists, process is not running."  
  30.         else  
  31.             PID=$(cat $PIDFILE)  
  32.             echo "Stopping..."  
  33.             $REDIS_CLI -p $REDISPORT SHUTDOWN  
  34.             while [ -x $PIDFILE ]  
  35.             do  
  36.                 echo "Waiting for Redis to shutdown..."  
  37.                 sleep 1  
  38.             done  
  39.             echo "Redis stopped"  
  40.         fi  
  41.         ;;  
  42.     restart|force-reload)  
  43.         ${0} stop  
  44.         ${0} start  
  45.         ;;  
  46.     *)  
  47.         echo "Usage: /etc/init.d/redis {start|stop|restart|fore-reload}"  
  48.         exit 1  
  49. esac   

添加脚本的执行权限
        sudo chmod +x /etc/init.d/redis
设置开机自动启动
       sudo update-rc.d redis defaults
       报错:
       

      上面为两个错误
       第一个参考https://my.oschina.net/u/943306/blog/345923
            解决方法:安装一个中文语言,系统就知道zh_CN.UTF-8了,这个时候用perl就不会报错了
                  apt-get install language-pack-zh-hans
      第二个参考:http://bashell./archives/directspace-debian-6-vps-vzquota-missing.html
           解决方法:编辑/etc/init.d/redis
                在文件头部#!/bin/sh下面添加
                ### BEGIN INIT INFO
                # Provides: OSSEC HIDS
                # Required-Start: $network $remote_fs $syslog $time
                # Required-Stop:
                # Default-Start: 2 3 4 5
                # Default-Stop: 0 1 6
                # Short-Description: OSSEC HIDS
                ### END INIT INFO
使用脚本启动服务
          开启redis: service redis start
          停止redis: service redis stop
          重启redis: service redis restart
         查看服务状态:service redis status
最后将机器关机,重新启动
         此时redis服务也启动了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多