名下有多台VPS服务器放在不同的云供应商那里,定期备份服务器数据成了很棘手的问题。 习惯上会使用挂载nfs方式,使用s3fs-fuse先将S3的Bucket挂载到本机分区,然后向该分区写入需要备份的文件, 但是近期S3的接入稳定性确实很差,即使是AWS的老家美国,使用s3fs-fuse挂载的分区,也不能有比较稳定的读写。 碰到大量文件和持续读写的情况,效果非常不理想 近期发现使用 AWS Storage Gateway可以直接让虚拟机连接到iscsi的target,然后操作相应的LUN和卷。iscsi协议因为使用了比HTTP/S更低的TCP/IP协议,相对s3fs方式可以更稳定。 另外 AWS Storage Gateway的传入流量是免费的,只收取存储到S3,EBS的的存储费用。 服务器版本:Ubuntu18.04 LTS 设备目标:/dev/sdc 一、安装和配置iscsi发起端程序 1.安装open-scsi和utils #安装open-scsi和utils sudo apt-get install open-iscsi open-iscsi-utils 2.发现iscsi target #发现iscsi target sudo iscsiadm -m discovery -t sendtargets -p XXX.XXX.XXX.XXX:3260 3.登陆target #登陆target sudo iscsiadm -m node –targetname iqn.1997-05.com.amazon.XXXXXX -p XXX.XXX.XXX.XXX:3260 –login 二、挂载硬盘 1.发现并分区格式化磁盘 fdisk -l 2.分区格式化LUN fdisk /dev/sdc mkfs.ext4 /dev/sdc1 …
Category Archives: 零敲碎打
PostgreSQL使用PL/SQL和游标实现按日期批量执行
现有的DWH系统的是按天创建数据表的,使得定期维护变得麻烦,例如每个月底需要将按当月产生的临时表archive。 方式1.批量生成SQL,按固定的日期值生成一堆SQL,SQL生成方法多样。但是需要确认全部sql是否正确。 方式2.编写PL/SQL function,使用游标方式批量执行。 drop function fun_datecursor(from_date text,to_date text,cond text); create or replace function fun_datecursor(from_date text,to_date text,cond text) returns text as $ declare cur_date refcursor; buffer text := ”; var_day date; begin open cur_date for execute ‘SELECT generate_series(”’|| from_date ||”’::date,”’|| to_date ||”’::date,”’|| cond ||”’)’; loop –开始循环 fetch cur_date into var_day; –将游标指定的值赋值给变量 if found then ————————————— …
PostgreSQL创建ReadOnly只读用户
PostgreSQL可以通过schema和table级别对数据表进行只读控制 一般会使用PostgreSQL创建只读用户,然后给予相应的只读权限方式实现 通过使用 — 创建readonly_user用户,密码为readonly_password create user readonly_user with encrypted password ‘readonly_password’; — 设置readonly_user用户为只读事务 alter user readonly_user set default_transaction_read_only=on; — 授予usage权限给到readonly_user用户 grant usage on schema “public” to readonly_user; — 将默认”public”schema下新建表的读取权限授予给readonly_user alter default privileges in schema “public” grant select on tables to readonly_user; — 授予select权限给到readonly_user用户 grant select on all tables in schema “public” to readonly_user; grant …
[VBA]Base64编码和Base64解码
VBA实现Base64编码和Base64解码,用于处理加密的URL非常方便。 VBA Base64 编码/加密函数: ‘VBA Base64 编码/加密函数: Function Base64Encode(StrA As String) As String ‘Base64 编码 On Error GoTo over ‘排错 Dim buf() As Byte, length As Long, mods As Long Dim Str() As Byte Dim i, kk As Integer kk = Len(StrA) – 1 ReDim Str(kk) For i = 0 To kk Str(i) = Asc(Mid(StrA, …
Nginx HTTP站点使用301跳转HTTPS
方法一,使用Return方式,适用于全站HTTPS server_name www.lidaren.com lidaren.com; return 301 https://www.lidaren.com$request_uri; 方法二,rewirte方式转发特定目录,适用于子目录HTTPS化 location 使用 ·/· 根目录则全站跳转 location 使用 ·/XXX目录· 子目录则跳转指定子目录 location / { rewrite ^(.*) https://www.lidaren.com$1 permanent } 完整参考 server { listen 80; server_name www.lidaren.com lidaren.com; # 方法一,使用Return方式,适用于全站HTTPS return 301 https://www.lidaren.com$request_uri; # 方法二,rewirte方式转发特定目录,适用于子目录HTTPS化 # location 使用/根目录则全站跳转 # location / { # rewrite ^(.*) https://www.lidaren.com$1 permanent # } }
Python 代码方式生产中国身份证号码
Python 代码方式生产中国身份证号码 python做爬虫需要填写中国身份证号码,而且又各种验证规则,所以网上找了个靠谱的 import random, datetime def ident_generator(): #身份证号的前两位,省份代号 sheng = (’11’, ’12’, ’13’, ’14’, ’15’, ’21’, ’22’, ’23’, ’31’, ’32’, ’33’, ’34’, ’35’, ’36’, ’37’, ’41’, ’42’, ’43’, ’44’, ’45’, ’46’, ’50’, ’51’, ’52’, ’53’, ’54’, ’61’, ’62’, ’63’, ’64’, ’65’, ’66’) #随机选择距离今天在7000到25000的日期作为出生日期(没有特殊要求我就随便设置的,有特殊要求的此处可以完善下) birthdate = (datetime.date.today() – datetime.timedelta(days = random.randint(7000, 25000))) #拼接出身份证号的前17位(第3-第6位为市和区的代码,中国太大此处就偷懒了写了定值,有要求的可以做个随机来完善下;第15-第17位为出生的顺序码,随机在100到199中选择) ident = …
CentOS7 使用SystemD实现开机自启动和服务管理
CentOS7 可以在SystemD管理服务Service方式实现服务的自启动 SystemD即为System Daemon,是linux下的一种init软件,开发目标是提供 更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动, 同时达到降低Shell的系统开销的效果。 这里假设需要启动 # /usr/share/autostartup/foobar.sh STEP1.创建SystemD管理服务使用的.service文件 /usr/share/autostartup/foobar.service 以下是测试service文件,.service的具体编写,参考systemd相关文档 [Unit] Description=foobar Documentation=http://www.doc.com/doc.html After=network.target [Service] Type=simple WorkingDirectory=/home/foobar ExecStart=/usr/share/autostartup/foobar.sh ExecStop=/bin/kill -s QUIT $MAINPID Restart=always StandardOutput=syslog StandardError=syslog SyslogIdentifier=foobar User=foobar Group=foobar Environment= [Install] WantedBy=multi-user.target