文章目录

  • ubuntu, debian 安装redis,设置开机自动启动和密码,允许外网访问
  • 通过Python3连接redis

ubuntu, debian 安装redis,设置开机自动启动和密码,允许外网访问

apt的包里自带redis,如果对redis的版本不是要求特别高的,可以直接使用apt进行安装:

apt install redis-server

启动redis:

redis-server

启动命令行接口:

redis-cli

注意:使用apt安装后,redis的默认配置文件的位置是:/etc/redis/redis.conf
复制配置文件后进行修改:

nano /etc/redis/redis.conf

注释掉bind ip这行,把保护模式关闭,外网就可以访问了(要设置密码):

#bind 127.0.0.1 ::1
protected-mode no #把yes改为no

apt安装的redis是默认后台启动的:

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

设置密码:

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass test

用新的配置文件重启redis:

service redis-server restart

修改配置:

sudo echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sudo sysctl -p
sudo echo 2048 > /proc/sys/net/core/somaxconn
sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled
chmod 644 /etc/redis/redis.conf
service redis-server start

通过Python3连接redis

先安装redis库:

pip3 install redis

然后进行连接:

import redis
r=redis.Redis(host='127.0.0.1',port=6379,password='test')
r.set('test','connect success')
print(r.get('test'))

如果输出connect success,说明连接成功了。


需要注意的是redis.Redis的参数有以下这些:

__init__(self, host='localhost', port=6379, db=0, password=None, socket_timeout=None, socket_connect_timeout=None, socket_keepalive=None, socket_ke
epalive_options=None, connection_pool=None, unix_socket_path=None, encoding='utf-8', encoding_errors='strict', charset=None, errors=None, decode_respon
ses=False, retry_on_timeout=False, ssl=False, ssl_keyfile=None, ssl_certfile=None, ssl_cert_reqs='required', ssl_ca_certs=None, max_connections=None)

我的数据库系列文章:

  • debian,ubuntu下安装MariaDB,并设置密码,修改端口,允许外网访问
  • python操作MariaDB
  • debian,ubuntu 安装mongodb 允许外网访问,修改端口,设置用户和密码
  • python操作mongodb进行读写
  • ubuntu, debian 安装redis,设置开机自动启动和密码,允许外网访问
  • redis设置主从复制-slave Replication–解决报错:(error) READONLY You can’t write against a read only slave.

ubuntu, debian 安装redis,设置开机自动启动和密码,允许外网访问相关推荐

  1. debian,ubuntu下安装MariaDB,并设置密码,修改端口,允许外网访问

    文章目录 安装MariaDB 设置密码 修改端口 允许远程访问 安装MariaDB MariaDB存在apt 的更新中,如果追求最新版,可以下载二进制文件进行编译安装,但普通人用没必要那么麻烦,直接装 ...

  2. 如何设置windows下xampp的phpMyAdmin外网访问?

    使用xampp安装完bugfree之后,很多学员反映,想要远程访问phpmyadmin并备份数据库,但是发现只有在部署的服务器上可以访问,远程访问的时候提示拒绝访问或者没有权限等问题,先做一下统一说明 ...

  3. debian,ubuntu 安装mongodb 允许外网访问,修改端口,设置用户和密码

    使用apt安装mongodb: apt update && apt install mongodb 查看运行状态: systemctl status mongodb.service 结 ...

  4. [MySql] - Windows MySql 8.x 手动zip包安装与外网访问登录权限设定

    MySql 8.x官方下载地址 https://dev.mysql.com/downloads/mysql/8.0.html https://cdn.mysql.com//Downloads/MySQ ...

  5. Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动

    Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动 >>>>>>>>>>>>>> ...

  6. Ubuntu添加和设置开机自动启动程序的方法

    Ubuntu添加和设置开机自动启动程序的方法 1.Ubuntu添加开机自动启动程序的方法ubuntu 1. 开机启动时自动运行程序 Linux加载后, 它将初始化硬件和设备驱动, 而后运行第一个进程i ...

  7. linux redis自动重启,Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动

    Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动 >>>>>>>>>>>>>> ...

  8. sysv-rc-conf --- Linux设置开机自动启动

    Linux设置自启动 sysv-rc-conf - Linux设置开机自动启动 CentOS7 开机自启动脚本 chkconfig方式 通过sysv-rc-conf命令设置 1.在/etc/init. ...

  9. ubuntu安装redis_在Ubuntu上安装Redis

    ubuntu安装redis Redis is key-value storage known for its flexibility, performance, and wide language s ...

最新文章

  1. 利用java多线程向MongoDB中批量插入静态文件
  2. WPF ValidationRule的特点(默认目标-源才校验)
  3. 阅读笔记一——java高并发的性能优化
  4. 团队开发--手机小游戏 需求分析
  5. linux 内核配置 dns,Linux的dns配置 - Linux操作系统基础进阶练习题_Linux教程_Linux公社-Linux系统门户网站...
  6. python find next_美化组4,findNext()函数
  7. Ajax获取数据的流程
  8. mininet在哪编写python脚本_1 mininet 简介及同时支持python2和python3
  9. 前端学习(2501):动态绑定样式
  10. 关于处理百万级大批量数据的mysql运行几个重要点
  11. Intellij idea 出现错误 error:java: 无效的源发行版: 11解决方法
  12. 面试:Zookeeper
  13. snipaste如何滚动截图_每天都在用的QQ截图,居然升级了这么多实用功能!
  14. python 网盘搭建_Python无所不能?五分钟教会你用python打造个人云盘!
  15. 序列的修改、散列和切片
  16. 一个极简的RePlugin
  17. C++、C#、Java、Python、可以获取L2行情实时数据吗?
  18. 时区,GMT时间,UTC时间,UNIX时间戳
  19. Android最火的框架系列(四)Volley
  20. Python 鸡兔同笼

热门文章

  1. 第二课.图卷积神经网络
  2. manifest文件
  3. drugbank下载XML文件解析
  4. Science:充满铵盐的环境依然发生固氮
  5. R语言ggplot2可视化将两个dataframe可视化的结果组合在一起实战:combining two plots from different data.frames
  6. R语言广义线性模型函数GLM、glm函数构建泊松回归模型、模型中存在过离散(Overdispersion)、则将连接函数从possion函数替换为quasipoisson函数重新构建泊松回归模型
  7. pandas计算滑动窗口中的中位数实战(Rolling Median of a Pandas Column):计算单数据列滑动窗口中的中位数、计算多数据列滑动窗口中的中位数
  8. R语言构建xgboost模型使用早停法训练模型(early stopping):自定义损失函数(目标函数,loss function)、评估函数(evaluation function)
  9. Python使用过滤器(filter)进行图像模糊处理
  10. R语言常用线性模型特征筛选(feature selection)技术实战:基于前列腺特异性抗原(PSA)数据