Archive

Author Archive

Tensorboard几个使用技巧

April 1st, 2020 No comments

1.Tensorboard需要对比多个Training的数据
常规的做法现实单次训练的数据,–logdir=path

tensorboard --logdir=path

多个Training的数据对比,则需要规定各个run的名称

tensorboard --logdir=run1:“path1",run2:“path2",run3:“path3"

2.Tensorboard强制使用CPU
GPU被占满的时候,只能使用CPU来渲染Tensorboard的数据,具体做法是在启动命令前增加CUDA_VISIBLE_DEVICES=“”

CUDA_VISIBLE_DEVICES=“" tensorboard --logdir=path

3.Tensorboard提示No dashboards are active for the current data
一般发生在Tensorboard切换版本后,–logdir=后面不要接带单引号的路径,如果路径包含空格,转意或使用双引号

# 错误
tensorboard —logdir=‘path'
# 正确
tensorboard --logdir=path

tensorboard完整的命令参数

usage: tensorboard [-h] [--helpfull] [--logdir PATH] [--host ADDR]
                   [--port PORT] [--purge_orphaned_data BOOL]
                   [--reload_interval SECONDS] [--db URI] [--db_import]
                   [--db_import_use_op] [--inspect] [--version_tb] [--tag TAG]
                   [--event_file PATH] [--path_prefix PATH]
                   [--window_title TEXT] [--max_reload_threads COUNT]
                   [--reload_task TYPE]
                   [--samples_per_plugin SAMPLES_PER_PLUGIN]
                   [--debugger_data_server_grpc_port PORT]
                   [--debugger_port PORT] [--master_tpu_unsecure_channel ADDR]
Categories: 语言编程 Tags:

[WP] 升级WordPress5.x以后Nginx伪静态设置

April 1st, 2020 No comments

[WP] 升级Wordpress 5.x以后Nginx伪静态设置

升级Wordpress 5.x 以前,Nginx的伪静态设置方法。

location / {
if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
        }
if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
        }
if (!-f $request_filename){
                rewrite (.*) /index.php;
        }
}

WordPress 5.x 以后,Nginx的伪静态设置方法,
当然,nginx本身是提供向前兼容的,使用哪种方式按需设置即可。

location / {
	try_files $uri $uri/ /index.php?$args;
}
 
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

对于wp-admin的伪静态设置, WordPress 无论是否升级 5.x都是一样的。

  if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php) $2 last;
  }

官方文档地址

Nginx

Categories: 博客技巧, 系统管理 Tags:

[Ubuntu]使用open-iscsi发起iscsi连接Target

January 19th, 2020 No comments

名下有多台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

3.挂载到指定

sudo mkdir /mnt/backup
sudo mount /dev/sdc1 /mnt/backup

4.卸载硬盘

sudo unmount /mnt/backup

三、开机自动连接到LUN,挂载硬盘

1.开机自动登陆target
修改/etc/iscsi/iscsid.conf,开启自动登陆到Gateway

vi /etc/iscsi/iscsid.conf
#自动开启
node.startup = automatic

2.修改/etc/fstab,实现开机自动挂载

#获取文件系统的UUID
tune2fs -l

修改/etc/fstab,实现开机自动挂载

#修改/etc/fstab
sudo vi /etc/fstab

#在/etc/fstab中添加

UUID=6dba31ff-xxxx-4430-bbd2-c1a932a53308 /backup ext4 _netdev 0 0

几个需要注意的地方:
1.如果跟AWS Storage Gateway连接期间发生未知中断,可以试试强制刷新设备

udevadm test /sys/block/sdc

2.如果发生连接超时的情况,通常跟网络质量有关,AWS推荐可以修改iscsid.conf

vi /etc/iscsi/iscsid.conf
# 修改连接超时参数
node.session.timeo.replacement_timeout = 600 
node.conn[0].timeo.noop_out_interval = 60
node.conn[0].timeo.noop_out_timeout = 600

参考
https://docs.aws.amazon.com/storagegateway/latest/userguide/initiator-connection-common.html#CustomizeLinuxiSCSISettings

Categories: 系统管理, 零敲碎打 Tags:

[Powershell]查找文件系统中的长文件名文件

January 19th, 2020 No comments

查找文件系统中的长文件名文件
向OOS等对象存储转移数据的时候,因为文件系统兼容性的问题,最好处理掉那些文件名长度大于255的文件,以免出现转移失败的情况

Windows下可以使用Powershell的Get-ChildItem命令方式

Get-ChildItem -r * # 获取文件夹下所有对象
{$_.GetType().Name -match”File” } #获取文件类型的名称
{$_.fullname.length -ge 256} # 文件名长度大于等于256的文件
%{$_.fullname} #打印文件名

Get-ChildItem -r * |? {$_.GetType().Name -match"File" } |? {$_.fullname.length -ge 256} |%{$_.fullname}

linux直接利用 length属性即可

find. -type f | awk 'length> 255'> longfilename-list.txt

附各文件系统的最大文件名长度

文件系统 最大文件名长度 最大文件大小 最大分区大小
ext2 255 bytes 2 TB 16 TB
ext3 255 bytes 2 TB 16 TB
ext4 255 bytes 16 TB 1 EB
XFS 255 bytes 8 EB 8 EB
Btrfs 255 bytes 16 EB 16 EB

参考
https://stackoverflow.com/q/12697259/614863
https://www.helplib.com/diannao/article_172660
https://blog.csdn.net/baixiaokanglili/article/details/78804991

Categories: 系统管理 Tags: ,

[BATCH]批处理中enabledelayedexpansion启动变量延迟

January 19th, 2020 No comments

一个简单的需求,批量定义变量并运算赋值,再对获取变量计算的结果值

方法:
1.使用SET /A 方式暂存表达式的中间计算结果
2.使用setlocal enabledelayedexpansion 避免解释器在循环体中实时展开变量
3.使用&合并表达式为1行
启用setlocal enabledelayedexpansion。启动变量延迟

@echo on
set var4="test"
for /l %%i in (1,1,3) do set var%%i=%%i
echo %var1%
echo %var2%
echo %var3%
echo %var4%
setlocal enabledelayedexpansion
for /l %%j in (1,1,3) do ( set /a t= var%%j & echo !t! )
for /l %%j in (1,1,3) do (
set /a t= var%%j 
echo !t!
)
endlocal

pause
输出
1
2
3
4

关闭enabledelayedexpansion
输出
4
4
4
4

关于setlocal和enabledelayedexpansion
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc772046(v=ws.11)?redirectedfrom=MSDN

Categories: 系统管理 Tags: ,

nohup 后台运行python程序print无输出

July 26th, 2019 No comments

使用nohup后台运行python,print没有输出到日志

nohup python foobar.py > foobar.log 2>&1 &

发现foobar.log中显示不出来python程序中print的东西。
这是因为python的输出有缓冲,导致foobar.log并不能够马上看到输出。
python 有个-u参数,使得python不启用缓冲。

nohup python -u foobar.py > foobar.log 2>&1 &

其他玩法:
只输出错误到日志
# Only error write to log
nohup python -u ./foobar.py> /dev/null 2>foobar.log &
不输出到日志
# Nothing to Display
nohup python -u ./foobar.py> /dev/null 2>&1 &
全部print输出到日志
# Write all to log
nohup python -u ./foobar.py> ./foobar.log 2>&1 &

https://blog.csdn.net/Statham_stone/article/details/78290813

Categories: 系统管理 Tags:

[Python]PostgreSQL字典/JSON类型递归自展开

July 15th, 2019 No comments

PostgreSql 习惯上会将特殊数据类型的各个节点按字典/JSON类型存储
程序中需要获得完整的数据信息的时候,需要对这个节点进行自展开。

以下使用global id方式进行展开,一般适用于SQL+NoSQL结合的系统使用

import sys, os
import numpy as np
 
def get_object_by_gid(id):
	for dict in data["json"]:
		if dict["gid"] == id:
	return dict.copy()
 
def self_exact_node(key):
	dict = get_object_by_gid(key)
	for k,v in dict.items():
		if k == "sub_item" :
			item_arr = []
			for id in v["gids"]:
				item_arr.append(self_exact_node(id))
			v["item_arr"] = item_arr.copy()
	return dict
 
def demo():
	data_exact = data.copy()
	for d in data_exact["json"]:
		d = self_exact_node(d["gid"])
 
def main():
	demo()
 
if __name__ == '__main__’:
	sys.exit(main())

其他玩法

# Global ID方式
"gid": "大分类2:中分类2:子分类2",
# 复合ID
"id":{"l1_cat":"大分类1","l2_cat":"中分类2","l3_cat":"子分类2"}
# 链表式
"chain":{"next_gid":"","pre_gid":"","head_gid":"","tail_gid":""}
# 二叉树式
"btree":{"next_sibling":"","child":”"}

Read more…

Categories: 语言编程 Tags: , , ,