Redis Configure user authentication password

Source: Internet
Author: User
Tags min mkdir pings redis socket syslog redis server
1, download and install
    Download, extract and compile Redis with:
    $ wget http://download.redis.io/releases/redis-3.2.8.tar.gz
    $ tar xzf Redis-3.2.8.tar.gz
    $ cd redis-3.2.8
    $ make

PS: Previously in the bin directory, now becomes the SRC directory,

The binaries that is now compiled is available in the SRC directory. Run Redis with: $ src/redis-server
You can interact with Redis using the built-in client:



Make a soft connection and place Redis under the regular directory/usr/local

Ln-s/data/soft/redis-3.2.8/usr/local/redis-3.2.8



Set up data directory, log directory, run directory, configuration file directory

    cd/usr/local/redis-3.2.8
    mkdir  data-p
    mkdir  logs-p
    mkdir  conf-p mkdir  
    run-p


2, configuration file

RZ redis.conf #里面修改ip地址以及各种数据, log, run directory
# Redis configuration file example. # Note This in order to read the configuration file, Redis must is # started with the file path as first argument: # #. /redis-server/path/to/redis.conf # Note on units:when memory size is needed, it's possible to specify # It's in the Usua L form of 1k 5GB 4M and so forth: # # 1k = bytes # 1kb = 1024x768 bytes # 1m = 1000000 bytes # 1MB = 1024  *1024 bytes # 1g = 1000000000 bytes # 1gb = 1024*1024*1024 Bytes # # units is case insensitive so 1GB 1Gb 1gB is

All the same.  ################################## includes ################################### # Include one or more other config files  Here. This was useful if you # has a standard template, goes to all Redis servers but also need # to customize a few Per-ser  ver settings.
Include files can include # Other files, so use this wisely. # # Notice option "include" won ' t be rewritten by command "CONFIG REWRITE" # from admin or Redis Sentinel. Since Redis always uses the last processed # line as value of a configuration directive, you ' d better put includes # on the beginning of this file T
o Avoid overwriting config change at runtime. # If instead interested in using includes to override configuration # options, it's better to use include as th
e last line. # # # include/path/to/local.conf # include/path/to/other.conf ################################## NETWORK ############## ####################### # By default, if no "bind" configuration directive are specified, Redis listens # for connections
From all the network interfaces available on the server. # It is possible to listen to just one or multiple selected interfaces using # the "bind" configuration directive, Followe
D by one or more IP addresses. # # # # Examples: # # Bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1:: 1 # ~ ~ ~ ~ WARNING ~ ~ ~ If the computer running Redis is di Rectly exposed to the # Internet, binding to all the interfaces is dangerous and would expose the # instance to everybody O N The internet. So by default we uncomment the # following BIND directive, that would force Redis to listen only into # the IPV4 lookback i Nterface address (This means Redis would be able to # accept connections only from clients running into the same computer I
t # is running).
# # IF You is sure you want YOUR INSTANCE to LISTEN to all the INTERFACES # JUST COMMENT the following line. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 10.247.7.11 127.0.0.1 # Protected Mode is a layer of security protection, in order to avoid that # Redis instances left open on the internet was accessed an
D exploited. # when protected mode was on and if: # # 1) The server was not binding explicitly to a set of addresses using the # "BI
nd "directive.
# 2) No password is configured. # # The server only accepts connections from clients connecting from the # IPV4 and IPV6 loopback addresses 127.0.0.1 and
:: 1, and from Unix domain # sockets. # By default protected mode is ENABled. You should disable it only if # is sure you want clients from the other hosts to the connect to Redis # even if no Authentica
tion is configured, nor a specific set of interfaces # are explicitly listed using the ' bind ' directive.
Protected-mode Yes # Accept connections on the specified port, default is 6379 (IANA #815344).
# If Port 0 is specified Redis would not listen on a TCP socket.
Port 6489 # TCP Listen () backlog.  # in high Requests-per-second environments you need a high backlog in order # to avoid slow clients connections issues. Note that the Linux kernel # would silently truncate it to the value of/proc/sys/net/core/somaxconn so # make sure to Rai
Se both the value of Somaxconn and Tcp_max_syn_backlog # in order to get the desired effect.
Tcp-backlog 511 # Unix socket. # # Specify the path for the Unix sockets that would be used to listen for # Incoming connections.
There is no default, so Redis would not listen # on a UNIX socket when not specified. # Unixsocket/tmp/reDis.sock # unixsocketperm # Close The connection after a client are idle for N seconds (0 to disable) Timeout 0 # TCP
KeepAlive. # # If Non-zero, use so_keepalive to send TCP ACKs to clients in absence # of communication.
This was useful for the reasons: # # 1) Detect dead peers.
# 2) Take the connection alive from the point of view of the network # equipment in the middle.
# on Linux, the specified value (in seconds) are the period used to send ACKs.
# Note that to close the connection, the double of the time is needed.
# on and kernels the period depends on the kernel configuration.
# # A Reasonable value for this option was seconds, which is the new # Redis default starting with Redis 3.2.1. Tcp-keepalive ################################# General ##################################### # By default Redis do Es not run as a daemon.
Use the ' yes ' if you need it.
# Note that Redis would write a PID file in/var/run/redis.pid when daemonized. Daemonize Yes # If you run the Redis from Upstart or SYSTEMD, Redis can interact with your # supervision tree.  Options: # Supervised no-no Supervision interaction # supervised upstart-signal upstart by putting Redis into  SIGSTOP Mode # supervised systemd-signal systemd by writing Ready=1 to $NOTIFY _socket # supervised Auto-detect Upstart or Systemd method based on # Upstart_job or notify_socket environment variables # note:th ESE supervision methods only signal "process was ready." # They does not enable continuous liveness pings back to your
Supervisor.
Supervised no # If a PID file is specified, Redis writes it where specified at startup # and removes it at exit. # # When the server runs non daemonized, no PID file was created if none was # specified in the configuration.
When the server was daemonized, the PID file # is used even if not specified and defaulting to "/var/run/redis.pid". # # Creating A PID file is the best effort:if Redis isn't able to create it # no bad happens, the server would start and run normally.
Pidfile/usr/local/redis-3.2.8/run/redis_6489.pid # Specify the server verbosity level. # This can is one of: # Debug (a lot of information, useful for development/testing) # Verbose (many rarely useful info, b UT not a mess like the "Debug level") # Notice (moderately verbose, what are want in production probably) # warning (only ve RY important/critical Messages is logged) loglevel Notice # Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. Note that if the standard # output for logging is daemonize, logs'll be sent To/dev/null logfile "/usr/local/redis -3.2.8/logs/redis.log "# To enable logging to the system logger, just set ' syslog-enabled ' to Yes, # and optionally updat
E The other syslog parameters to suit your needs.
# syslog-enabled No # Specify the syslog identity. # syslog-ident Redis # Specify the syslog facility.
Must be USER or between local0-local7. # Syslog-faciLity Local0 # Set the number of databases.  The default database is DB 0, you can select # a different one on a per-connection basis using select <dbid> where # Dbid is a number between 0 and ' databases '-1 databases ################################ snapshotting ############### ################# # Save the DB on disk: # # Save <seconds> <changes> # # would save the DB if both the G
Iven number of seconds and the given # Number of write operations against the DB occurred. # in the example below the behaviour would be is to save: # after the SEC (min.) If at least 1 key changed # after 3 XX sec (5 min) If at least ten keys changed # after the SEC if at least 10000 keys changed # # note:you can disable SAV
ing completely by commenting-all "save" lines.  # # It's also possible to remove all the previously configured save # Points by adding a save directive with a single Empty string argument # like in the following example: # # Save "" Save 900 1 Save ten 10000 # By default Redis would stop accepting writes if RDB snapshots is enabled # (at least one
Save point) and the latest background save failed.  # This would make the user aware (in a hard-to-do) that data is not persisting # on disk properly, otherwise chances was that
No one'll notice and some # disaster'll happen.
# # IF The background saving process would start working again Redis would # automatically allow writes again. # # However if you had setup your proper monitoring of the Redis server # and persistence, you could want to disable this F
Eature So, Redis would # continue to work as usual even if there is problems with disk, # permissions, and so forth.
Stop-writes-on-bgsave-error Yes # Compress string objects using LZF when dump. RDB databases?
# for default this ' s set to ' yes ' as it's almost always a win. # If you want to save some CPU on the saving child set it to ' no ' but # the dataset would likely be bigger If you have comp Ressible values or KEys.
Rdbcompression Yes # Since version 5 of RDB a CRC64 checksum is placed at the end of the file. # This makes the format of more resistant to corruption but there is a performance # hits to pay (around 10%) when saving and
Loading RDB files, so you can disable it # for maximum performances.
# # RDB files created with checksum disabled has a checksum of zero that would # tell the loading code to skip the check.
Rdbchecksum Yes # the filename where to dump the DB dbfilename Dump.rdb # The working directory.  # # The DB would be written inside this directory, with the filename specified # above using the ' dbfilename ' configuration
directive.
# # The Append only File would also be created inside this directory.
# Note that you must specify a directory here, not a file name. Dir/usr/local/redis-3.2.8/data ################################# REPLICATION ################################# # Master-slave replication. Use slaveof to make a Redis instance a copy of # another Redis server. A Few Things to understand ASAP about Redis replication.  # 1) Redis replication is asynchronous, but can configure a master to # stop accepting writes if it appears to be
Not connected with at least # a given number of slaves.  # 2) Redis slaves is able to perform a partial resynchronization with the # Master if the replication link was lost for A relatively small amount of # time. Want to configure the replication backlog size (see the next # sections of this file) with a sensible value DEP
Ending on your needs. # 3) Replication is automatic and does not need user intervention.
After a # network partition slaves automatically try to reconnect to Masters # and resynchronize with them. # # slaveof <masterip> <masterport> # If The master is password protected (using the "Requirepass" Configurat Ion # directive below) It's possible to tell the slave to authenticate before # starting the replication synchronization process, otherwise the master would
# refuse the slave request. # # Masterauth <master-password> # When a slave loses it connection with the master, or when the replication # is  Still in progress, the slave can act in both different ways: # # 1) If Slave-serve-stale-data is set to ' Yes ' (the default) The slave would # still reply to client requests, possibly with out of date data, or the # data set could just be empt
Y if this is the first synchronization. # 2) If Slave-serve-stale-data is set to ' no ' the Slave would reply with # A error "SYNC with Master in progress" to
All the kind of commands # but to INFO and slaveof. # slave-serve-stale-data Yes # can configure a Slave instance to accept writes or not. Writing against # A Slave instance may is useful to store some ephemeral data (because data # written on a slave would be E Asily deleted after Resync with the master) but # may also cause problems if clients is writing to it because of a # misc
Onfiguration. # # Since Redis 2.6 By default slavesIs read-only. # # Note:read Only slaves is not designed to being exposed to untrusted clients # on the Internet.
It ' s just a protection layer against misuse of the instance. # still a read only slave exports by default all the administrative commands # such as CONFIG, DEBUG, and so forth. To a limited extent your can improve # Security of Read only slaves using ' Rename-command ' to shadow all the # Administrati
ve/dangerous commands.
slave-read-only Yes # Replication SYNC strategy:disk or socket. # #-------------------------------------------------------# warning:diskless REPLICATION is experimental currently #- ------------------------------------------------------# # New slaves and reconnecting slaves that is not able to continu E The replication # process just receiving differences, need to does what's called a "Full # synchronization".
An RDB file was transmitted from the master to the slaves. # The transmission can happen in both different ways: # # 1) disk-backed:the Redis MasTER creates a new process that writes the RDB # file on disk.
Later the file is transferred by the parent # process to the slaves incrementally. # 2) diskless:the Redis Master creates a new process that directly writes the # RDB file to slave sockets, W
Ithout touching the disk at all. # # with disk-backed replication, while the Rdb file was generated, more slaves # can be queued and served with the RDB fil e As soon as the current child producing # The RDB file finishes it work.  With diskless replication instead once # The transfer starts, new slaves arriving would be queued and a new transfer # would
Start when the current one terminates. # when diskless replication was used, the master waits a configurable amount of # time (in seconds) before starting the T
Ransfer in the hope that multiple slaves # would arrive and the transfer can be parallelized.
# # with slow disks and fast (large bandwidth) networks, diskless replication # works better.Repl-diskless-sync No # When diskless replication is enabled, it's possible to configure the delay # the server waits in
Order to spawn the transfers the RDB via sockets # to the slaves. # # is important since once the transfer starts, it's not possible to serve # New slaves arriving, that'll be Queu
Ed for the next RDB transfer, so the server # waits-a delay in order-to-let more slaves arrive. # # The delay is specified in seconds, and by default is 5 seconds.
To disable # It entirely just set it to 0 seconds and the transfer would start ASAP. Repl-diskless-sync-delay 5 # Slaves Send PINGs to server in a predefined interval. It ' s possible to change # this interval with the Repl_ping_slave_period option.
The default value is ten # seconds. # # Repl-ping-slave-period # The following option sets the replication timeout for: # # 1) Bulk transfer I/O during SY
NC, from the point of view of slave.
# 2) Master timeout from the point of view of slaves (data, pings). # 3)Slave timeout from the point of view of Masters (replconf ACK pings). # # It's important to make sure, the this value was greater than the value # specified for Repl-ping-slave-period Otherwis
e a timeout would be detected # every time there was low traffic between the master and the slave.
# # Repl-timeout # Disable Tcp_nodelay on the slave socket after SYNC? # # IF you select "Yes" Redis would use a smaller number of TCP packets and # Less bandwidth to the send data to slaves. But this can add a delay for # The data to appear on the slave side, up to + milliseconds with # Linux kernels using a de
Fault configuration. # # If you select ' No ' the delay for data to appear on the slave side would # be reduced and more bandwidth would be used fo
R replication. # By default we optimize for low latency, but in very-traffic conditions # or when the master and slaves is many H
OPS away, turning this to ' yes ' may # is a good idea. Repl-disable-tcp-nodelay No # Set the replication backlog size. The backlog is a buffer of accumulates # slave data when slaves be disconnected for some time, so if a slave #  Wants to reconnect again, often a full resync was not needed, but a partial # resync is enough, just passing the portion of
Data the slave missed while # disconnected.  # The bigger the replication backlog, the longer the time the slave can be # disconnected and later being able to perform a
Partial resynchronization.
# # The backlog is only allocated once there are at least a slave connected. # # Repl-backlog-size 1MB # After a master have no longer connected slaves for some time, the backlog # would be freed. The following option configures the amount of seconds that # need-elapse, starting from the time the last slave disconn
Ected, for # The backlog of buffer to be freed. # # A value of 0 means to never release the backlog.
Related Article

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.