Zeno Tian


  • 首页

  • 归档

  • 标签

未命名

发表于 2017-11-15

iterm 和 oh-my-zsh 简单配置

晚上更新系统一个不小心将系统重置了。打开笔记本,之前使用习惯的快捷键和诸多配置全部不见了/(ㄒoㄒ)/~。

痛定思痛,这次重新配置将会记录,以防类似事件再次发发生。

1.下载iTerm2和oh-my-zsh

iTerm2官网

oh-my-zsh

1
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

2. 下载配色方案

github上有不错的配色方案,clone到本地

iterm2配色方案官网可以在线预览

1
git clone https://github.com/mbadolato/iTerm2-Color-Schemes.git

未命名

发表于 2017-11-13
分页查询
1
2
Employee.find().limit(limit).skip(skip).exec()
Employee.find().count()

未命名

发表于 2017-11-13

https://github.com/typicode/husky
git commit 规范/检测

https://github.com/chancejs/chancejs
随机生成数据

import NProgress from ‘nprogress’ // Progress 进度条

https://github.com/roman01la/webpack-closure-compiler
webpack js 优化

未命名

发表于 2017-11-07
1
vim ~/.zshrc
1
2
#vscode快捷方式
alias vs="open -a /Applications/Visual\ Studio\ Code.app"
1
source ~/.zshrc

未命名

发表于 2017-10-17



未命名

发表于 2017-09-28

安装/运行jenkins容器

1
2
3
docker pull Jenkins:latest
sudo mkdir /var/jenkins_home
sudo docker run --name myjenkins -p 49001:8080 -v /var/jenkins_home:/var/jenkins_home -d jenkins
docker文件权限错误处理
  • 错误信息:
    touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
    Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

  • 错误原因:docker容器的拥有者是jenkins
    通过-v /var/jenkins_home:/var/jenkins_home挂载的/var/jenkins_home文件夹拥有者是root

  • 错误验证:

    1. 查看容器用户

      1
      2
      3
      4
      sudo docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "whoami && id" jenkins
      jenkins
      uid=1000(jenkins) gid=1000(jenkins) groups=1000(jenkins)
    2. 查看容器内/var/jenkins_home目录拥有者

      1
      2
      3
      4
      5
      6
      7
      sudo docker run -ti --rm --entrypoint="/bin/bash" jenkins -c "ls -la /var/jenkins_home"
      total 16
      drwxr-xr-x 2 jenkins jenkins 4096 Sep 28 06:16 .
      drwxr-xr-x 12 root root 159 Sep 14 06:32 ..
      -rw-r--r-- 1 jenkins jenkins 220 May 15 19:45 .bash_logout
      -rw-r--r-- 1 jenkins jenkins 3526 May 15 19:45 .bashrc
      -rw-r--r-- 1 jenkins jenkins 675 May 15 19:45 .profile
  • 错误处理:
    将主机的/var/jenkins_home的拥有者修改为uid 1000

    1
    2
    sudo chown -R 1000 jenkins_home
    docker start jenkins

镜像启动后报错:Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
权限错误处理办法: http://blog.csdn.net/yulei_qq/article/details/53228601

安装后

运行成功后如果是在服务器上,通过服务器ip或域名 + 映射的主机端口号(如:49001)访问会有一个页面

根据页面的指令拷贝/var/jenkins_home/secrets/initialAdminPassword到页面中
Administrator password

由于是第一次使用jenkins所以选择了建议的

系统管理

  1. 安装Publish Over SSH插件
    在可选插件中搜索 Publish Over SSH,直接安装

    安装完毕之后我们需要重启Jenkins

    重启完成之后,我们就需要对插件进行设置了。进入 系统管理>系统设置。首先为了连接到我们的远程服务器,我们需要添加服务器配置。找到你得Publish over SSH插件栏

    2.在docker中密钥对

    • 将密钥粘贴到jenkins的配置中,或者设置密钥的路径
    • 将公钥粘贴到服务器对应下面ssh serve配置的username的authorized_keys文件中
    • 
      如果你用的是docker容器,需要进到容器里面生成密钥和公钥
      在服务器的机器人上生成ssh密钥对
      1
      ssh-keygen -t rsa

构建账号没有root密码:
sudo: no tty present and no askpass program specified

由于帐号并没有开启免密码导致的

假设当前帐号为abc
切换到root下

1 打开sudoers
vi /etc/sudoers
2 添加免密码
abc ALL = NOPASSWD: ALL

未命名

发表于 2017-09-26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#定义Nginx运行的用户和用户组
#user nobody;
#nginx进程数,建议设置为等于CPU总核心数。
worker_processes 1;
#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#进程文件
#pid logs/nginx.pid;
#工作模式与连接数上限
events {
#单个进程最大连接数(最大连接数=连接数*进程数)
worker_connections 1024;
}
#设定http服务器
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改 成off。
sendfile on;
#防止网络阻塞
#tcp_nopush on;
#长连接超时时间,单位是秒
#keepalive_timeout 0;
keepalive_timeout 65;
#开启gzip压缩输出
#gzip on;
#虚拟主机的配置
server {
#监听端口
listen 80;
#域名可以有多个,用空格隔开
server_name localhost;
#默认编码
#charset utf-8;
#定义本虚拟主机的访问日志
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}

未命名

发表于 2017-09-25

flag

第一版目标

功能

立flag
  • 目标标题
  • 目标详情

    • 总目标截止日期
    • 目标拆分

    打卡周期:N天1次
    子目标: 目标 + 截止日期

    • 奖惩措施
打卡/完成
  • 文字
  • 图片 (图片上传)
时光轴

完成前是否生成?

分享

数据库

  • 目标

    • 标题
    • 开始日期
    • 结束日期
    • 子目标 (关联表)
    • 奖惩措施 (文字)
  • 子目标

    • 子标题
    • 打卡时间
    • 截止日期
    • 打卡状态
    • 文字打卡
    • 图片

api服务器

(测试/正式)

  • 域名
  • 图片上传
    • 七牛
  • mongoDB
  • https??

公众号

  • 推送

未命名

发表于 2017-09-21

关于小程序swiper的问题

代码

在官方示例上给swiper添加了current``bindchange``circular
添加了一个button``bindtap用于切换下一张

index.wxml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<swiper indicator-dots="{{indicatorDots}}"
bindchange="swiperChange"
current="{{index}}"
circular="true"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
<block wx:for="{{imgUrls}}">
<swiper-item>
<image src="{{item}}" class="slide-image" width="355" height="150"/>
</swiper-item>
</block>
</swiper>
<button bindtap="changeIndicatorDots"> indicator-dots </button>
<button bindtap="changeAutoplay"> autoplay </button>
<button bindtap="nextSwiper"> 下一张 </button>
<slider bindchange="intervalChange" show-value min="500" max="2000"/> interval
<slider bindchange="durationChange" show-value min="1000" max="10000"/> duration

index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* create by ZenoTian
*/
Page({
data: {
imgUrls: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
],
indicatorDots: false,
autoplay: false,
interval: 5000,
duration: 1000,
index: 2
},
changeIndicatorDots: function(e) {
this.setData({
indicatorDots: !this.data.indicatorDots
})
},
nextSwiper: function (e) {
let {index} = this.data
index === 2
?index = 0
:index++
console.log(`下一张:${index}`)
this.setData({
index
})
},
changeAutoplay: function(e) {
this.setData({
autoplay: !this.data.autoplay
})
},
intervalChange: function(e) {
this.setData({
interval: e.detail.value
})
},
durationChange: function(e) {
this.setData({
duration: e.detail.value
})
},
swiperChange: function (e) {
console.log('bindchange事件', `this.data.index:${this.data.index} e.detail.current:${e.detail.current}`)
}
})

问题1:手动赋值current值,衔接滑动无效

点击下一张,通过给setData改变swiper的current值,在从最后一张切换至第一张时,虽然设置了circular,但是不会有衔接滑动的效果,而是从尾部一路溜到了头。

问题2:绑定的current的值,滑动并不会改变

通过给swiper的current绑定了this.data.index
默认值是生效的,但是在手滑滑块的时候,并不会自动改变this.data.index的值。
通过bindchange的打印可以看出来。this.data.index的值是永远不会变的。
所以这时候current和this.data.index是不照应的。

例如:向右滑动

1
2
3
4
5
bindchange事件 this.data.index:2 e.detail.current:1
bindchange事件 this.data.index:2 e.detail.current:0
bindchange事件 this.data.index:2 e.detail.current:2
bindchange事件 this.data.index:2 e.detail.current:1
bindchange事件 this.data.index:2 e.detail.current:0

在官方文档中

如果在 bindchange 的事件回调函数中使用 setData 改变 current 值,则有可能导致 >setData 被不停地调用,因而通常情况下请不要这样使用

如果想让current和this.data.index对照,还是需要在bindchange 的事件回调函数中使用setData改变current值。

1
2
3
4
5
6
7
8
swiperChange: function (e) {
console.log('bindchange事件',`this.data.index:${this.data.index} e.detail.current:${e.detail.current}`)
this.setData({
index: e.detail.current
})
}

问题3:控制current的值切换,与滑动切换代码结果不一样

如果采取了在bindchange 的事件回调函数中使用setData改变current值。
点击下一张:给this.data.index赋值后触发的bindchange事件回调中的,this.data.index与e.detail.current的值相同。

1
2
3
4
5
6
7
8
9
10
下一张:0
bindchange事件 this.data.index:0 e.detail.current:0
下一张:1
bindchange事件 this.data.index:1 e.detail.current:1
下一张:2
bindchange事件 this.data.index:2 e.detail.current:2
下一张:0
bindchange事件 this.data.index:0 e.detail.current:0
下一张:1
bindchange事件 this.data.index:1 e.detail.current:1

手动滑动时:bindchange事件回调中的,this.data.index的值会是上一次的值

1
2
3
4
5
bindchange事件 this.data.index:2 e.detail.current:1
bindchange事件 this.data.index:1 e.detail.current:0
bindchange事件 this.data.index:0 e.detail.current:2
bindchange事件 this.data.index:2 e.detail.current:1
bindchange事件 this.data.index:1 e.detail.current:0

总结

使用手动改变current的值时,current的值先变,然后触发bindchange,在事件回调中无需再去设置current的值。这种切换方式,设置swiper的circular="true"是无效的,会从最后一张跑到第一张。

而通过滑动屏幕切换,在bindchange,绑定的current的值是不会改变的,而实际上swiper的current已经改变了。

未命名

发表于 2017-09-16

title 在centOS部署自己的代码库

参照网上的一些教程,总结一份较好的方案

1.安装git

1
yum install -y git

2.添加用户/用户组

创建一个git用户组,和git用户
因为考虑到可能会和多人共用git代码库,所以建立一个专门的分享系统用户给开发者们。

1
2
3
sudo groupadd git
sudo adduser git -g git
sudo passwd git

1
vim /etc/passwd

将
git:x:1001:1001:,,,:/home/git:/bin/bash
修改为
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
让git用户只能使用git-shell进行git相关的操作

ssh登录

在参考网上的一些

  1. 开启服务器RSA验证
    1
    vim /etc/ssh/sshd_config

找到并去掉前面的#号

1
2
3
4
5
6
7
RSAAuthentication yes
PubkeyAuthentication yes
RSAAuthentication yes
RSAAuthentication #设置是否允许只有RSA安全验证。
PasswordAuthentication
PasswordAuthentication yes #PasswordAuthentication”设置是否允许口令验证。
AuthorizedKeysFile .ssh/authorized_keys

  1. 配置RSA公钥
    如果使用的是非root用户需要切换到git用户,才有权限对/home/git下的文件进行操作
1
su - git #切换用户

创建authorized_keys文件,用于配置开发者的公钥

1
2
3
4
5
cd /home/git/
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

  1. 客户端生成公钥
    1
    2
    ssh-keygen -t rsa -C "youremail@your.com" -f ~/.ssh/my-rsa #生成公钥,并指定文件名
    cat ~/.ssh/my-rsa.pub # 复制里面的内容,粘贴到服务器的authorized_keys中去

验证

创建git中央仓库
1.进入git用户主目录

cd /home/git
2.创建一个裸仓库 (一般以.git结尾)

git init –bare test.git #以test.git为例子,当然你可以叫任意名字
裸仓库是没有工作区的,纯粹为了共享

3.修改仓库用户属主

chown -R git:git test.git

1
git clone git@xxx.xxx.xxx.xxx:test.git

1、查看git-shell的位置

which git-shell
得到的位置:/usr/bin/git-shell

2、将git-shell添加到shell当中
1)vim /etc/shells
2)/usr/bin/git-shell 将这写到 /etc/shells的最后一行

3、更改git用户使用的shell
chsh git
到此位置git的用户权限已全部设置完成

12…4
Zeno Tian

Zeno Tian

38 日志
17 标签
GitHub
© 2017 Zeno Tian
由 Hexo 强力驱动
主题 - NexT.Mist