HackToday Walk Blog


  • Home

  • Tags

  • Archives

  • Search

kindle购买美国亚马逊的书籍

Posted on 2016-05-29

参考知乎上的链接 https://www.zhihu.com/question/23863224

主要步骤:

  1. 注册美亚账号

  2. 填写地址信息,如果使用中国地址,你是无法购买美亚的kindle书籍的

  3. 使用信用卡或者礼品卡(某tao网站)

  4. 下单,直接选择deliver方式,会发现kindle设备的书籍下载进度很慢,半天不动,可能和墙有些关系,
    所以直接使用通过电脑下载本地,然后USB连接kindle,copy到Documents目录中即可。

Docker网络 Bridge and none Mode使用

Posted on 2016-05-28

Docker默认的是三种网络类型,bridge,none,host
其中bridge是典型的类似VM的linux-bridge网络

具体在每次运行docker run的时候,container都会从bridge对应的网络范围中选择一个空闲的ip,然后将其设置为对应容器的eth0的ip。
Docker bridge的网络ip设置对应每个容器的默认网关,提供给容器来访问外部的网络。

因为docker自己操作的容器网络名字空间并不是放在/var/run/netns中,所以ip netns无法直接查看,可以通过以下的方式来访问:

下面的过程是对none类型的容器进行网络配置的例子:

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
$ docker inspect -f '{{.State.Pid}}' 63f36fc01b5f
2778
$ pid=2778
$ sudo mkdir -p /var/run/netns
$ sudo ln -s /proc/$pid/ns/net /var/run/netns/$pid

$ ip addr show docker0
21: docker0: ...
inet 172.17.42.1/16 scope global docker0
...

# Create a pair of "peer" interfaces A and B,
# bind the A end to the bridge, and bring it up

$ sudo ip link add A type veth peer name B
$ sudo brctl addif docker0 A
$ sudo ip link set A up

# Place B inside the container's network namespace,
# rename to eth0, and activate it with a free IP

$ sudo ip link set B netns $pid
$ sudo ip netns exec $pid ip link set dev B name eth0
$ sudo ip netns exec $pid ip link set eth0 address 12:34:56:78:9a:bc
$ sudo ip netns exec $pid ip link set eth0 up
$ sudo ip netns exec $pid ip addr add 172.17.42.99/16 dev eth0
$ sudo ip netns exec $pid ip route add default via 172.17.42.1

借助Hexo建立Github上的网站

Posted on 2016-04-29

上一篇Hexo中,我们介绍了它是一个简单提供了快速搭建静态博客系统的软件,那么我们就想借助它来实现可以建立一个公开可访问博客网站,
问题来了,如果没有自己的域名服务器,怎么实现这个要求?

有人想到了使用公有云的虚拟机,但是域名购买还是需要的,使用ip访问?这个显然不太方便让外面用户访问,这时我们想到了github pages。

Github提供了github pages功能,借助它可以方便的实现个人博客的在线系统。

那具体操作如下:(下面的操作都是在上一篇启动的Hexo容器中操作)

  1. 建立一个公共的repository, username.github.io

  2. git clone到本地,cd 到相应的目录,建立一个新的分支,这里我们使用的名字是source,下面所有的操作都是source分支

  3. 执行hexo init初始化,生成相应的博客系统配置文件

  4. 执行 npm install安装相应的nodejs包

  5. 执行 npm install hexo-deployer-git –save,这一步配置完成hexo git deploy插件的安装

  6. 配置相应的git deploy 部署参数:

1
2
3
4
5
6
# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/username/username.github.io.git
  branch: master
  1. 然后在source文件夹写博客

  2. 返回到主目录,执行hexo g,产生相应的博客网站需要的文件

  3. 执行hexo deploy 部署博客网站

访问 http://username.github.io/, 就是部署后的网站了。

这里借助github.io的repository就方便的实现了博客源文件管理(source分支)和快速部署(master分支)的需求,
而且借助github pages实现了在线博客的运行。

参考:

  1. https://pages.github.com/
  2. https://github.com/hexojs/hexo

Ghost和Hexo博客系统的体验

Posted on 2016-04-19

一直打算部署博客系统,比较了流行的WP, Ghost, Hexo and Pelican

网上先调研了一番,发现有两篇文章比较有参考价值:
一个是个人的实践 http://www.maintao.com/2014/hexo-beginner%27s-guide/
另外一个是知乎的 http://www.zhihu.com/question/21981094

综合比较下来,发现还是这个Hexo满足我的最简单最小化静态博客需求,但是既然借助容器体验非常方便,那么我就也顺便体验了ghost一番

Hexo使用:

1.安装Hexo

1
   docker run --name hexo -it -p 8083:80 -v `pwd`: /usr/share/nginx/html/source simplyintricate/hexo
  1. 发布一篇blog
1
docker exec -it hexo hexo new "This is one post"

Ghost使用

1
docker run --name some-ghost -p 8085:2368 -d ghost

直接操作UI就行了,Ghost相对UI比较好,操作简单,但是依赖数据库存储,而且现有的API发布一篇markdown文档不简单

Hexo简单,UI稍微逊色,不依赖数据库,原始文档即博客数据(存在固定的文件夹下),非常方便,发布新的博客,需要重启容器,
这点网上也介绍有第三方工具,实现动态更新,还没有研究。

static binary 安装docker遇到Devices cgroup is not mounted

Posted on 2016-03-25

实验环境: ubuntu 14.04
docker 版本: 1.10.3
kernel: 3.13.**

如果采用binary docker的使用方式
https://github.com/docker/docker/blob/master/docs/installation/binaries.md

你会发现docker启动,报错 Devices cgroup isn't mounted

这个是因为默认的cgroup的cpu,memory等没有被挂载,需要使用一个脚本来挂载,具体使用脚本是
https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount

执行完上面的脚本后,然后就可以运行docker就不会报cgroup的错误了。

这个问题解决了,但是会遇到另外一个

1
AppArmor enabled on system but the docker-default profile could not be loaded,

这个正在跟踪docker官方的issue,后面调查结果会随后更新

使用Docker进行天气预报

Posted on 2016-03-15

Docker的容器化带来的一个好处是可以方便的尝试各种app的快速部署和体验,github上有一个有趣的天气预报app,https://github.com/schachmat/wego

步骤如下:

  1. 部署一个支持golang运行环境的容器
    docker run –rm -it golang bash
  1. 安装wego
    运行wego,第一次安装的时候会生成一个配置文件,~/.wegorc
    其中需要配置一个key,这个key是可以支持调用worldweatheronline.com网站的API,
    你需要到对应的网站免费注册,获得相应的免费API key,配置到上面的这个文件中。
  1. 配置城市
    city=Beijing

  2. 再次运行wego, 就获得了结果

多窗口下的VIM常用的快捷键和操作

Posted on 2016-02-02
  1. split vsplit 窗口分割

  2. Ctrl +w + 窗口的上下左右调整

  3. 窗口的调整大小

1
2
3
:res +5

:vertical resize +5

Docker btrfs的实践

Posted on 2016-02-02

使用OpenStack部署的虚拟机,其中只有一块盘,但是docker的btrfs需要一个单独的设备,如果OpenStack没有Cinder服务,
还要手动加盘,实在有点麻烦,作为实验来说有点不便。那么怎么绕过去呢,很简单,使用全能的loop device,具体如下:

  1. 创建一个空的image文件(9.6G)
1
dd if=/dev/zero of=btrfs.img bs=512 count=20000000
  1. 建立loop,操作来为mount准备
1
losetup /dev/loop0 btrfs.img
  1. 安装btrfs tools
1
sudo apt-get install btrfs-tools
  1. 创建btrfs存储池
1
sudo mkfs.btrfs -f /dev/loop0
  1. 创建docker使用的文件目录
1
sudo mkdir -p /var/lib/docker
  1. 获取btrfs文件系统的UUID
1
sudo blkid /dev/loop
  1. 创建对应的/etc/fstab项目,使得可以系统启动时可以自动挂载
1
2
/dev/loop0 /var/lib/docker btrfs defaults 0 0
UUID="b18ea60f-5cad-4b3d-8769-a2da818fdedb"  /var/lib/docker btrfs defaults 0 0
  1. 挂载上面的新的文件系统
1
sudo mount -a
  1. 重启docker
1
sudo service docker start

这样就完成btrfs storage driver配置完成。

后面我们想做一个实验,想获取btrfs文件的Magic Number : 9123683e

1
2
3
docker run --rm -it -v "$PWD":/usr/src/mygo -w /usr/src/mygo  -v /var/lib/docker:/var/lib/docker  golang bash

export GOPATH=$GOPATH:/usr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// mygo/main.go

package main

import (
        "fmt"
        "log"
        "os"
        "syscall"
)

        
func main() {
        log.Printf("Args are :%s ", os.Args)
        var stat syscall.Statfs_t
        if err := syscall.Statfs("/var/lib/docker", &stat); err != nil {
                log.Fatalf("Stat error\n")
        }
                
        fmt.Printf("The type is %x\n", uint32(stat.Type))
}
//

在容器中运行程序,可以得到结果:
2016/02/02 13:38:46 Args are :[mygo]
The type is 9123683e

参考资料:

http://wiki.osdev.org/Loopback_Device
https://www.howtoforge.com/a-beginners-guide-to-btrfs
https://github.com/docker/docker/blob/master/docs/userguide/storagedriver/btrfs-driver.md

2016容器大会分享资料

Posted on 2016-01-25

在昨天这么严寒的北京日子,聚集了一帮对容器感兴趣的程序员和运维开发人员,大会还是有不少公司分享的干货的,
大家可以下载大会的ppt,从中学习一些docker的实践案例。

下载地址: http://pan.baidu.com/s/1i4nN2Qh

Vim Plugin 推荐

Posted on 2015-12-30

前段时间使用vim作为Go的开发编辑环境,顺便使用了几个不错的plugin,值得推荐一下:

  1. Vim的强大之处,在于丰富的plugin生态,使用plugin必然缺不了plugin的管理器
    Vim plugin manager:Vundle, Neobundle 等

  2. neocomplete 关键字补全

  3. go development vim plugin vim-go

vim-go 依赖其他的组件实现更加强大的类IDE功能 其中包括neocomplete,tagbar,

  1. tagbar 视图功能

  2. molokai 色彩主题

  3. nerdtree 代码目录树视图

  4. unite 高级文件查找和显示

  5. the_platinum_searcher 高级代码查找工具, 可以配合unite使用

综上使用,可以帮助你快速的go代码开发和阅读

参考:

  1. https://github.com/VundleVim/Vundle.vim
  2. https://github.com/Shougo/neobundle.vim
  3. https://github.com/Shougo/neocomplete.vim
  4. https://github.com/fatih/vim-go
  5. https://github.com/majutsushi/tagbar
  6. https://github.com/fatih/molokai
  7. https://github.com/scrooloose/nerdtree
  8. https://github.com/Shougo/unite.vim
  9. https://github.com/monochromegane/the_platinum_searcher
1…678…26

Kai Qiang Wu

This is a place for thinking and writing

253 posts
32 tags
GitHub
© 2020 Kai Qiang Wu
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4
Visitor Total Visit