go mod init # 初始化go.mod
go mod tidy # 更新依赖文件
go mod download # 下载依赖文件
go mod vendor # 将依赖转移至本地的vendor文件
go mod edit # 手动修改依赖文件
go mod graph # 打印依赖图
go mod verify # 校验依赖
作者:lzg
查看某个后台进程的输出内容
在后台执行PHP的脚本时,若想看进程输出内容(如脚本中的echo信息),可执行以下命令查看
1 |
strace -p {pid} -ewrite |
其中,pid是进程的pid值,可以通过ps aux|grep ‘进程名’查看。
Elasticsearch常用命令
- 查看mapping:
1curl -XGET '127.0.0.1:9200/【your-index】/_mapping' - 为现有mapping添加新属性:
123//给tags添加 age 属性:curl -X PUT 'http://127.0.0。1:9200/【your-index】/_mapping/【your-type-if-exists】' -H 'content-type:application/json' -d '{"properties":{"tags":{"type":"object","properties":{"age":{"type":"long"}}}}}'
3. 迁移旧index的数据到新index:
1curl -X POST 'http://127.0.0.1:9200/_reindex' -H 'content-type:application/json' -d '{"source":{"index":"【your-old-index】"},"dest":{"index":"【your-new-index】"}}'
4. 删除index:
1curl -X DELETE 'http://127.0.0.1:9200/【your-index】'
Elasticsearch学习笔记
1. 新增加某种字段时,需要先更新mapping信息(相当于SQL中的变更表结构)。
执行方式有,
1.1 通过PUT请求动态添加新的字段;
1.2 使用新的mapping信息,新建索引(index),再通过POST请求使用_reindex来迁移旧数据;
1.3 动态添加新字段时,如果报错(Limit of total fields [1000] in index … has been exceeded),可能是有脏数据不支持的缘故,此时重建索引(index),再迁移数据(_reindex)即可。
2. Elasticsearch 仅7.0之前的版本支持在索引(index)下建 type .
(如果把index比作 sql中的database,则 type 类比sql中的table),
原因是,在sql中,不同表里可以用相同的字段名(即使只是同名,存储内容可以不同),但在Elasticsearch中,同一字段表示同一内容,即使是在不同的type中。所以被认为比较鸡肋,在7.0版本后彻底放弃了。
【参考】
tasker进入后台后不正常工作
背景:
小米手机,安装了tasker软件,设置收到某特定号码来电时,触发一些任务(如打开某应用)。
最初tasker在前台运行时,能正常使用,触发任务后,tasker自动进入后台运行,此时再触发条件也不能执行任务了。
处理:
权限问题,给tasker【锁屏显示】、【后台弹出界面】、【显示悬浮窗】、【常驻通知】等权限,并加【后台运行锁】(多任务界面,给应用加锁)即可。
docker笔记
# 查看所有容器
docker ps -a
# 查看所有镜像
docker images
# 删除指定容器
docker rm [container_id|container_name]
docker rm $(docker ps -a -q)
# 删除指定镜像
docker rmi [image_id]
docker rmi $(docker images -q)
# 创建&运行容器
docker run –rm -i -t -p 8080:80 -v /tmp/web:/var/www/html -d ubuntu:latest bash
Dockerfile:
1 2 3 4 5 6 7 8 9 10 |
FROM ubuntu:16.04 LABEL maintainer="YourName <your@email>" RUN apt-get update && apt-get install nginx -y \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ && echo "daemon off;" >> /etc/nginx/nginx.conf CMD ["nginx"] |
根据Dockerfile文件创建镜像:
docker build -t yourname/nginx:0.1.2 .
ldap实现域账号统一认证服务
supervisor的安装与配置
安装与配置:https://www.jianshu.com/p/669ff9c19f14
group配置的使用:https://www.cnblogs.com/zhaoyingjie/p/13392938.html
php实现doc转pdf
软件:https://www.libreoffice.org/
安装完后,创建软连接: ln -s path/to/soffice /usr/local/bin/soffice
转换命令:
1 |
/usr/local/bin/soffice --headless --convert-to pdf ["path/to/source.doc(x)"] --outdir "/tmp" |
PS,如果报错,尝试以下步骤:
1.安装需要的扩展, yum install libXinerama.x86_64 (可以先 yum search libXinerama 看有哪些)
【参考:https://superuser.com/questions/688871/error-while-loading-shared-libraries-libxinerama-so-1-cannot-open-shared-objec】
2.安装java环境:
1 2 3 |
yum install java-1.8.0-openjdk-devel yum install java-1.8.0-openjdk |
【参考:https://phoenixnap.com/kb/install-java-on-centos】
3.若执行转换命令发现有中文乱码,安装字体,并重启机器:
1 |
yum groupinstall "fonts" |
将 /etc/locale.conf 内容改为 LANG="zh_CN.UTF-8" ,然后reboot重启。
【参考:https://blog.csdn.net/xujingcheng123/article/details/84643021】
附php参考代码:(带超时设置)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/** * 将文件转换成pdf格式 * @param $source * @param $desti * @param string $bin * @throws * @return string */ public static function convert2Pdf($source, $desti, $bin = "/usr/local/bin/soffice"){ @exec("timeout 3 {$bin} --headless --convert-to pdf --outdir {$desti} {$source} > /dev/null"); $pathInfo = pathinfo($source); $destiFilePath = $desti."/{$pathInfo['filename']}.pdf"; if(!file_exists($destiFilePath)) throw new Exception("转换文件格式失败, ".__CLASS__."::".__FUNCTION__.", source:{$source}"); return $destiFilePath; } |
php调用exec时设置超时
1 |
<span class="kwd">exec</span><span class="pun">(</span><span class="str">"timeout [seconds] [command]"</span><span class="pun">);</span> |
参考:https://stackoverflow.com/questions/9419122/exec-with-timeout