当前位置:   article > 正文

Redis 下载安装_redis安装包

redis安装包

目录

Linux安装

1.安装Redis依赖

2.下载安装包并解压

3.启动

默认启动

指定配置文件启动

开机启动

Docker安装

1.搜索镜像

 2.下载镜像

3.配置文件

3.启动容器

 Redis客服端

1.Redis命令行客户端

 2.图形化桌面客户端

 安装

 建立连接


Linux安装

此处选择的Linux版本为CentOS 7.

Redis的官方网站地址:Redis

1.安装Redis依赖

Redis是基于C语言编写的,因此首先需要安装Redis所需要的gcc依赖:

yum install -y gcc tcl

2.下载安装包并解压

Download | Redis

 例如,我放到了/usr/local/src 目录:

 解压缩:

tar -xzf redis-6.2.6.tar.gz

解压后:

进入redis目录:

cd redis-6.2.6

 运行编译命令:

make && make install

如果没有出错,应该就安装成功了。

默认的安装路径是在 /usr/local/bin目录下:

该目录以及默认配置到环境变量,因此可以在任意目录下运行这些命令。其中:

  • redis-cli:是redis提供的命令行客户端

  • redis-server:是redis的服务端启动脚本

  • redis-sentinel:是redis的哨兵启动脚本

3.启动

redis的启动方式有很多种,例如:

  • 默认启动

  • 指定配置启动

  • 开机自启

默认启动

安装完成后,在任意目录输入redis-server命令即可启动Redis:

redis-server

如图:

 这种启动属于前台启动,会阻塞整个会话窗口,窗口关闭或者按下CTRL + C则Redis停止。不推荐使用。

指定配置文件启动

如果要让Redis以后台方式启动,则必须修改Redis配置文件,就在我们之前解压的redis安装包下(/usr/local/src/redis-6.2.6),名字叫redis.conf:

 我们先将这个配置文件备份一份:

cp redis.conf redis.conf.bck

然后修改redis.conf文件中的一些配置:

  1. # 允许访问的地址,默认是127.0.0.1,会导致只能在本地访问。修改为0.0.0.0则可以在任意IP访问,生产环境不要设置为0.0.0.0
  2. bind 0.0.0.0
  3. # 守护进程,修改为yes后即可后台运行
  4. daemonize yes
  5. # 密码,设置后访问Redis必须输入密码
  6. requirepass 123321

Redis的其它常见配置:

  1. # 监听的端口
  2. port 6379
  3. # 工作目录,默认是当前目录,也就是运行redis-server时的命令,日志、持久化等文件会保存在这个目录
  4. dir .
  5. # 数据库数量,设置为1,代表只使用1个库,默认有16个库,编号0~15
  6. databases 1
  7. # 设置redis能够使用的最大内存
  8. maxmemory 512mb
  9. # 日志文件,默认为空,不记录日志,可以指定日志文件名
  10. logfile "redis.log"

启动Redis:

  1. # 进入redis安装目录
  2. cd /usr/local/src/redis-6.2.6
  3. # 启动
  4. redis-server redis.conf

停止服务:

  1. # 利用redis-cli来执行 shutdown 命令,即可停止 Redis 服务,
  2. # 因为之前配置了密码,因此需要通过 -u 来指定密码
  3. redis-cli -u 123321 shutdown

开机启动

我们也可以通过配置来实现开机自启。

首先,新建一个系统服务文件:

vi /etc/systemd/system/redis.service

内容如下:

  1. [Unit]
  2. Description=redis-server
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/bin/redis-server /usr/local/src/redis-6.2.6/redis.conf
  7. PrivateTmp=true
  8. [Install]
  9. WantedBy=multi-user.target

然后重载系统服务:

systemctl daemon-reload

现在,我们可以用下面这组命令来操作redis了:

  1. # 启动
  2. systemctl start redis
  3. # 停止
  4. systemctl stop redis
  5. # 重启
  6. systemctl restart redis
  7. # 查看状态
  8. systemctl status redis

执行下面的命令,可以让redis开机自启:

systemctl enable redis

Docker安装

1.搜索镜像

https://hub.docker.com/

 2.下载镜像

不指明redis镜像版本时,docker pull redis默认下载最新版本镜像,如下:

为了后面更好的解释docker的run命令,我选择一个不是最新版本的redis来做演示

docker pull redis:7.0.4

 

 

3.配置文件

下载配置文件:Redis configuration | Redis

注意不同版本的redis配置文件内容不一样,要下载对应版本的redis配置文件

自行创建一个redis.conf文件,将官网的redis.conf内容复制进去即可,然后修改一下配置文件内容

默认内容如下:

  1. # Redis configuration file example.
  2. #
  3. # Note that in order to read the configuration file, Redis must be
  4. # started with the file path as first argument:
  5. #
  6. # ./redis-server /path/to/redis.conf
  7. # Note on units: when memory size is needed, it is possible to specify
  8. # it in the usual form of 1k 5GB 4M and so forth:
  9. #
  10. # 1k => 1000 bytes
  11. # 1kb => 1024 bytes
  12. # 1m => 1000000 bytes
  13. # 1mb => 1024*1024 bytes
  14. # 1g => 1000000000 bytes
  15. # 1gb => 1024*1024*1024 bytes
  16. #
  17. # units are case insensitive so 1GB 1Gb 1gB are all the same.
  18. ################################## INCLUDES ###################################
  19. # Include one or more other config files here. This is useful if you
  20. # have a standard template that goes to all Redis servers but also need
  21. # to customize a few per-server settings. Include files can include
  22. # other files, so use this wisely.
  23. #
  24. # Note that option "include" won't be rewritten by command "CONFIG REWRITE"
  25. # from admin or Redis Sentinel. Since Redis always uses the last processed
  26. # line as value of a configuration directive, you'd better put includes
  27. # at the beginning of this file to avoid overwriting config change at runtime.
  28. #
  29. # If instead you are interested in using includes to override configuration
  30. # options, it is better to use include as the last line.
  31. #
  32. # Included paths may contain wildcards. All files matching the wildcards will
  33. # be included in alphabetical order.
  34. # Note that if an include path contains a wildcards but no files match it when
  35. # the server is started, the include statement will be ignored and no error will
  36. # be emitted. It is safe, therefore, to include wildcard files from empty
  37. # directories.
  38. #
  39. # include /path/to/local.conf
  40. # include /path/to/other.conf
  41. # include /path/to/fragments/*.conf
  42. #
  43. ################################## MODULES #####################################
  44. # Load modules at startup. If the server is not able to load modules
  45. # it will abort. It is possible to use multiple loadmodule directives.
  46. #
  47. # loadmodule /path/to/my_module.so
  48. # loadmodule /path/to/other_module.so
  49. ################################## NETWORK #####################################
  50. # By default, if no "bind" configuration directive is specified, Redis listens
  51. # for connections from all available network interfaces on the host machine.
  52. # It is possible to listen to just one or multiple selected interfaces using
  53. # the "bind" configuration directive, followed by one or more IP addresses.
  54. # Each address can be prefixed by "-", which means that redis will not fail to
  55. # start if the address is not available. Being not available only refers to
  56. # addresses that does not correspond to any network interface. Addresses that
  57. # are already in use will always fail, and unsupported protocols will always BE
  58. # silently skipped.
  59. #
  60. # Examples:
  61. #
  62. # bind 192.168.1.100 10.0.0.1 # listens on two specific IPv4 addresses
  63. # bind 127.0.0.1 ::1 # listens on loopback IPv4 and IPv6
  64. # bind * -::* # like the default, all available interfaces
  65. #
  66. # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
  67. # internet, binding to all the interfaces is dangerous and will expose the
  68. # instance to everybody on the internet. So by default we uncomment the
  69. # following bind directive, that will force Redis to listen only on the
  70. # IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
  71. # will only be able to accept client connections from the same host that it is
  72. # running on).
  73. #
  74. # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
  75. # COMMENT OUT THE FOLLOWING LINE.
  76. #
  77. # You will also need to set a password unless you explicitly disable protected
  78. # mode.
  79. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. bind 127.0.0.1 -::1
  81. # By default, outgoing connections (from replica to master, from Sentinel to
  82. # instances, cluster bus, etc.) are not bound to a specific local address. In
  83. # most cases, this means the operating system will handle that based on routing
  84. # and the interface through which the connection goes out.
  85. #
  86. # Using bind-source-addr it is possible to configure a specific address to bind
  87. # to, which may also affect how the connection gets routed.
  88. #
  89. # Example:
  90. #
  91. # bind-source-addr 10.0.0.1
  92. # Protected mode is a layer of security protection, in order to avoid that
  93. # Redis instances left open on the internet are accessed and exploited.
  94. #
  95. # When protected mode is on and the default user has no password, the server
  96. # only accepts local connections from the IPv4 address (127.0.0.1), IPv6 address
  97. # (::1) or Unix domain sockets.
  98. #
  99. # By default protected mode is enabled. You should disable it only if
  100. # you are sure you want clients from other hosts to connect to Redis
  101. # even if no authentication is configured.
  102. protected-mode yes
  103. # Redis uses default hardened security configuration directives to reduce the
  104. # attack surface on innocent users. Therefore, several sensitive configuration
  105. # directives are immutable, and some potentially-dangerous commands are blocked.
  106. #
  107. # Configuration directives that control files that Redis writes to (e.g., 'dir'
  108. # and 'dbfilename') and that aren't usually modified during runtime
  109. # are protected by making them immutable.
  110. #
  111. # Commands that can increase the attack surface of Redis and that aren't usually
  112. # called by users are blocked by default.
  113. #
  114. # These can be exposed to either all connections or just local ones by setting
  115. # each of the configs listed below to either of these values:
  116. #
  117. # no - Block for any connection (remain immutable)
  118. # yes - Allow for any connection (no protection)
  119. # local - Allow only for local connections. Ones originating from the
  120. # IPv4 address (127.0.0.1), IPv6 address (::1) or Unix domain sockets.
  121. #
  122. # enable-protected-configs no
  123. # enable-debug-command no
  124. # enable-module-command no
  125. # Accept connections on the specified port, default is 6379 (IANA #815344).
  126. # If port 0 is specified Redis will not listen on a TCP socket.
  127. port 6379
  128. # TCP listen() backlog.
  129. #
  130. # In high requests-per-second environments you need a high backlog in order
  131. # to avoid slow clients connection issues. Note that the Linux kernel
  132. # will silently truncate it to the value of /proc/sys/net/core/somaxconn so
  133. # make sure to raise both the value of somaxconn and tcp_max_syn_backlog
  134. # in order to get the desired effect.
  135. tcp-backlog 511
  136. # Unix socket.
  137. #
  138. # Specify the path for the Unix socket that will be used to listen for
  139. # incoming connections. There is no default, so Redis will not listen
  140. # on a unix socket when not specified.
  141. #
  142. # unixsocket /run/redis.sock
  143. # unixsocketperm 700
  144. # Close the connection after a client is idle for N seconds (0 to disable)
  145. timeout 0
  146. # TCP keepalive.
  147. #
  148. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
  149. # of communication. This is useful for two reasons:
  150. #
  151. # 1) Detect dead peers.
  152. # 2) Force network equipment in the middle to consider the connection to be
  153. # alive.
  154. #
  155. # On Linux, the specified value (in seconds) is the period used to send ACKs.
  156. # Note that to close the connection the double of the time is needed.
  157. # On other kernels the period depends on the kernel configuration.
  158. #
  159. # A reasonable value for this option is 300 seconds, which is the new
  160. # Redis default starting with Redis 3.2.1.
  161. tcp-keepalive 300
  162. # Apply OS-specific mechanism to mark the listening socket with the specified
  163. # ID, to support advanced routing and filtering capabilities.
  164. #
  165. # On Linux, the ID represents a connection mark.
  166. # On FreeBSD, the ID represents a socket cookie ID.
  167. # On OpenBSD, the ID represents a route table ID.
  168. #
  169. # The default value is 0, which implies no marking is required.
  170. # socket-mark-id 0
  171. ################################# TLS/SSL #####################################
  172. # By default, TLS/SSL is disabled. To enable it, the "tls-port" configuration
  173. # directive can be used to define TLS-listening ports. To enable TLS on the
  174. # default port, use:
  175. #
  176. # port 0
  177. # tls-port 6379
  178. # Configure a X.509 certificate and private key to use for authenticating the
  179. # server to connected clients, masters or cluster peers. These files should be
  180. # PEM formatted.
  181. #
  182. # tls-cert-file redis.crt
  183. # tls-key-file redis.key
  184. #
  185. # If the key file is encrypted using a passphrase, it can be included here
  186. # as well.
  187. #
  188. # tls-key-file-pass secret
  189. # Normally Redis uses the same certificate for both server functions (accepting
  190. # connections) and client functions (replicating from a master, establishing
  191. # cluster bus connections, etc.).
  192. #
  193. # Sometimes certificates are issued with attributes that designate them as
  194. # client-only or server-only certificates. In that case it may be desired to use
  195. # different certificates for incoming (server) and outgoing (client)
  196. # connections. To do that, use the following directives:
  197. #
  198. # tls-client-cert-file client.crt
  199. # tls-client-key-file client.key
  200. #
  201. # If the key file is encrypted using a passphrase, it can be included here
  202. # as well.
  203. #
  204. # tls-client-key-file-pass secret
  205. # Configure a DH parameters file to enable Diffie-Hellman (DH) key exchange,
  206. # required by older versions of OpenSSL (<3.0). Newer versions do not require
  207. # this configuration and recommend against it.
  208. #
  209. # tls-dh-params-file redis.dh
  210. # Configure a CA certificate(s) bundle or directory to authenticate TLS/SSL
  211. # clients and peers. Redis requires an explicit configuration of at least one
  212. # of these, and will not implicitly use the system wide configuration.
  213. #
  214. # tls-ca-cert-file ca.crt
  215. # tls-ca-cert-dir /etc/ssl/certs
  216. # By default, clients (including replica servers) on a TLS port are required
  217. # to authenticate using valid client side certificates.
  218. #
  219. # If "no" is specified, client certificates are not required and not accepted.
  220. # If "optional" is specified, client certificates are accepted and must be
  221. # valid if provided, but are not required.
  222. #
  223. # tls-auth-clients no
  224. # tls-auth-clients optional
  225. # By default, a Redis replica does not attempt to establish a TLS connection
  226. # with its master.
  227. #
  228. # Use the following directive to enable TLS on replication links.
  229. #
  230. # tls-replication yes
  231. # By default, the Redis Cluster bus uses a plain TCP connection. To enable
  232. # TLS for the bus protocol, use the following directive:
  233. #
  234. # tls-cluster yes
  235. # By default, only TLSv1.2 and TLSv1.3 are enabled and it is highly recommended
  236. # that older formally deprecated versions are kept disabled to reduce the attack surface.
  237. # You can explicitly specify TLS versions to support.
  238. # Allowed values are case insensitive and include "TLSv1", "TLSv1.1", "TLSv1.2",
  239. # "TLSv1.3" (OpenSSL >= 1.1.1) or any combination.
  240. # To enable only TLSv1.2 and TLSv1.3, use:
  241. #
  242. # tls-protocols "TLSv1.2 TLSv1.3"
  243. # Configure allowed ciphers. See the ciphers(1ssl) manpage for more information
  244. # about the syntax of this string.
  245. #
  246. # Note: this configuration applies only to <= TLSv1.2.
  247. #
  248. # tls-ciphers DEFAULT:!MEDIUM
  249. # Configure allowed TLSv1.3 ciphersuites. See the ciphers(1ssl) manpage for more
  250. # information about the syntax of this string, and specifically for TLSv1.3
  251. # ciphersuites.
  252. #
  253. # tls-ciphersuites TLS_CHACHA20_POLY1305_SHA256
  254. # When choosing a cipher, use the server's preference instead of the client
  255. # preference. By default, the server follows the client's preference.
  256. #
  257. # tls-prefer-server-ciphers yes
  258. # By default, TLS session caching is enabled to allow faster and less expensive
  259. # reconnections by clients that support it. Use the following directive to disable
  260. # caching.
  261. #
  262. # tls-session-caching no
  263. # Change the default number of TLS sessions cached. A zero value sets the cache
  264. # to unlimited size. The default size is 20480.
  265. #
  266. # tls-session-cache-size 5000
  267. # Change the default timeout of cached TLS sessions. The default timeout is 300
  268. # seconds.
  269. #
  270. # tls-session-cache-timeout 60
  271. ################################# GENERAL #####################################
  272. # By default Redis does not run as a daemon. Use 'yes' if you need it.
  273. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  274. # When Redis is supervised by upstart or systemd, this parameter has no impact.
  275. daemonize no
  276. # If you run Redis from upstart or systemd, Redis can interact with your
  277. # supervision tree. Options:
  278. # supervised no - no supervision interaction
  279. # supervised upstart - signal upstart by putting Redis into SIGSTOP mode
  280. # requires "expect stop" in your upstart job config
  281. # supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
  282. # on startup, and updating Redis status on a regular
  283. # basis.
  284. # supervised auto - detect upstart or systemd method based on
  285. # UPSTART_JOB or NOTIFY_SOCKET environment variables
  286. # Note: these supervision methods only signal "process is ready."
  287. # They do not enable continuous pings back to your supervisor.
  288. #
  289. # The default is "no". To run under upstart/systemd, you can simply uncomment
  290. # the line below:
  291. #
  292. # supervised auto
  293. # If a pid file is specified, Redis writes it where specified at startup
  294. # and removes it at exit.
  295. #
  296. # When the server runs non daemonized, no pid file is created if none is
  297. # specified in the configuration. When the server is daemonized, the pid file
  298. # is used even if not specified, defaulting to "/var/run/redis.pid".
  299. #
  300. # Creating a pid file is best effort: if Redis is not able to create it
  301. # nothing bad happens, the server will start and run normally.
  302. #
  303. # Note that on modern Linux systems "/run/redis.pid" is more conforming
  304. # and should be used instead.
  305. pidfile /var/run/redis_6379.pid
  306. # Specify the server verbosity level.
  307. # This can be one of:
  308. # debug (a lot of information, useful for development/testing)
  309. # verbose (many rarely useful info, but not a mess like the debug level)
  310. # notice (moderately verbose, what you want in production probably)
  311. # warning (only very important / critical messages are logged)
  312. loglevel notice
  313. # Specify the log file name. Also the empty string can be used to force
  314. # Redis to log on the standard output. Note that if you use standard
  315. # output for logging but daemonize, logs will be sent to /dev/null
  316. logfile ""
  317. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
  318. # and optionally update the other syslog parameters to suit your needs.
  319. # syslog-enabled no
  320. # Specify the syslog identity.
  321. # syslog-ident redis
  322. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
  323. # syslog-facility local0
  324. # To disable the built in crash log, which will possibly produce cleaner core
  325. # dumps when they are needed, uncomment the following:
  326. #
  327. # crash-log-enabled no
  328. # To disable the fast memory check that's run as part of the crash log, which
  329. # will possibly let redis terminate sooner, uncomment the following:
  330. #
  331. # crash-memcheck-enabled no
  332. # Set the number of databases. The default database is DB 0, you can select
  333. # a different one on a per-connection basis using SELECT <dbid> where
  334. # dbid is a number between 0 and 'databases'-1
  335. databases 16
  336. # By default Redis shows an ASCII art logo only when started to log to the
  337. # standard output and if the standard output is a TTY and syslog logging is
  338. # disabled. Basically this means that normally a logo is displayed only in
  339. # interactive sessions.
  340. #
  341. # However it is possible to force the pre-4.0 behavior and always show a
  342. # ASCII art logo in startup logs by setting the following option to yes.
  343. always-show-logo no
  344. # By default, Redis modifies the process title (as seen in 'top' and 'ps') to
  345. # provide some runtime information. It is possible to disable this and leave
  346. # the process name as executed by setting the following to no.
  347. set-proc-title yes
  348. # When changing the process title, Redis uses the following template to construct
  349. # the modified title.
  350. #
  351. # Template variables are specified in curly brackets. The following variables are
  352. # supported:
  353. #
  354. # {title} Name of process as executed if parent, or type of child process.
  355. # {listen-addr} Bind address or '*' followed by TCP or TLS port listening on, or
  356. # Unix socket if only that's available.
  357. # {server-mode} Special mode, i.e. "[sentinel]" or "[cluster]".
  358. # {port} TCP port listening on, or 0.
  359. # {tls-port} TLS port listening on, or 0.
  360. # {unixsocket} Unix domain socket listening on, or "".
  361. # {config-file} Name of configuration file used.
  362. #
  363. proc-title-template "{title} {listen-addr} {server-mode}"
  364. ################################ SNAPSHOTTING ################################
  365. # Save the DB to disk.
  366. #
  367. # save <seconds> <changes> [<seconds> <changes> ...]
  368. #
  369. # Redis will save the DB if the given number of seconds elapsed and it
  370. # surpassed the given number of write operations against the DB.
  371. #
  372. # Snapshotting can be completely disabled with a single empty string argument
  373. # as in following example:
  374. #
  375. # save ""
  376. #
  377. # Unless specified otherwise, by default Redis will save the DB:
  378. # * After 3600 seconds (an hour) if at least 1 change was performed
  379. # * After 300 seconds (5 minutes) if at least 100 changes were performed
  380. # * After 60 seconds if at least 10000 changes were performed
  381. #
  382. # You can set these explicitly by uncommenting the following line.
  383. #
  384. # save 3600 1 300 100 60 10000
  385. # By default Redis will stop accepting writes if RDB snapshots are enabled
  386. # (at least one save point) and the latest background save failed.
  387. # This will make the user aware (in a hard way) that data is not persisting
  388. # on disk properly, otherwise chances are that no one will notice and some
  389. # disaster will happen.
  390. #
  391. # If the background saving process will start working again Redis will
  392. # automatically allow writes again.
  393. #
  394. # However if you have setup your proper monitoring of the Redis server
  395. # and persistence, you may want to disable this feature so that Redis will
  396. # continue to work as usual even if there are problems with disk,
  397. # permissions, and so forth.
  398. stop-writes-on-bgsave-error
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/875832
推荐阅读
相关标签
  

闽ICP备14008679号