Archive

Archive for the ‘系统管理’ Category

[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 Error ‘TSaslClientTransport’ object has no attribute ‘trans’

November 12th, 2018 No comments

解决Python Error ‘TSaslClientTransport’ object has no attribute ‘trans’
原因应该是thrift和impyla包版本的问题

sudo pip uninstall thrift
sudo pip uninstall impyla
sudo pip install thrift==0.9.3
sudo pip install impyla==0.13.8

参考
http://community.cloudera.com/t5/Interactive-Short-cycle-SQL/Python-Error-TSaslClientTransport-object-has-no-attribute/m-p/58033

Categories: 系统管理 Tags: ,

RQAlpha Docker容器化Dockerfile

November 12th, 2018 No comments

最近需要使用RQAlpha进行国内的量化分析工作,并对RQAlpha进行了容器化处理,
方便使用docker和ks进行容器化管理

1.基于 jupyter/minimal-notebook jupyter的官方镜像,默认使用python3
2.使用Anaconda的mini-conda进行环境管理,可以自由切换python27和python3运行环境
3.使用pip安装了其他非conda管理的包内容

pip install bs4 cx-Oracle docopt future hdfs pyecharts PyMySQL raven typing lxml

4.使用编译方式安装了TA-lib,暂时为32bit版本,安装了国内流行的tushare

pip install tushare TA-lib

5.将matplotlib.pyplot自动导入,同时配合安装了国内流行的pyechart
6.安装了HDFS,cx-Oracle,PyMySQL等常用的数据连接包

可以在以下位置找到
https://github.com/limccn/rqalpha/tree/master/docker

Read more…

Categories: 系统管理 Tags: ,

RQAlpha BUG Issue#219

November 12th, 2018 No comments

Pingback https://github.com/ricequant/rqalpha/issues/219

Hello, RQAlpha Team

RQAlpha is really a effective tool for price back-testing.

I found something wrong when using command `# rqalpha plot someresult.pkl` to plot my back-testing result. It came out a blank window. I tried to solve this problem and found something interesting.

in `rqalpha/rqalpha/mod/rqalpha_mod_sys_analyser/plot.py`, line 52-53

 portfolio = result_dict["portfolio"]
 benchmark_portfolio = result_dict.get("benchmark_portfolio")

 print portfolio.index
 print benchmark_portfolio.index

by printing portfolio.index and benchmark_portfolio.index , I found an unreasonable difference.

![image](https://user-images.githubusercontent.com/4476941/33165321-59a13c02-d071-11e7-80e1-b41a5fbdd6db.png)

According to https://github.com/pandas-dev/pandas/issues/8614 says, matplotlib can not plotting when DatetimeIndex is created by pandas > 0.15 .

I found a temporary way to solve this problem. and finally plotting was working functionally.

Use `index.to_pydatetime()` to explicitly convert `DatetimeIndex` type index to Python `Datetime` type.

For example: modify `rqalpha/rqalpha/mod/rqalpha_mod_sys_analyser/plot.py`, line 152
`ax.plot(portfolio[“unit_net_value”] – 1.0, label=_(u”strategy”), alpha=1, linewidth=2, color=red)`
to
`ax.plot(index.to_pydatetime(),portfolio[“unit_net_value”] – 1.0, label=_(u”strategy”), alpha=1, linewidth=2, color=red)`

Although it is not the best way to solve this problem, I know you can find the best one finally.
And I hope these information may help you.

Thanks.

Categories: 算法研究, 系统管理 Tags: