Centos7 Configuring Redis, Php-redis

Source: Internet
Author: User
Tags truncated

First, installation + configuration:
  1. Installation:
    yum  -y  install  redis  php-redis
  2. Configuration:
    Vim/etc/redis.conf
    # Allow all hosts to access bind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised Nopidfile/var/run/redis_6379.pidloglevel noticelogfile/var/log/redis/redis.logdatabases 16save 1save 10save 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir/var/lib/ Redisslave-serve-stale-data yesslave-read-only Yesrepl-diskless-sync Norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100# set access password Requirepass 123456# maximum number of accesses MaxClients 100000appendonly Noappendfilename "appendonly.aof" Appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated Yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" Hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64HLL-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit Normal 0 0 0client-output-buffer-limit slave 256MB 64MB 60client-output-buffer-limit pubsub 32mb 8MB 60hz 10aof-rewrite-incremental-fsync Yes
    Second, master-slave replication:
  3. Primary server configuration (192.168.8.81):
    Vim/etc/redis.conf
    # Allow all hosts to access bind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised Nopidfile/var/run/redis_6379.pidloglevel noticelogfile/var/log/redis/redis.logdatabases 16save 1save 10save 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir/var/lib/ Redisslave-serve-stale-data yesslave-read-only Yesrepl-diskless-sync Norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100# set access password Requirepass 123456# maximum number of accesses MaxClients 100000appendonly Noappendfilename "appendonly.aof" Appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated Yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" Hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64HLL-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit Normal 0 0 0client-output-buffer-limit slave 256MB 64MB 60client-output-buffer-limit pubsub 32mb 8MB 60hz 10aof-rewrite-incremental-fsync Yes
  4. From server Configuration (192.168.8.82):
    # Allow all hosts to access bind 0.0.0.0protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize nosupervised Nopidfile/var/run/redis_6379.pidloglevel noticelogfile/var/log/redis/redis.logdatabases 16save 1save 10save 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir/var/lib/redis# Set to slaveof 192.168.8.81 6379# master server password Masterauth 123456slave-serve-stale-data yesslave-read-only from server Yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100# set access password Requirepass 123456# Maximum number of accesses maxclients 100000appendonly noappendfilename "appendonly.aof" Appendfsync Everysecno-appendfsync-on-rewrite Noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated Yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" Hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing Yesclient-output-buffer-limit Normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit PubSub 32MB 8MB 60hz 10aof-rewrite-incremental-fsync Yes
  5. Test:
    A. Main (192.168.8.81):
    Redis-cli-a 123456
    set  name  dollarphp


    B. From (192.168.8.82):
    Redis-cli-a 123456

    get  name

    Three, load Balancing (twemproxy):

  6. Usage scenarios:
    适用于多个从redis从服务器之间的读操作
  7. System Architecture:
    角色                        ip地址主redis+负载均衡   192.168.8.81从redis                    192.168.8.82从redis                    192.168.8.83
  8. Download:
    yum  -y  groupinstall  "development  tools"git  clone  https://github.com/dollarphper/twemproxy.gitcd  twemproxy
  9. Extract:
    tar  -xzf  nutcracker-0.4.1.tar.gz
  10. Installation:
    cd  nutcracker-0.4.1autoreconf  -fvi./configure  --prefix=/usr/local/twemproxymake  -j  8make  install
  11. Set Environment variables:
    echo  "PATH=$PATH:/usr/local/twemproxy/sbin/"  >>  /etc/profile.  /etc/profile
  12. To create a directory:
    mkdir  /usr/local/twemproxy/{run,conf}
  13. To add a configuration file:
    Vim/usr/local/twemproxy/sbin/conf/nutcracker.yml
    alpha:listen: 127.0.0.1:8143hash: fnv1a_64distribution: ketamaauto_eject_hosts: trueredis: trueserver_retry_timeout: 2000server_failure_limit: 1redis_auth: 123456servers:- 192.168.8.82:6379:1- 192.168.8.83:6379:1
  14. Check the configuration file syntax:
    cd  /usr/local/twemproxy/sbin/./nutcracker  -t

  15. Start the service:
    nutcracker  -d  -c  /usr/local/twemproxy/sbin/conf/nutcracker.yml  -p  /usr/local/twemproxy/run/redisproxy.pid  -o  /usr/local/twemproxy/run/redisproxy.log
  16. Stop service:
    kill  -9  `cat  /usr/local/twemproxy/run/redisproxy.pid`
  17. To create a startup service:
    Vim/etc/init.d/twemproxy
    #!/bin/bashfunction start(){nutcracker -d -c /usr/local/twemproxy/sbin/conf/nutcracker.yml -p /usr/local/twemproxy/run/redisproxy.pid -o /usr/local/twemproxy/run/redisproxy.log}function stop(){kill -9 `cat /usr/local/twemproxy/run/redisproxy.pid`}case "$1" instart)    start;;  stop)    stop;;  restart)    stop    start;;*)    echo "Usage : start | stop | restart";;esac
  18. Start the service:
    systemctl  start  twemproxy
  19. Test:
    A. Primary server (192.168.8.81):
    A-1. Window 1:
    redis-cli  -a  123456set  name  dollarphp


    A-2. Window 2:

    redis-cli  -a  123456  -p  8143get  name


    B. From the server (192.168.8.82):

    systemctl  stop  redis

    C. From the server (192.168.8.83):

    systemctl  stop  redis

    D. master server (Windows 2):

    Iv. PHP connection to Redis:
Five, Php+redis implementation queue: Six, Php+redis Implementation subscription/release:

Centos7 configuring Redis, Php-redis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.