Home  >  Article  >  Database  >  How to install and configure redis in Ubuntu

How to install and configure redis in Ubuntu

WBOY
WBOYforward
2023-05-30 17:31:061601browse

Use the command line to update all software packages

sudo apt-get update
###### 在Linux Ubuntu中安装Redis数据库

```LINUX
#安装Redis服务器端
~ sudo apt-get install redis-server

After the installation is completed, the Redis server will start automatically. We check the Redis server program

# 检查Redis服务器系统进程
~ ps -aux|grep redis
redis     4162  0.1  0.0  10676  1420 ?        Ss   23:24   0:00 /usr/bin/redis-server /etc/redis/redis.conf
conan     4172  0.0  0.0  11064   924 pts/0    S+   23:26   0:00 grep --color=auto redis

# 通过启动命令检查Redis服务器状态
~ netstat -nlt|grep 6379
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN

# 通过启动命令检查Redis服务器状态
~ sudo /etc/init.d/redis-server status
redis-server is running
Access Redis through the command line client

Installing the Redis server will automatically install the Redis command line client program.
Enter the redis-cli command on the local machine to start, and the client program accesses the Redis server.

~ redis-cli
redis 127.0.0.1:6379>

# 命令行的帮助
redis 127.0.0.1:6379> help
redis-cli 2.2.12
Type: "help @" to get a list of commands in 
      "help " for help on 
      "help " to get a list of possible help topics
      "quit" to exit


# 查看所有的key列表
redis 127.0.0.1:6379> keys *
(empty list or set)
Modify Redis configuration

By default, no password is required to access the Redis server. In order to increase security, we need to set the access password of the Redis server. Set the access password to redisredis.

  • Use vi to open the configuration file redis.conf of the Redis server

~ sudo vi /etc/redis/redis.conf

#取消注释requirepass
requirepass redisredis
Let the Redis server be accessed remotely
~ sudo vi /etc/redis/redis.conf

#注释bind
#bind 127.0.0.1
Modify After that, restart the Redis server.
~ sudo /etc/init.d/redis-server restart
Stopping redis-server: redis-server.
Starting redis-server: redis-server.
  • We check the network listening port of Redis

检查Redis服务器占用端口
~ netstat -nlt|grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN

The above is the detailed content of How to install and configure redis in Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete