docker笔记

#1.Install packages to allow apt to use a repository over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common

#2.Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

#3.Use the following command to set up the stable repository.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

#4.Update the apt package index.
sudo apt update

#5.Install the latest version of Docker CE
sudo apt install docker-ce

#6.Ensure that you have a supported version of Docker:
docker version

#7.Verify that Docker CE is installed correctly by running the hello-world image.
sudo docker run hello-world

#8.List the hello-world image that was downloaded to your machine:
docker image ls

#9.List the hello-world container (spawned by the image) which exits after displaying its message. If it were still running, you would not need the --all option:
docker container ls --all

#10.Search the Docker Hub for images
docker search <image>

#11.Start container
docker start <name>

#12.Attach container
docker attach <name>

#13.Commit image
docker commit -m="has update" -a="comet" ea4c82dcd15a comet/ubuntu:v2

#20.Other command
docker build -t friendlyhello . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode
docker container ls # List all running containers
docker container ls -a # List all containers, even those not running
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker image ls -a # List all images on this machine
docker image rm <image id> # Remove specified image from this machine
docker image rm $(docker image ls -a -q) # Remove all images from this machine
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push username/repository:tag # Upload tagged image to registry
docker run username/repository:tag # Run image from a registry

#21.Docker command
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

Reference from :https://docs.docker.com/get-started/

ansible笔记

以下为markdown格式:

# 客户端
# 1.准备工作
## 1.1安装openssh-server和python
`apt install openssh-server pytnon`

## 1.2允许root登录
修改 /etc/ssh/sshd_config 中 PermitRootLogin 的值为yes
默认值为 prohibit-password

## 1.3重启openssh服务
`systemctl restart ssh.service`

# 管理端
# 1安装及配置ansible
## 1.1生成密钥对
使用root登录后执行 ssh-keygen 生成密钥对

## 1.2对客户端加入公钥
`ssh-copy-id -i .ssh/id_rsa.pub root@192.168.13.71`

## 1.3安装ansible
`apt install ansible`

## 1.4配置ansible
编辑 /etc/ansible/ansible.cfg

# 2使用ansible命令
## 2.1配置inventory文件
编辑inventory文件hosts

/etc/ansible/hosts

[mysrv]

192.168.13.71

## 2.2执行命令
ping hosts文件中全部的主机,-o为输出结果为1行

`ansible all -m ping -o`

复制test.txt文件到客户端
文件模式600,所属用户为user1,所属组为user1group
可以用file模块替代copy模块

`ansible mysrv -m copy -a 'src=test.txt dest=~/test.txt mode=600 owner=user1 group=user1group' -o`

利用username的用户去对mysrv组中的电脑进行重启
参数-f 10为fork出10个子进程(每次执行10台电脑)

`ansible mysrv -a "/sbin/reboot" -u username --sudo --ask-sudo-pass -f 10`

使用user模块可以方便的创建账户,删除账户,或是管理现有的账户:

`ansible all -m user -a "name=foo password=<crypted password here>"`

`ansible all -m user -a "name=foo state=absent"`

利用apt安装nginx,需输入密码

`ansible one -m apt -a "name=nginx state=present" --sudo --ask-sudo-pass`

利用apt卸载nginx,需输入密码

`ansible one -m apt -a "name=nginx state=absent" --sudo --ask-sudo-pass`

# 3使用playbook
## 3.1检测语法
`ansible-playbook --syntax-check the.yml`

## 3.2测试运行
`ansible-playbook -C the.yml`

## 3.3创建用户的例子
createuser.yml

```
---
- hosts: one
vars:
username: "testuser"
user: root
tasks:
- name: create user
user: name="{{ username }}"
```
执行playbook
`ansible-playbook createuser.yml`

## 3.3安装nginx的例子
nginx.yml

```
---
- hosts: one
remote_user: root
tasks:
- name: ensure nginx is at the latest version
apt: name=nginx state=latest
- name: ensure nginx is running
service: name=nginx state=started
handlers:
- name: restart nginx
service: name=nginx state=restarted
```

## 3.4状态类型
安装软件:state={present|latest}

卸载软件:state={absent}

服务状态:state={started|stoped|restarted}

atom常用快捷键

英文 中文 快捷键 功能
New Window 新建界面窗口 Ctrl + Shift + N 如中文意思
New File 新建文件 Ctrl + N 如中文意思
Open File 打开文件 Ctrl + O 如中文意思
Open Folder 打开文件夹 Ctrl + Shift + O 如中文意思
Add Project Folder 加载项目目录 Ctrl + Alt + O 如中文意思
Reopen Last Item 重新加载上次项目 Ctrl + Shift + T 如中文意思
Save 保存文件 Ctrl + S 如中文意思
Save As 另存为 Ctrl + Shift +S 如中文意思
Close Tab 关闭当前编辑文档 Ctrl + W 如中文意思
Close Window 关闭编辑器 Ctrl + Shift + W 如中文意思
Undo 撤销 Ctrl + Z 如中文意思
Redo 重做 Ctrl + Y 如中文意思
Cut 剪切 Shift + Delete 如中文意思
Copy 复制 Ctrl + Insert 如中文意思
Copy Path 复制文档路径 Ctrl + Shift + C 如中文意思
Paste 粘贴 Shift + Insert 如中文意思
Select All 全选 Ctrl + A 如中文意思
Select Encoding 选择编码 Ctrl + Shift +U 就是设置文件的编码
Go to Line 跳转到某行 Ctrl + G 支持行列搜索,Row:Column
Slect Grammar 语法选择 Ctrl + Shift + L 和Sublime的Syntax设置功能一样
Reload 重载 Ctrl+ Alt +R 重新载入当前编辑的文档
Toggle Full Screen F11 全屏 如中文意思
Increase Font Size 增大字体 Ctrl + Shift + “+” Sublime的Ctrl + 也能生效
Decrease Font Size 减小字体 Ctrl + Shift + “-“ Sublime的Ctrl - 也能生效
Toggle Tree View 展示隐藏目录树 Ctrl + |Sublime的Ctrl+K,+B这里也可以生效
Toggle Commadn palette 全局搜索面板 Ctrl + Shift + P 和Sublime的大同小异
Select Line 选定一行 Ctrl + L 如中文意思
Select First Character of Line 选定光标至行首 Shift + Home 如中文意思
Slect End of Line 选定光标至行尾 Shift + End 如中文意思
Select to Top 选定光标处至文档首行 Ctrl + Shift + Home 就是光标处作为分割线,取文档上部分
Select to Bottom 选定光标处至文档尾行 Ctrl + Shfit + End 就是光标处作为分割线,取文档下部分
Find in Buffer 从缓存器搜索 Ctrl + F 与Sublime一致
Replace in Buffer 高级替换 Ctrl + Shift + F 与Sublime一致
Select Next 匹配选定下一个 Ctrl + D 和Sublime一模一样有木有
Select All 匹配选定所有 Alt + F3 和Sublime一模一样有木有
Find File 查询文件,选定打开 Ctrl + P 与Sublime不一样
Delte End of Word 删除光标处至词尾 Ctrl + Del 如中文意思
Duplicate Line Ctrl + Shift + D 复制当前行追加到后面 如中文意思
Delete Line 删除一行 Ctrl + Shift + K 如中文意思
Toggle Comment 启用注释 Ctrl + / 与Sublime一致
Toggle developer tools 打开Chrome调试器 Ctrl + Alt + I 神奇啊
Indent 增加缩进 Ctrl + [ 向右缩进
Outdent 减少缩进 Ctrl + ] 向左缩进
Move Line Up 行向上移动 Ctrl + up 如字面意思
Move Line Down 行向下移动 Ctrl + Down 如字面意思
Join Lines 行链接 Ctrl + J 追加
newline-below 光标之下增加一行 Ctrl + Enter 与sublime 一致
editor:newline-above 光标之上增加一行 Ctrl + Shift + Enter 与sublime 一致
pane:show-next-item 切换编辑的标签页 Ctrl + Tab 如中文意思
Fuzzy Finder 文件跳转面板 Ctrl + T 如字面意思
Select Line Move above 选中行上移 Ctrl + up 如中文意思
Select Line Move below 选中行下移 Ctrl + down 如中文意思
Symbol-view 进入变量、函数跳转面板。 Ctrl + R 如中文意思

来自:http://blog.csdn.net/crper/article/details/45674649

mariadb允许远程访问

ubuntu 安装的 mariadb 默认是不允许远程访问的,这里启用远程访问。

1​.修改数据库配置文件:sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
修改内容:将配置文件中的bind-address=127.0.0.1前面加上#号注释掉。

2.修改root的远程访问权限
sudo mysql -u root -p mysql
use mysql;

update user set host='%' where user='root';
update user set password=PASSWORD("12345678") where user="root";

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '12345678' WITH GRANT OPTION;
flush privileges;

3退出后重启一下Mariadb:
sudo service mysql restart​

修改完就可以远程访问数据库了.

树莓派控制温湿度传感器dht11

来自 http://guojianxiang.com/posts/2015-11-26-RP_Controle_Dht11.html

基于python

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
channel = 4
data = []
j = 0
GPIO.setmode(GPIO.BCM)
time.sleep(1)
GPIO.setup(channel, GPIO.OUT)
GPIO.output(channel, GPIO.LOW)
time.sleep(0.02)
GPIO.output(channel, GPIO.HIGH)
GPIO.setup(channel, GPIO.IN)
while GPIO.input(channel) == GPIO.LOW:
continue
while GPIO.input(channel) == GPIO.HIGH:
continue
while j < 40:
k = 0
while GPIO.input(channel) == GPIO.LOW:
continue
while GPIO.input(channel) == GPIO.HIGH:
k += 1
if k > 100:
break
if k < 8:
data.append(0)
else:
data.append(1)
j += 1
print "sensor is working."
print data
humidity_bit = data[0:8]
humidity_point_bit = data[8:16]
temperature_bit = data[16:24]
temperature_point_bit = data[24:32]
check_bit = data[32:40]
humidity = 0
humidity_point = 0
temperature = 0
temperature_point = 0
check = 0
for i in range(8):
humidity += humidity_bit[i] * 2 ** (7-i)
humidity_point += humidity_point_bit[i] * 2 ** (7-i)
temperature += temperature_bit[i] * 2 ** (7-i)
temperature_point += temperature_point_bit[i] * 2 ** (7-i)
check += check_bit[i] * 2 ** (7-i)
tmp = humidity + humidity_point + temperature + temperature_point
if check == tmp:
print "temperature :", temperature, "*C, humidity :", humidity, "%"
else:
print "wrong"
print "temperature :", temperature, "*C, humidity :", humidity, "% check :", check, ", tmp :", tmp
GPIO.cleanup()

ubuntu 安装shadowsocks和polipo

由于Ubuntu Server是不带用户界面的,所以要为Server配置Shadowsocks还是稍显麻烦。本文就是我配置Shadowsocks的一些经验,以待参考。

1.安装shadowsocks
由于shadowsocks是基于Python开发的,所以必须安装python:
sudo apt-get install python
接着安装python的包管理器pip:
sudo apt-get install python-pip
安装完毕之后,通过pip直接安装shadowsocks:
sudo pip install shadowsocks

2.配置shadowsocks
新建一个配置文件shadowlocal.json,然后配置相应的参数:

{
"server": "{your-server}",
"server_port": "{your-server-port}",
"local_port": 1088,
"password": "{your-password}",
"timeout": 600,
"method": "aes-256-cfb"
}
上面的参数需要你的shadowsocks服务提供商为你提供,当然你也可以自己搭建一个。搭建个人的shadowsocks服务器的话,多几个参数,执行文件是ssserver,这里赞不多说明。

配置完成后就可以启动shadowsocks客户端:

sudo sslocal -c shadowlocal.json -d start

配置全局代理
启动shadowsocks服务后,发现并不能科学上网,这是因为shadowsocks是socks 5代理,需要客户端配合才能科学。

为了让整个系统都走shadowsocks通道,需要配置全局代理,可以通过polipo实现。

3.安装polipo
sudo apt-get install polipo

4.配置polipo

修改/etc/polipo/config:

logSyslog = true
logFile = /var/log/polipo/polipo.log

proxyAddress = "0.0.0.0"

socksParentProxy = "127.0.0.1:1088"
socksProxyType = socks5

chunkHighMark = 50331648
objectHighMark = 16384

serverMaxSlots = 64
serverSlots = 16
serverSlots1 = 32
重启polipo服务:

sudo /etc/init.d/polipo restart
为终端配置http代理:

export http_proxy="http://127.0.0.1:8123/"
接着测试下能否科学上网:

curl www.google.com
如果有响应,则全局代理配置成功。

注意事项
服务器重启后,下面两句需要重新执行:

sudo sslocal -c shadowlocal.json -d start
export http_proxy="http://127.0.0.1:8123/"