zoukankan      html  css  js  c++  java
  • redis的单实例配置+web链接redis

    [root@cache01 src]# wget http://download.redis.io/redis-stable.tar.gz
    [root@cache01 src]# tar -xzvf redis-stable.tar.gz 
    [root@cache01 redis-stable]# pwd
    /usr/local/src/redis-stable
    [root@cache01 redis-stable]# ls
    00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
    BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
    CONTRIBUTING     INSTALL  README.md  runtest-cluster  src
    

     安装redis依赖包

    [root@cache01 redis-stable]# yum install -y gcc tcl
    

     编译并安装redis

    [root@cache01 redis-stable]# make
    [root@cache01 redis-stable]# make test
    [root@cache01 redis-stable]# make install PREFIX=/app/server/redis-3.2.1
    [root@cache01 redis-stable]# make test
    [root@cache01 redis-stable]# ln -s /app/server/redis-3.2.1/ /app/server/redis
    

     配置环境变量并生效:

    [root@cache01 bin]# echo "PATH=/app/server/redis/bin:$PATH" >>/etc/profile
    
    [root@cache01 bin]# . /etc/profile
    [root@cache01 bin]#mkdir /app/server/redis/conf
    

     创建redis配置文件目录,拷贝相关配置文件

    [root@cache01 bin]# cp /usr/local/src/redis-stable/redis.conf /app/server/redis/conf/6379.conf
    

     修改配置文件中相关参数,如下所示:

    [root@cache01 bin]# mkdir /app/server/redis/logs
    [root@cache01 bin]# egrep "(daemonize|pidfile|logfile)" /app/server/redis/conf/6379.conf
    # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    daemonize yes
    # When the server runs non daemonized, no pid file is created if none is
    # specified in the configuration. When the server is daemonized, the pid file
    pidfile /var/run/redis_6379.pid
    # output for logging but daemonize, logs will be sent to /dev/null
    logfile "/app/server/redis/logs/6379.log"
    

     拷贝redis启动脚本到/etc/init.d/目录下,并重命名为redis

    [root@cache01 bin]# cp /usr/local/src/redis-stable/utils/redis_init_script /etc/init.d/redis
    

     修改redis启动脚本,相关参数如下所示:

    [root@cache01 bin]# egrep "^(REDISHOME|EXEC|CLIEXEC|PIDFILE|CONF)" /etc/init.d/redis
    REDISHOME=/app/server/redis
    EXEC=$REDISHOME/bin/redis-server
    CLIEXEC=$REDISHOME/bin/redis-cli
    PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="$REDISHOME/conf/${REDISPORT}.conf"
    

     配置完成,启动redis并查看进程及端口号:

    [root@cache01 bin]# /etc/init.d/redis start
    
    [root@cache01 bin]# ss -lnupt|grep 6379
    tcp    LISTEN     0      128            127.0.0.1:6379                  *:*      users:(("redis-server",10590,4))
    
    
    [root@cache01 bin]# ps -ef|grep redis|grep -v grep
    root     10590     1  0 14:52 ?        00:00:00 /app/server/redis/bin/redis-server 127.0.0.1:6379
    

     执行客户端命令并测试:

    [root@cache01 bin]# redis-cli
    127.0.0.1:6379> set num 100
    OK
    127.0.0.1:6379> get num
    "100"
    127.0.0.1:6379> incr num
    (integer) 101
    127.0.0.1:6379> decr num
    (integer) 100
    127.0.0.1:6379> del num
    (integer) 1
    127.0.0.1:6379> get num
    (nil)
    127.0.0.1:6379> 
    

     关闭redis服务

    [root@cache01 bin]# /etc/init.d/redis stop
    Stopping ...
    Redis stopped
    
    [root@cache01 bin]# ps -ef |grep redis|grep -v "grep"
    [root@cache01 bin]# ss -lnutp|grep 6379
    

     到此redis的单实例配置完成。

    web链接redis测试:192.168.1.112是redis服务器

    <?php
    $redis = new redis();
    $redis->connect('192.168.1.112',6379);
    $result = $redis->set('test',"1234567");
    var_dump($result);
    ?>
    
  • 相关阅读:
    luogu P2827 蚯蚓
    CHOI1001/1002 火车进出栈问题
    hdoj4699 Editor
    反弹shell监控
    AppScan 9.0.3.6 crack
    Spectre & Meltdown Checker – CPU芯片漏洞检查脚本Linux版
    Microsoft IIS WebDav 'ScStoragePathFromUrl' Remote Buffer Overflow (CVE-2017-7269)
    Shodan新手使用指南
    The Art of Subdomain Enumeration (转)
    DDOS攻击方式总结 (转)
  • 原文地址:https://www.cnblogs.com/bass6/p/5640506.html
Copyright © 2011-2022 走看看