zoukankan      html  css  js  c++  java
  • centos8 安装 redis5

    引言

    本文转自centos8安装redis,如果其中redis目录不存在,按照命令中路径创建即可,同时注意按照自己的目录,修改响应命令,步骤不再赘述,这里只提一下关于redis配置文件修改的事儿,redis安装配置文件配置

    另外,redis5 我虚拟机上的下载目录:

    [root@localhost xgcd]# cd /home/xgcd/
    [root@localhost xgcd]# 
    [root@localhost xgcd]# ll
    total 140048
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Desktop
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Documents
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Downloads
    -rw-rw-r--. 1 xgcd xgcd 41182192 Mar 17 05:10 esl-erlang_22.2.8-1_centos_8_amd64.rpm
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Music
    -rw-rw-r--. 1 xgcd xgcd 87768737 Mar 17 06:35 otp_src_22.2.tar.gz
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Pictures
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Public
    -rw-rw-r--. 1 xgcd xgcd 12462936 Mar 17 06:00 rabbitmq-server-3.8.3-1.el8.noarch.rpm
    drwxrwxr-x. 6 root root     4096 Nov 20 01:05 redis-5.0.7
    -rw-r--r--. 1 root root  1984203 Nov 20 01:06 redis-5.0.7.tar.gz
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Templates
    drwxr-xr-x. 2 xgcd xgcd        6 Mar 16 22:31 Videos

    配置文件目录:

    [root@localhost conf]# cd /usr/local/soft/redis5/conf/
    [root@localhost conf]# ll
    total 64
    -rw-r--r--. 1 root root 61794 Mar 20 11:12 redis.conf

    配置文件关键项:

    bind 127.0.0.1
    bind 192.168.81.129
    
    protected-mode yes
    
    port 6379
    
    daemonize yes
    
    logfile "/usr/local/soft/redis5/log/redis.log"
    
    dbfilename dump.rdb
    
    dir ./
    
    requirepass 123456

    启动并查看状态:

    [root@localhost redis5]# ./bin/redis-server /usr/local/soft/redis5/conf/redis.conf 
    [root@localhost redis5]# 
    [root@localhost redis5]# netstat -anp|grep 6379
    tcp        0      0 192.168.81.129:6379     0.0.0.0:*               LISTEN      14993/./bin/redis-s 
    [root@localhost redis5]# 
    [root@localhost redis5]# 
    [root@localhost redis5]# ps -ef|grep redis
    root      14993      1  0 07:29 ?        00:00:00 ./bin/redis-server 192.168.81.129:6379
    root      15000   2363  0 07:30 pts/0    00:00:00 grep --color=auto redis
    [root@localhost redis5]# 
    [root@localhost redis5]# 

     客户端连接测试:

    [root@localhost redis5]# ./bin/redis-cli -h 192.168.81.129 -a 123456
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.81.129:6379> 
    192.168.81.129:6379> ping
    PONG
    192.168.81.129:6379> 
    192.168.81.129:6379> 

    防火墙状态查看:(关于防火墙详细可看linux防火墙——redis connect refused...问题解决

    [root@localhost xgcd]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
       Active: active (running) since Sat 2020-03-21 04:12:17 CST; 2h 59min ago
         Docs: man:firewalld(1)
     Main PID: 944 (firewalld)
        Tasks: 2 (limit: 4874)
       Memory: 2.6M
       CGroup: /system.slice/firewalld.service
               └─944 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid
    
    Mar 21 04:12:16 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
    Mar 21 04:12:17 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
    [root@localhost xgcd]# 

    防火墙配置文件查看:

    [root@localhost sysconfig]# vi iptables
    [root@localhost sysconfig]# 

    内容为:

    # sample configuration for iptables service
    # you can edit this manually or use system-config-firewall
    # please do not ask us to add additional ports/services to this default configuration
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT

    重启防火墙:

    [root@localhost sysconfig]# service iptables restart
    Redirecting to /bin/systemctl restart iptables.service
    [root@localhost sysconfig]# systemctl restart iptables.service
    [root@localhost sysconfig]# 
    [root@localhost sysconfig]# 
    [root@localhost sysconfig]# 
    [root@localhost sysconfig]# iptables -L -n
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:6379
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination         
    [root@localhost sysconfig]# 
    [root@localhost sysconfig]# 

    再次查看端口状态:

    [root@localhost sysconfig]# iptables -L -n
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:6379
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination         
    [root@localhost sysconfig]# 

     redis manager 客户端连接测试:

    启动

    [root@localhost redis5]# ./bin/redis-server /usr/local/soft/redis5/conf/redis.conf 
    [root@localhost redis5]# 

    停止

    直接杀进程欧了

    设置开机自启动

    centos8 设置 redis 开机自启动

    以下为转载正文

    一,下载:

           1,下载页面:

           https://redis.io/

           2,下载

    [root@localhost source]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz

    说明:架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

     说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,解压:

    [root@localhost source]# tar -xzvf redis-5.0.7.tar.gz 

    三,准备编译

    1,  请在操作前确认gcc是否已安装,

    如未安装,可以执行这个命令安装:

    [root@localhost redis-5.0.7]# yum install gcc

    2,请在操作前确认tcl是否已安装

    如未安装,可以执行这个命令安装:

    [root@localhost redis-5.0.7]# yum install tcl

    四,编译:

    [root@localhost source]# cd redis-5.0.7/
    
    [root@localhost redis-5.0.7]# make MALLOC=libc

    说明:make 后加 MALLOC的参数的原因:

              避免提示找不到 jemalloc/jemalloc.h

    五,测试编译:

    [root@localhost redis-5.0.7]# make test

    如果看到以下字样:表示无错误:

    o/ All tests passed without errors!

    六,安装:

    [root@localhost redis-5.0.7]# mkdir /usr/local/soft/redis5
    [root@localhost redis-5.0.7]# cd /usr/local/soft/redis5/
    [root@localhost redis5]# mkdir bin
    [root@localhost redis5]# mkdir conf
    [root@localhost redis5]# cd bin/
    [root@localhost bin]# cp /usr/local/source/redis-5.0.7/src/redis-cli ./
    [root@localhost bin]# cp /usr/local/source/redis-5.0.7/src/redis-server ./
    [root@localhost bin]# cd ../conf/
    [root@localhost conf]# cp /usr/local/source/redis-5.0.7/redis.conf ./

    七,配置:

    [root@localhost conf]# vi redis.conf

    设置以下两个地方:

    # daemonize no
    daemonize yes
    
    # maxmemory <bytes>
    maxmemory 128MB 

    说明:分别是以daemon方式独立运行   / 内存的最大使用限制

    八,运行:

    [root@localhost conf]# /usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.conf

    九,检查端口是否在使用中

    [root@localhost conf]# netstat -anp | grep 6379
    
    tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      16073/redis-server  

    十,查看redis的当前版本:

    [root@localhost conf]# /usr/local/soft/redis5/bin/redis-server -v
    
    Redis server v=5.0.7 sha=00000000:0 malloc=libc bits=64 build=8e31d2ed9a4c9593

    十一,使redis可以用systemd方式启动和管理

    1,编辑service文件

    [root@localhost liuhongdi]# vim /lib/systemd/system/redis.service

    2,service文件内容:

    [Unit]
    Description=Redis
    After=network.target

    [Service]
    Type=forking
    PIDFile=/var/run/redis_6379.pid
    ExecStart=/usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

    3.重载系统服务

    [root@localhost liuhongdi]# systemctl daemon-reload

    4,用来管理redis

    启动
    systemctl start redis    
    查看状态
    systemctl status redis
    使开机启动
    systemctl enable redis

    十二,查看本地centos的版本:

    [root@localhost lib]# cat /etc/redhat-release 
    CentOS Linux release 8.1.1911 (Core) 
  • 相关阅读:
    php
    图片拖拽
    12.20
    正则详细讲解
    12.19
    正则
    闭包
    date类
    二分查找
    冒泡排序
  • 原文地址:https://www.cnblogs.com/yadongliang/p/12530498.html
Copyright © 2011-2022 走看看