Archive

Archive for the ‘系统管理’ Category

PostgreSQL查询表和index占用空间大小

November 12th, 2018 No comments

PostgreSQL查询表和index占用空间大小

PostgreSQL表和index占用空间大小信息存储在
information_schema.tables中
通过SQL可以查询到相应的统计数据

--查出单个表的大小
SELECT pg_size_pretty(pg_relation_size('TABLENAME'));

查出表大小按大小含Index

-- 查出表大小按大小含Index
SELECT
"table_name",
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size
FROM (
SELECT
TABLE_NAME,
SUBSTRING("table_name",1,10) AS short_name,
pg_table_size(TABLE_NAME) AS table_size,
pg_indexes_size(TABLE_NAME) AS indexes_size,
pg_total_relation_size(TABLE_NAME) AS total_size
FROM (
SELECT ('"' || table_schema || '"."' || TABLE_NAME || '"') AS TABLE_NAME
FROM information_schema.tables
) AS all_tables
WHERE all_tables.table_name LIKE '%TABLENAME%'
ORDER BY total_size DESC
) AS pretty_sizes

Read more…

Nginx HTTP站点使用301跳转HTTPS

November 12th, 2018 No comments

方法一,使用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
#    }
}
Categories: 系统管理, 零敲碎打 Tags:

npm中Error: could not get uid/gid问题的解决方法

November 9th, 2018 No comments

在Docker中运行npm出现Error: could not get uid/gid的问题

但是通过设置`unsafe-perm true` 可以解决这个问题,不可思议。

npm config set unsafe-perm true

其他可以用的npm配置
# 关闭安全证书检查

npm config set unsafe-perm true

# 关闭强制SSL

npm config set strict-ssl false

# 更改npm源

npm config set registry https://registry.npm.taobao.org

#设置代理

# socks5 proxy
npm config set proxy http://xx@xx.com:xxxx 
# http proxy
npm config set https-proxy=http://xx@xx.com:xxxx

参考
http://www.cnblogs.com/liyongjian5179/p/9884944.html

Categories: 系统管理 Tags: ,

Linux使用sed命令对进行文件行操作

November 9th, 2018 No comments

1、删除文档的第一行
sed -i ‘1d’
2、删除文档的最后一行
sed -i ‘$d’
3、在文档指定行中增加一行
例如文档如下:
echo “1”;
echo “2”;
echo “4”;
echo “5”;
想要在echo “2”;后面加上一条echo “3”;可以用如下命令
sed -i ‘/echo “2”;/aecho “3”;’
之所以用分号,是因为文本中本来就有。也就是说分号不是必须的!
抽象出来就是: sed -i ‘/* /a*’
4、删除文件中的一行
sed -i ‘3d’
5、删除文件中包含某个关键字开头的所有行
sed -i ‘/^QWQ/d’
6、删除文件中包含某个关键字的所有行
sed -i ‘/QWQ/d’

Categories: 系统管理 Tags: ,

RQAlpha安装 ta-lib进行技术指标分析

November 9th, 2018 No comments

RQAlpha安装 ta-lib进行技术指标分析
RQAlpha安装时需要事先安装ta-lib否则Python引用时会出现错误

STEP1.使用 ta-lib 的源代码编译 ta-lib 的静态库

wget https://jaist.dl.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
tar xf ta-lib-0.4.0-src.tar.gz 
cd ta-lib
# 安装到/usr
./configure --prefix=/usr
make
sudo make install

注意这里需要指定安装位置,编译安装的ta-lib是32位版本,
如果不指定的话在64位操作系统下是无法在lib和/usr/lib下找到的

STEP2.使用pip安装ta-lib

pip install TA-Lib

参考
https://stackoverflow.com/questions/41155985/python-ta-lib-install-problems

CentOS7 使用SystemD实现开机自启动和服务管理

November 9th, 2018 No comments

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

Read more…

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

CentOS6 使用rc.local实现开机自启动

November 9th, 2018 No comments

CentOS6 可以在rc.local中增加启动shell脚本实现开启自启动

这里假设需要启动

/usr/share/autostartup/demo-service.sh

STEP1. 将需要开启启动的脚本设置为标记为可执行文件

chmod +x /usr/share/autostartup/demo-service.sh

STEP2. 执行如下命令将/etc/rc.d/rc.local文件标记为可执行文件

chmod +x /etc/rc.d/rc.local

在CentOS7 中,/etc/rc.d/rc.local文件的权限被降低了,开机的时候执行在自己的脚本是不能起动一些服务的。

将需要执行的脚本写入到 /etc/rc.d/rc.local

echo/usr/share/autostartup/demo-service.sh” >> /etc/rc.d/rc.local
Categories: 系统管理, 零敲碎打 Tags: ,