自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(75)
  • 资源 (1)
  • 收藏
  • 关注

原创 pycharm2020.1配置pipenv

image.pngbase interpreter:表示你用的python路径,可用which命令查找pipenv executable:表示你的pipenv路径,也可用which命令查找image.png最后点击add就完成添加了...

2021-04-06 10:54:06 642

原创 NTP集群时间统一

原理:NTP(Network Time Protocol,网络时间协议)是用来使计算机时间同步的一种协议。它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),切可介由加密确认的方式来防止恶意的协议攻击。端口:123(udp)安装(客户端和服务端都是ntp):# ubuntusudo apt install nt...

2021-02-26 16:06:38 666

原创 python 获取IP地址

思路是先获取网关,再拿到对应的IP信息,这样可以在没有公网是也能拿到地址:import netifacesdef get_host_ip(): try: gws = netifaces.gateways() net_name = gws['default'][netifaces.AF_INET][1] info = netifaces....

2020-10-14 10:23:15 718

原创 新ubuntu18.04系统,安装pyenv,python3.8

1.更换源文件vi /etc/apt/sources.listdeb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse...

2020-06-24 15:36:16 527

原创 ubuntu18.04没有网络开关,没网问题

如下操作:sudo service network-manager stopsudo rm /var/lib/NetworkManager/NetworkManager.statesudo service network-manager startsudo gedit /etc/NetworkManager/NetworkManager.conf把false改成truesudo s...

2020-06-11 16:21:55 1471

原创 ubuntu18.04 安装配置fish

1.安装fish拉取fish最新版本sudo apt-add-repository ppa:fish-shell/release-3sudo apt updatesudo apt install fish2.安装autojumpgit clone https://github.com/wting/autojump.gitcd autojump./install.py3. 配...

2020-05-21 17:53:12 751

原创 pycharm升级软件

1.配置导出:导出配置2.导入:安装pycharm第一步可以选择配置文件导入。3.设置快捷图标:进入/usr/share/applications,创建pycharm.desktop文件,写入[Desktop Entry]Type=ApplicationName=PycharmGenericName=Pycharm3Comment=Pycharm3...

2020-01-07 10:23:00 4066

原创 python2 assert判断字典的包含关系

python 2:在python2里,用assert判断一个字典是否是另一个字典的子集并不能直接用in, not in,只能用set的issubset比较方法:a = {'x': 1, 'y': 2, 'z': 3}b = {'x': 1}c = {'y': 2, 'd': 3}assert six.viewitems(b) in six.viewitems(a)#...

2019-12-02 18:06:09 2296

原创 ansible 连接错误

FAILED! => {"changed": false,"module_stderr": "Shared connection to 52.82.37.16 closed.\r\n","module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n","msg": "MODULE FAILURE","rc": 127}...

2019-11-13 10:15:36 3578

原创 ubuntu下python paramiko实现docker容器ssh连接宿主机

背景:由于slurm的server和client的版本只兼容相差一个版本,导致宿主机跟docker容器始终存在版本兼容的问题,现在的设计是,由docker容器执行slurm的时候直接利用ssh连接宿主机,从而让两个环境slurm始终保持一致。一、宿主机的准备工作1.生成ssh的公钥和私钥ssh-keygen -t rsa一路回车下去,不用设置密码,最后生成的公钥私钥在~/...

2019-10-24 16:14:04 1482

原创 python 实现多线程并返回函数返回值的三种方法

方法一:使用threading在threading中,并没有实现返回值的方法,我们可以用数据库或者是全局变量来实现返回值的获取。这里使用的是全局变量。def thread_function(age): for i in age: i += 1 q.put( { 'age': i ...

2019-10-12 18:21:33 22126 6

原创 python paramiko模块

1.介绍:ssh是一个协议,OpenSSH是其中一个开源实现,paramiko是Python的一个库,实现了SSHv2协议(底层使用cryptography)。有了Paramiko以后,我们就可以在Python代码中直接使用SSH协议对远程服务器执行操作,而不是通过ssh命令对远程服务器进行操作。由于paramiko属于第三方库,所以需要使用如下命令先行安装:pip ins...

2019-10-11 16:44:15 282

原创 python datetime 与字符串的相互转化

1. 如何将字符串的格式转换为datetime格式呢?可以利用dateutil这个库:import dateutilt1 = dateutil.parser.parse("2019-02-24T19:36:20-05:00")print type(t1)print 't1: ', t1<type 'datetime.datetime'&...

2019-07-11 12:11:00 662

原创 python 字典value实现+=操作

通常我们都会需要去实现一个值为int或float的字典,还要实现-=,+=,有没有更加简便的方法呢?答案是:肯定有啊!!!那就是使用defaultdict:from collections import defaultdictfoo = defaultdict(int)foo['count'] += 1在Python> = 2.7中,您...

2019-07-11 11:53:00 4001

原创 linux挂载文件系统,mount,/etc/fstab

情景介绍:在aws的ec2下attach一个ebs卷,现在需要把ebs卷挂载到ec2下。 ssh登陆 df -h 看看磁盘情况 很好,只有默认的8g的卷,但是看不到我们挂载的ebs卷。 lsblk查看存储情况 可算找到了啊,在最后,不过名字被改了,无所谓,但是这个卷没有mountpoint,这个MOUNTPOINT你可以理解为EC2实例上...

2019-05-24 16:01:00 1530

原创 关于boto3中run_instances和volume的问题

问题1:run_instances的一些问题这是一个boto3的run_instances()的请求,用来申请一台ec2。import base64import boto3client = boto3.client('ec2')# a 是一个shell脚本,使用api不需要base64。a = """#!/bin/bash touch /...

2019-05-24 11:50:00 348

原创 python2自定义异常retry模块(装饰器版)

现在要求做一个重试逻辑,由于考虑到要做成docker镜像,减少依赖,于是自己写了一个异常重试的逻辑,代码如下:import timeimport logging# logger模块logger = logging.getLogger('fastone.cwl-runner')logger.setLevel(level=logging.INFO)formatter = logging...

2019-05-10 11:07:00 1037

转载 【转】LINUX常用命令

防火墙查看防火墙状态systemctl status iptables (或service iptables status)关闭防火墙systemctl stop iptables(或service iptables stop)系统信息curl ifconfig.me 查找本机公网IParch 显示机器的处理器架构(1)uname -m 显示机器的处理器架构(2)uname...

2019-04-15 14:51:00 86

原创 python argparse 解析yaml文件

运用场景给原本的service-client项目添加一个本地运行版本。这里就用到了python的argparse了。argparse是一个处理命令行参数的库,默认是sys.argv[1],详情点这里。这篇文章只给出在项目中用到的模块:1.parser # parser parser = argparse.ArgumentParser() cluster_i...

2019-04-14 23:43:00 3634

原创 docker设置多个环境变量

在命令行直接使用-e或–env,–env-file2.在dockerfile里设置这里键值是以空格分开的

2019-03-29 17:55:01 26472

原创 flask自动生成swagger的api接口文档

生成接口文档一直是一件麻烦的事,这里想自动化生成swagger的接口文档,所以用了一个框架:Flask-RESTPlus链接里有安装教程。结合yaml版本会更容易理解: yaml版本传送门本文依旧是以代码+效果图的方式表现:from flask_restplus import Api, Resource, fieldsapp = Flask(__name__) api = Api(...

2019-03-27 17:36:10 21252 2

原创 用swagger生成api的接口文档(yaml版)

swagger的文档可以用json和yaml写,这里我用的yaml写的,会以文档+效果图表现出来:swagger: "2.0" info: description: "this is a api for authenticating users and binding cloud accounts." version: "1.0.0" title: "Auth api" ho...

2019-03-27 16:29:38 52347 4

原创 python readwritelock读写锁的实现

1.场景: 现在要读取和写入s3上的文件,为避免读写不一致,须实现一个读写锁,要求如下: 写优先,如果有线程写入,读线程等待。2.实现方法:利用python自带的threading库中的threading.Condition()方法,再结合一个计数器。3. 代码及测试如下:import threadingclass MyReadWriteLock(object): &quot;&quot;...

2019-03-18 17:14:13 1380

原创 python grpc+jwt+s3 对用户token进行验证

写在前面:用户信息是存储在aws的s3上,现在要做到用户登陆创建新token,访问api,验证token。目录结构:1.grpc部分:第一步,序列化,规定api方法及参数等。。syntax = "proto3";package authsvc; """In Python, the package directive is ignored, since Python mod...

2019-02-27 17:42:08 1336

原创 python grpc注意事项

记录几个在使用grpc时遇到的问题:1. 在.proto文件使用enum时,遇到0无法字符串序列化的问题,表现为:返回 VALID可以,INVALID没有返回值。修改如下:2. 报错context.set_code(grpc.StatusCode.INVALID_ARGUMENT)context.set_...

2019-02-19 14:33:00 1375

原创 ubuntu16.04 卸载mysql,重新安装

卸载mysql:1. sudo apt-get autoremove --purge mysql-server-5.7 2. sudo apt-get remove mysql-common3. sudo rm -rf /etc/mysql/ /var/lib/mysql 4. dpkg -l |grep ^rc|awk '{print $2}'...

2019-02-14 09:57:00 610

原创 Ubuntu 和 pycharm下设置环境变量

场景:由于pycharm需要模拟项目在docker容器中运行,现在需要给项目提供环境变量,并判断其类型。我的第一反应是,给ubuntu设置环境变量:给root设置环境变量:vim /etc/environment# 写入环境变量PARENT=8#更新source /etc/environment在root用户下是可以得到结果的:ec...

2019-01-24 16:41:00 4257

原创 dockerfile实例

docker build steps编辑dockerfile文件由于本次镜像的有些依赖自己也有依赖,为了保持镜像的精简性,这里采用分步制作,所谓分步,就是把依赖在第一个镜像内编译完成之后,复制给第二个镜像,这样第二个镜像内就不会有编译工具等不需要的东西了。编辑dockerfile # first step FROM python:2.7-alpine as builder ...

2019-01-24 15:44:00 404

原创 Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

docker本地默认是unix socket,这里报错是使用了tcp,默认情况下,Unix的socket属于用户root,其它用户要使用要通过sudo命令。由于这个原因,docker daemon通常使用root用户运行,使用了几种解决方式。一丶未成功的(万一你们成了呢 #滑稽):编辑/etc/docker/daemon.json 无效{ ...

2019-01-14 16:45:00 10183 1

原创 编写dockerfile制作docker镜像

在制作之前,请先看一下docker的基础知识,这样会更深入的理解整个制作过程,附上链接:Docker Dockerfile 定制镜像1. 添加Dockerfile文件找到你项目的根目录,新建一个Dockerfile文件,这个文件是在docker build时运行的step,一般分成两步,一步配置镜像默认环境与依赖,第二步添加本地文件到远程,如果已经把...

2018-12-07 18:05:00 349

原创 prometheus的collect的使用

之前写的export由于要改进代码,稍作了修改,出现了几个小问题,记录一下。之前的代码全写在collect中,因为是获取单个节点的信息,现在要获取多个节点的信息,所以考虑了多个封装函数:class CustomCollector(object): def collect(self): # 执行scontrol,获取nodes信...

2018-12-07 11:24:00 1278

转载 关于AWS网络的一切

你应该知道的网络的一部分如果您在AWS上运行基础架构和应用程序,那么您将遇到所有这些事情。它们不是网络设置的唯一部分,但根据我的经验,它们是最重要的部分。VPC虚拟私有云(VPC)是一个专用网络空间,您可以在其中运行基础架构。它有一个你选择的地址空间(CIDR范围),例如10.0.0.0/16。这决定了您可以在VPC中分配的IP地址数量。您在VPC内创建的每个服务器都需要一个IP地址,因此...

2018-11-30 16:10:00 893

原创 几个小问题:判断字典的键值是否存在,排序sort,six,U开头的字符串怎么转码

1. 判断字典的键值是否存在:1. has_key()a = {'a' : 1}print a.has_key('a'):#####True2. ina = {'a': 1}print 'b' in a#####False2. 排序sortdemo = {'c': [('a', 20), ('b', 40)], 'd': [...

2018-11-20 09:57:00 156

转载 [转]竞价实例与AWS SPOT逆向解析

竞价实例与AWS SPOT逆向解析李力李力腾讯云的老程序员,招聘各类技术职位作者是我的同事alexmwang,已经获得授权竞价实例是什么 —— what用户视角的竞价实例AWS竞价实例,即AWS EC2 SPOT instance 用户在竞价型实例请求中指定愿意支付的最高出价。 如果竞价型实例价格不高于用户的出价,则用户实例可以运行,且按照竞价型...

2018-11-16 11:15:00 1012

原创 list()原理

今天看到个好玩的东西:a = (x for x in range(10))print aprint list(a)&lt;generator object &lt;genexpr&gt; at 0x7f0f46055f00&gt;[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]a 是一个生成器,很明显,但是用list(a)之后...

2018-11-13 17:50:00 238

原创 闭包中的nonlocal和global以及不使用nonlocal实现其功能

effective-python中,在阐述作用域变量时提到了nonlocal和global,当提到python2没有nonlocal时,实现了其功能,这例子没读懂:# Python2def sort_priority(values, group): found = [False] def helper(x): if x ...

2018-11-01 12:11:00 326

原创 理解sort()函数中的key

最近在看effective-python,第二章函数中提到了优先排序的概念,具体代码如下:values = [1, 5, 3, 9, 7, 4, 2, 8, 6]group = [7, 9]def sort_priority(values, group): def helper(x): if x in group: ...

2018-10-31 16:55:00 1743

原创 pyenv下python依赖的路径和打包项目

写在前面:要保证任何python环境都能运行项目,需求就是把该项目的所有依赖都提取出来。现在有两种方法。1. 使用工具一个很好用的打包工具:pyinstaller1.1 直接pip install pyinstaller1.2 用法:很简单,cd到目标项目的.py目录下,运行pyinstaller -F file.py -F:表示...

2018-10-30 16:49:00 1282

原创 python自定义监控slurm的Prometheus的export

首先:这篇文章做的是写一个监控slurm的Prometheus的export,安装环境是ubuntu16.04。1. 下载Prometheus官网链接下载,然后解压tar -zxvf prometheus-2.4.3.linux-amd64.tar.gzcd prometheus-2.4.3.linux-amd642. 配置文件prometh...

2018-10-29 13:26:00 849

原创 Ubuntu16.04安装Slurm

1. 安装MUNGE安装MUNGE进行身份验证。确保集群中的所有节点具有相同的munge.key。确保Munge的守护程序munged在Slurm的守护进程之前启动。(由于我是在本地测试的,就没有设置多个节点,需要同步的可通过scp同步)sudo apt-get install munge # 安装mungesudo /usr/sbin/creat...

2018-10-23 11:30:00 2982

算法导论_ver3.pdf

This section will lead readers to start thinking about the design and analysis of algorithms, briefly introducing the expression of algorithms, some of the design strategies to be used in this book, and many of the basic ideas used in algorithm analysis. The rest of this book is based on this basic knowledge.Chapter 1 is an overview of algorithms and their place in modern computing systems. This chapter gives the definition of algorithm and some examples of algorithm. In addition, this chapter demonstrates that algorithms are a technology, as are fast hardware, graphical user interfaces, object-oriented systems, and networks.In chapter 2, we present the first algorithms in the book, which solve the problem of sorting n Numbers. These algorithms are presented in a form of pseudocode that, although not directly translated into any regular programming language, expresses the structure of the algorithm clearly enough for any competent programmer to implement the algorithm in the language of his choice. The sorting algorithm we analyzed is insertion sort, which takes an incremental approach;It also analyzes merge sort, which USES a recursive technique called divide-and-conquer. Although the running time required by both algorithms increases with the value of n, the rate of increase is different. In chapter 2, we analyze the running time of these two algorithms and give a useful representation to express these running times.Chapter 3 gives an exact definition of this representation, called asymptotic representation. At the beginning of chapter 3, several asymptotic symbols are defined, which are mainly used to represent the upper and lower bounds of algorithm running time. The rest of chapter 3 mainly presents some mathematical representation methods. The purpose of this section is more to ensure that the reader's notation matches the book's notation system than to teach it

2019-04-12

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除