安装redis数据库

    xiaoxiao2025-01-30  46

    简介

    Redis是一个开源(BSD许可),内存数据结构存储,用作数据库,缓存和消息代理。它支持数据结构,如 字符串,散列,列表,集合,带有范围查询的排序集,位图,超级日志,具有半径查询和流的地理空间索引。Redis具有内置复制,Lua脚本,LRU驱逐,事务和不同级别的磁盘持久性,并通过Redis Sentinel和Redis Cluster自动分区。

    您可以 对这些类型运行原子操作,例如附加到字符串 ; 递增哈希值 ; 将元素推送到列表中 ; 计算集合交集, 并集和差异 ; 或者在排序集中获得排名最高的成员。

    为了实现其出色的性能,Redis使用 内存数据集。根据您的使用情况,您可以通过 每隔一段时间将数据集转储到磁盘或通过将每个命令附加到日志来保留它。如果您只需要功能丰富的网络内存缓存,则可以选择禁用持久性。

    Redis还支持简单到设置的主从异步复制,具有非常快速的非阻塞第一次同步,自动重新连接以及在网络分割上的部分重新同步。 redis官网: https://redis.io/

    下面就开始安装redis啦

    [root@centos-1 ~]#wget http://download.redis.io/releases/redis-3.2.3.tar.gz [root@centos-1 ~]# tar zxf redis-3.2.3.tar.gz [root@centos-1 ~]# cd redis-3.2.3 [root@centos-1 redis-3.2.3]# make && make install [root@centos-1 redis-3.2.3]# cd utils/ 这里直接回车,默认即可。 [root@centos-1 utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! [root@centos-1 utils]# cat /etc/systemd/system/redis_6379.service [Unit] Description=Redis on port 6379 [Service] Type=forking ExecStart=/etc/init.d/redis_6379 start ExecStop=/etc/init.d/redis_6379 stop [Install] WantedBy=multi-user.target [root@centos-1 utils]# systemctl daemon-reload [root@centos-1 utils]# systemctl enable redis [root@centos-1 utils]# systemctl start redis_6379.service [root@centos-1 utils]# systemctl status redis_6379 ● redis_6379.service - Redis on port 6379 Loaded: loaded (/etc/systemd/system/redis_6379.service; enabled; vendor preset: disabled) Active: active (running) since 日 2019-05-26 14:15:51 CST; 941ms ago Process: 5030 ExecStop=/etc/init.d/redis_6379 stop (code=exited, status=0/SUCCESS) Process: 5042 ExecStart=/etc/init.d/redis_6379 start (code=exited, status=0/SUCCESS) Main PID: 5044 (redis-server) CGroup: /system.slice/redis_6379.service └─5044 /usr/local/bin/redis-server 127.0.0.1:6379 5月 26 14:15:51 centos-1 systemd[1]: Starting Redis on port 6379... 5月 26 14:15:51 centos-1 redis_6379[5042]: Starting Redis server... 5月 26 14:15:51 centos-1 systemd[1]: Started Redis on port 6379. [root@centos-1 utils]# firewall-cmd --permanent --add-port=3679/tcp success [root@centos-1 utils]# firewall-cmd --reload success 修改或者添加以下内容 [root@centos-1 utils]# vim /etc/redis/6379.conf bind 127.0.0.1 192.168.1.101 requirepass pwd@123 [root@centos-1 utils]# systemctl restart redis_6379 [root@centos-1 utils]# ss -anpt | grep redis LISTEN 0 128 192.168.1.101:6379 *:* users:(("redis-server",pid=5100,fd=5)) LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=5100,fd=4)) [root@centos-1 utils]# redis-cli -h 127.0.0.1 -p 6379 -a pwd@123 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set name list OK 127.0.0.1:6379> get name "list" 127.0.0.1:6379> exit
    最新回复(0)