Skip to main content

晓残

一个苦逼的创业者...

  • 主页
  • 服务器
  • 代码
  • 数据库
  • 图库
  • My Git
  • 购买域名
  • About me
  • Subscribe to our RSS Feed

Go Template 自定义函数

23rd August, 2017 • Go Code

Go html template 自定义函数 func GeoListGet(w http.ResponseWriter, r *http.Request) { tpl := template.New("main_parent.html") selfunc := make(template.FuncMap) selfunc["calNumber"] = CalNumbers tpl = tpl.Funcs(selfunc) var err error tpl, err = tpl.ParseFiles(fmt.Sprintf("%vparent/main_parent.html", conf.TmpPath), fmt.Sprintf("%vgeo/index.html", conf. …

Docker 基本命令

7th August, 2017 • Server

Docker 常用命令总结 安装 Docker的安装在1.12之后需要Centos7才行 yum update all -y curl -fsSL https://get.docker.com/ | sh 启动、停止 service docker start service docker stop 查看日志 journalctl -fu docker.service 列出可用镜像 docker images [root@ZJ2153 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE xiaocan_ghost_blog latest 37e318a865ed 5 days ago …

New server move logs

2nd August, 2017 • Server

Gitlab + Node.js 迁移到Docker记录 Centos 7.3 安装Docker 安装脚本 curl -fsSL https://get.docker.com/ | sh 启动docker service docker start 测试是否成功 docker run hello-world Docker + Gitlab Gitlab为我们提供了最新版本的docker image,可以直接使用: docker run --detach \ --hostname git.cansdk.com \ --publish 127.0.0.1:44301:443 --publish 127.0.0.1:8081:80 …

摘录 类型断言

27th May, 2017 • Code Go

类型断言:如何检测和转换接口变量的类型 一个接口类型的变量 varI 中可以包含任何类型的值,必须有一种方式来检测它的 动态 类型,即运行时在变量中存储的值的实际类型。在执行过程中动态类型可能会有所不同,但是它总是可以分配给接口变量本身的类型。通常我们可以使用 类型断言 来测试在某个时刻 varI 是否包含类型 T 的值: v := varI.(T) // unchecked type assertion varI 必须是一个接口变量,否则编译器会报错:invalid type assertion: varI.(T) (non-interface type (type of varI) on left) 。 类型断言可能是无效的,虽然编译器会尽力检查转换是否有效,但是它不可能预见所有的可能性。如果转换在程序运行时失败会导致错误发生。更安全的方式是使用以下形式来进行类型断言: if v, ok := varI.(T); ok …

Linux StrongSwan Cilent

12th May, 2017 • Server

StrongSwan Ikev2 Client 在Centos6.8系统上使用StrongSwan连接Ikev2 VPN 安装 yum install epel-release -y yum install gpm-devel pam-devel openssl-devel make gcc wget http://download.strongswan.org/strongswan.tar.gz tar xzvf strongswan.tar.gz cd strongswan-5.5.2 ./configure --prefix=/usr --sysconfdir=/etc/strongswan --enable-eap-identity --enable-eap-md5 --enable-eap-mschapv2 --enable-eap-tls --enable-eap-ttls --enable-eap-peap --enable-eap-tnc --enable-eap-dynamic --enable-eap-radius …

Virualmin + Nginx + PHP-FPM Unix Domain

17th March, 2017 • Server nginx PHP php-fpm

Virtualmin + Nginx + PHP-FPM Unix domain socket 本文基于已经在Virtualmin上安装配置好Nginx module,故不再描述Nginx等安装配置。 Virualmin + Nginx 安装配置 Why PHP-CGI不好进行配置和优化 配置PHP-FPM 编辑/etc/php-fpm.d/sitename.conf 添加或修改配置部分如下: ; 创建监听池 [pool name] ; 监听方式使用unix domain socket方式 listen = /tmp/php7-fpm.sock ; 运行的用户设置为与website相同 user = website group = website ; 对于多站点,并且用户各自不相同的情况,注意修改以下配置和权限 listen.owner = nobody listen.group = nobody listen.mode = 0666 配置Nginx …

Go IDE-Golang EAP & Hello world

15th March, 2017 • Code Go

Go IDE(Golang EAP) 环境构建 Golang EAP是JetBrain下的一个IDE,目前是开发预览版本 Download 这里只说已经安装好Go和Golang EAP之后,怎么在工程中调试Go Application。因为全网的搜索结果基本都是基于Go1.3的,本文基于Go1.8来说一个Hello world怎么写。同样,此文章并非准确也并非推荐做法,仅作为新手入门过程中的记录。 创建项目 创建项目的时候注意选择好使用的Go版本。 创建目录 为了遵循Google的Go的开发规范,和方便我们之后的工作,我们按照Go的要求,在每个项目文件夹下建立三个文件夹: bin 生成的执行文件 pkg 编译的中间文件 src 程序的代码文件 同时可以创建一个vendor文件夹,用来存放一些固定的特殊的代码文件。 设置环境 点击打开项目配置,配置Go的使用环境,同样,遵循Google的开发建议,每个项目都建立自己独有的PATH 于是我们在这里添加我们的项目目录,如图。 编写代码 我在这里写了一个很简单的Hello world。Go语言推荐package名称和文件夹名称相同。 坑就出在这里,搜索到的所有的中文的文章在调试Go …

Mongodb 快速上手

10th March, 2017 • Database Mongodb

MongoDb 官网 安装环境Centos 6.7 x64 安装 Binary安装 curl -o mongo.tar.gz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.2.tgz tar -xvzf mongodb-linux-x86_64-rhel62-3.4.2.tgz cd mongodb-linux-x86_64-rhel62-3.4.2 bin中的就是mongodb的程序,记得将路径加入环境变量 export PATH=<mongodb-install-directory>/bin:$PATH Yum安装 创建repo文件在/etc/yum.repos.d/ …

ATX 免越狱调试IOS和Android

2nd March, 2017 • ATX Python Code

利用ATX配合WDA进行图形识别+自动化测试 通过使用AutomatorX,配合WebDriverAgent,可以实现在非越狱的IOS设备上更简单的进行自动化测试。同样,Android设备一样受到支持。 相关工程 AutomatorX WebDriverAgent 环境要求 Python3.5+ Brew Mac OS X 10.11+ IOS 10+ Android 4.0+ 配置环境 以下操作基于已经创建了python3.5的VirtualEnv 通用 brew install homebrew/science/opencv brew install pillow pip install --upgrade --pre atx -i https://pypi.doubanio.com/simple/ pip install opencv_ …

Mysql MHA

29th October, 2016 • Database Mysql

MHA MHA 安装 安装依赖 yum -y install perl-DBD-MySQL* yum -y install perl-Config-Tiny* yum -y install perl-Parallel-ForkManager* yum -y install perl-MailTools* yum -y install perl-Email-Date-Format* yum -y install perl-Mail-Sender* yum -y install perl-MIME-Types* yum -y install perl-MIME-Lite* yum -y install perl-Mail-Sendmail* yum -y install perl-Log-Dispatch* 下载MHA Manager和Node:下载 安装MHA [root@centos …

nginx if 多条件判断

27th October, 2016 • Server nginx

因为Nginx中的if语句不允许使用多条件判断,所以需要变通一下,使用变量作为中间值,然后判断这个变量: set $do_yaf 0; if ( $chic_ver = 3 ) { set $do_yaf 1; } if (!-e $request_filename) { set $do_yaf "${do_yaf}1"; } if ( $do_yaf = "11" ) { rewrite ^/(.*)$ /index.php/$1 last; } location / { include /etc/nginx/conf.d/fastcgi_params; if ( $chic_ver = 2 ) { proxy_pass http: …

Yaf Nginx with php-fpm socket

27th October, 2016 • Server nginx

Nginx+Php-fpm socket+Yaf 折腾了很久Yaf+Nginx在php-fpm的socket模式下的配置,总结如下: PHP设置 为了在nginx下使用,Php需要使用fix path info。打开php配置,加上如下配置: cgi.fix_pathinfo=1 Nginx设置 Nginx下的Server节点中配置如下: if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; } location / { include /etc/nginx/conf.d/fastcgi_params; fastcgi_pass unix:/var/php-nginx/14774481332305.sock/socket; } Nginx php-fpm设置 在/etc/nginx/ …

Nginx rewrite by header value

24th October, 2016 • Server nginx

Nginx 判断header中的value进行版本分离 当前有一个需求是为了平滑升级,需要老版本和新版本API共存,最简单的方法是从nginx上下手,建立两套代理机制。 大致来说就是使用nginx的map来进行头部数据的提取并转化为变量,然后在location中判断并使用rewrite。 nginx中if语句存在极大的不确定性,一定要仔细测试 if和后面括号以及变量等号这些元素都要有空格 map代码 map $http_xiaocan $ver{ default 3; 2 2; 3 3; } location中判断 location / { if ($ver == 2) { rewrite ^(.*)$ http://www.xiaocan.me } if ($ver == 3) { rewrite ^(.*)$ http://www.baidu.com } } 完整代码 # For more information on configuration, see: # * Official English Documentation: …

Mysql lock

23rd October, 2016 • Database Mysql

索引和执行计划 慢查询设置 设置longquerytime来将执行时间超过设置的SQL记录在slowlog中,单位s。 同时设置logqueriesnotusingindexes=1记录所有没有索引的SQL到slowlog中。 开启slow log需要添加slowquerylog_file参数指定文件位置。 因为slow log会记录重复的SQL,所以一般需要借助pt-query-digest工具来进行分析。 或者在Sql中直接开启: set global slow_query_log=on; set global slow_query_log_file='/home/data/mysql/3306/slow.log'; set global long_query_time=1; set global log_queries_not_using_indexes=on; 分析满日志 分析满日志 pt-query-digest slow. …

Mysql索引、查询计划、优化方向

15th October, 2016 • Database Mysql

索引 Innodb索引(聚集索引)(聚簇表分布) Innodb是索引组织表,其结构是B+Tree。其表索引结构是聚簇表分布。 其叶子节点保存了Key+Row Data(聚集索引,按主键排序),其Key是主键或非空的唯一索引。而其二级索引是非主键或者非空的唯一索引。即Innodb表会把主键作为聚集索引,如果没有主键,会选择非空的唯一索引作为聚集索引。如果非空的唯一索引也没有的情况下,Innodb表会默认生成一个6bytes的id,默认作为主键成为聚集索引。 在创建表的时候要自己指定一个没有业务含义的主键,便于快捷插入 默认6字节的数据,到达数据上限时,不会报错,而是会直接覆盖数据 Myisam索引(非聚集索引)(非聚簇表分布) Myiasm不管是主键索引还是二级索引,永远存储的是Key,数据则单独在表中。即非聚集索引,查询的时候要先查询索引,然后查询数据。 Innodb优化方向和注意事项 创建索引 需要注意的是创建索引不是越多越好,要注意基数和选择性。 基数: 一列数据,只有True和False两个结果。则这一列的基数是2 选择性: 列唯一键与行数的比值,在0-1之间。他的取值越小越好。选择性的值是根据表中值的数据而不一样的。基数为2的情况下, …

Python Celery

10th October, 2016 • Code Python

Python Celery + Redis 安装 pip install -U celery[redis] 配置redis参考 配置所使用的redis服务器 redis://:password@hostname:port/db_number Example: BROKER_URL = 'redis://localhost:6379/0' 配置redis的可见性超时 BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600} # 1 hour. redis中存储状态和返回值 CELERY_RESULT_BACKEND = 'redis://localhost:6379/0' 只让消息对活动的主机接受 BROKER_TRANSPORT_OPTIONS = {'fanout_prefix': True} 创建一个task.py …

Shadowsocks to Http over Mac

23rd September, 2016

polipo brew install polipo polipo socksParentProxy=localhost:1080 然后http代理使用8123端口就可以了 http_proxy=127.0.0.1:8123 curl http://www.google.com Genymotion使用的话,使用NAT模式,然后模拟器中代理设置为10.0.3.2:8123 …

Innodb Redo Undo & Checkpoint

21st September, 2016 • Database Mysql

事务隔离级别 Innodb 提供了四种隔离级别: Level Description READ UNCOMMITTED 幻像读、不可重复读和脏读都允许。 READ COMMITTED 允许幻像读、不可重复读,但不允许脏读。一般使用的级别 REPEATABLE READ 允许幻像读,但不允许不可重复读和脏读。InnoDB默认级别 SERIALIZABLE 幻像读、不可重复读和脏读都不允许。 检查和设置当前隔离级别 检查 mysql> SELECT @@global.tx_isolation; +-----------------------+ | @@global.tx_isolation | +-----------------------+ | REPEATABLE-READ | +-----------------------+ 1 row in set (0.00 sec) mysql> SELECT @@session.tx_ …

Webmin 1.8.10 Nginx 502 on Reboot

20th September, 2016 • Server webmin PHP nginx

因为Webmin1.8.10没有自动创建启动文件的bug,会导致nginx在重新启动服务器之后无法正确打开socket,从而无法正确执行PHP。解决方法如下: 在配置文件中找到socket: server { server_name casinopb.com www.casinopb.com; listen 192.74.244.100; root /home/healpb/public_html; index index.html index.htm index.php; access_log /var/log/virtualmin/healpb.com_access_log; error_log /var/log/virtualmin/healpb.com_error_log; …

Nginx optimization

14th September, 2016 • Server

Nginx 优化 提升文件句柄 编辑/etc/security/limits.conf,加上: nginx soft nofile 65535 nginx hard nofile 65535 查看cpu核心数 [root@ef ~]# grep processor /proc/cpuinfo | wc -l 8 根据核心数和句柄数设置nginx线程数和连接数 修改nginx.conf, 注意不要占满全部资源: ### 以下是全局设置,不在server{}中 # 指定nginx的用户 user nginx; # 设置线程数 worker_processes 8; # 将线程和CPU核心绑定,提升效率 worker_cpu_affinity 00000001 00000010 00000100 00001000 …

Page 1 of 3 Older

鄂ICP备13005395号-1

© 晓残, 2019 • All rights reserved.