password: 18 items found.

python中的*args 和 **kwargs

*args**kwargs 均为可变参数,方便记忆可以理解为 *args是列表形式的多个参数,不过它传值不是以list, 就是func(arg1, arg2, arg3...)
**kwargs可以理解为字典形式的多组key, value键值对,不过它传值也不是字典,而是func(a=1, b=2, c=3...)。

它们同时出现在func的定义中时,*args在前, **kwargs在后

**kwargs通常用在类的初始化多个配置项参数值传递。举一个pymongo的例子:

class MongoClient(common.BaseObject):
    def __init__(
            self,
            host=None,
            port=None,
            document_class=dict,
            tz_aware=None,
            connect=None,
            type_registry=None,
            **kwargs):
More ~

[python] 使用密码连接redis服务器 Connect redis with password

第一种方法:

rds = redis.StrictRedis(host='localhost', port=6379, password='123456')

第二种方法:

redis_config = {
        'host': os.getenv('REDIS_HOST', '127.0.0.1'),
        'port': os.getenv('REDIS_PORT', 6379),
        'password': os.getenv('REDIS_PWD', '123456')
    }
redis_uri = 'redis://:{password}@{host}:{port}/0'.format(**redis_config)
redis = Redis.from_url(redis_uri)
More ~

PyMongo使用密码连接Mongodb

以前的写法是这样的,

from pymongo import MongoClient
client = MongoClient(host='127.0.0.1')
db = client['dbname']
db.authenticate(user, password)

不过上面的已经废弃

warning:: Starting in MongoDB 3.6, calling :meth:authenticate
invalidates all existing cursors. It may also leave logical sessions
open on the server for up to 30 minutes until they time out.

More ~

为Ubuntu Server开启SSH

虚拟机安装的Ubuntu Server镜像,向导里需要设置用户账号,没有设置root密码.

1.登陆初始账号,修改root 密码
sudo passwd root

su切换root 试试

2.root 账号下修改配置文件
vi /etc/ssh/sshd_config
找到下面相关配置:

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

更改为:

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

3.重启ssh
sudo service ssh restart

More ~

First start ansible on macos

I installed the ansible via pip install, and there are several issues here:

where is the config

Here you should create a file ~/.ansible.cfg

[defaults]
inventory =~/.ansible/hosts
sudo_user=root
remote_port=22
host_key_checking=False
remote_user=root
log_path=~/.ansible/log/ansible.log
module_name=command
private_key_file=~/.ssh/id_rsa
More ~

rsync 用法

sync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。 rsync是一个功能非常强大的工具,其命令也有很多功能特色选项,我们下面就对它的选项一一进行分析说明。

rsync [OPTION]... SRC DEST
rsync [OPTION]... SRC [USER@]host:DEST
rsync [OPTION]... [USER@]HOST:SRC DEST
rsync [OPTION]... [USER@]HOST::SRC DEST
rsync [OPTION]... SRC [USER@]HOST::DEST
rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
More ~

Using mongodb service in docker-compose.yml

version: '3.1'

services:

  web:
    build: .
    restart: always
    ports:
      - 8080:80
    environment:      
      MONGODB_HOST: mongodb
      MONGODB_USER: root
      MONGODB_PWD: 123456
    depends_on:
      - mongodb

  mongodb:
    image: mongo:4.1
    restart: on-failure
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: 123456
    volumes:
      - ./data/mongo:/data/db
      - ./data/mongo-entrypoint/:/docker-entrypoint-initdb.d/

More ~