CentOS7

class="prettyprint prettyprinted">yum install -y https://download.opensuse.org/repositories/shells:/fish:/release:/3/CentOS_7/x86_64/fish-3.2.1-1.2.x86_64.rpm
chsh -s /usr/bin/fish

CentOS8

class="prettyprint prettyprinted">yum install -y https://download.opensuse.org/repositories/shells:/fish:/release:/3/CentOS_8/x86_64/fish-3.2.1-1.3.x86_64.rpm
chsh -s /usr/bin/fish

Debian

class="prettyprint prettyprinted">apt update
apt install fish
chsh -s /usr/bin/fish

转自:https://www.runoob.com/w3cnote/set-ssh-login-key.html

我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器。但是,一般的密码方式登录,容易有密码被暴力破解的问题。所以,一般我们会将 SSH 的端口设置为默认的 22 以外的端口,或者禁用 root 账户登录。其实,有一个更好的办法来保证安全,而且让你可以放心地用 root 账户从远程登录——那就是通过密钥方式登录。

密钥形式登录的原理是:利用密钥生成器制作一对密钥——一只公钥和一只私钥。将公钥添加到服务器的某个账户上,然后在客户端利用私钥即可完成认证并登录。这样一来,没有私钥,任何人都无法通过 SSH 暴力破解你的密码来远程登录到系统。此外,如果将公钥复制到其他账户甚至主机,利用私钥也可以登录。

下面来讲解如何在 Linux 服务器上制作密钥对,将公钥添加给账户,设置 SSH,最后通过客户端登录。

1. 制作密钥对

首先在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令:

class="prettyprint prettyprinted">class="pun">[class="pln">root@host class="pun">~]class="pln">$ sshclass="pun">-class="pln">keygen  class="pun"><== class="pun">建立密钥对  #或生成pem:ssh-keygen -t rsa -f my.pem -C "your@email.com"
class="typ">Generating class="kwd">publicclass="pun">/class="kwd">privateclass="pln"> rsa key pairclass="pun">.
class="typ">Enterclass="pln"> file class="kwd">inclass="pln"> which to save the key class="pun">(class="str">/root/class="pun">.class="pln">sshclass="pun">/class="pln">id_rsaclass="pun">): class="pun"><== class="pun">按 class="typ">Enter
class="typ">Createdclass="pln"> directory class="str">'/root/.ssh'class="pun">.
class="typ">Enterclass="pln"> passphrase class="pun">(class="pln">empty class="kwd">for class="kwd">noclass="pln"> passphraseclass="pun">): class="pun"><== class="pun">输入密钥锁码,或直接按 class="typ">Enter class="pun">留空
class="typ">Enterclass="pln"> same passphrase againclass="pun">: class="pun"><== class="pun">再输入一遍密钥锁码
class="typ">Yourclass="pln"> identification has been saved class="kwd">in class="pun">/class="pln">rootclass="pun">/.class="pln">sshclass="pun">/class="pln">id_rsaclass="pun">. class="pun"><== class="pun">私钥
class="typ">Your class="kwd">publicclass="pln"> key has been saved class="kwd">in class="pun">/class="pln">rootclass="pun">/.class="pln">sshclass="pun">/class="pln">id_rsaclass="pun">.class="pln">pubclass="pun">. class="pun"><== class="pun">公钥
class="typ">Theclass="pln"> key fingerprint class="kwd">isclass="pun">:
class="lit">0fclass="pun">:class="pln">d3class="pun">:class="pln">e7class="pun">:class="lit">1aclass="pun">:class="lit">1cclass="pun">:class="pln">bdclass="pun">:class="lit">5cclass="pun">:class="lit">03class="pun">:class="pln">f1class="pun">:class="lit">19class="pun">:class="pln">f1class="pun">:class="lit">22class="pun">:class="pln">dfclass="pun">:class="lit">9bclass="pun">:class="pln">ccclass="pun">:class="lit">08class="pln"> root@host

密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。

现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。

2. 在服务器上安装公钥

键入以下命令,在服务器上安装公钥:

class="prettyprint prettyprinted">class="pun">[class="pln">root@host class="pun">~]class="pln">$ cd class="pun">.class="pln">ssh
class="pun">[class="pln">root@host class="pun">.class="pln">sshclass="pun">]class="pln">$ cat id_rsaclass="pun">.class="pln">pub class="pun">>>class="pln"> authorized_keys

如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:

class="prettyprint prettyprinted">class="pun">[class="pln">root@host class="pun">.class="pln">sshclass="pun">]class="pln">$ chmod class="lit">600class="pln"> authorized_keys
class="pun">[class="pln">root@host class="pun">.class="pln">sshclass="pun">]class="pln">$ chmod class="lit">700 class="pun">~/.class="pln">ssh

3. 设置 SSH,打开密钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置:

class="prettyprint prettyprinted">class="typ">RSAAuthenticationclass="pln"> yes
class="typ">PubkeyAuthenticationclass="pln"> yes

另外,请留意 root 用户能否通过 SSH 登录:

class="prettyprint prettyprinted">class="typ">PermitRootLoginclass="pln"> yes

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

class="prettyprint prettyprinted">class="typ">PasswordAuthentication class="kwd">no

最后,重启 SSH 服务:

class="prettyprint prettyprinted">class="pun">[class="pln">root@host class="pun">.class="pln">sshclass="pun">]class="pln">$ service sshd restart

4. 将私钥下载到客户端,然后转换为 PuTTY 能使用的格式

使用 WinSCP、SFTP 等工具将私钥文件 id_rsa 下载到客户端机器上。然后打开 PuTTYGen,单击 Actions 中的 Load 按钮,载入你刚才下载到的私钥文件。如果你刚才设置了密钥锁码,这时则需要输入。

载入成功后,PuTTYGen 会显示密钥相关的信息。在 Key comment 中键入对密钥的说明信息,然后单击 Save private key 按钮即可将私钥文件存放为 PuTTY 能使用的格式。

今后,当你使用 PuTTY 登录时,可以在左侧的 Connection -> SSH -> Auth 中的 Private key file for authentication: 处选择你的私钥文件,然后即可登录了,过程中只需输入密钥锁码即可。

class="submitted">转自:http://www.ithierarchy.com/ITH/node/36
class="submitted">
class="submitted">Submitted by class="username" xml:lang="">Justin on Tue, 12/17/2013 - 21:42
class="content">

class="field field-name-body field-type-text-with-summary field-label-hidden">

class="field-items">

class="field-item even">

I needed to run LSI MegaRaid Storage Manager (vivaldiframework) for my LSI 9260-8i SAS card in my Ubuntu Desktop. Ubuntu is based on Debian so this may also work to get LSI MegaRaid Storage Manager on Debian as well, but I have not yet tried it yet. It took some work but I go it to install so I thought I would tell you how I did it. It is assumed that in the following, when editing a file you are doing it with superuser rights such as opening the files from the comand prompt with "sudo nano /path/to/file/file" or "sudo vi /path/to/file/file"

I found that you need to have a GUI installed (though the install can be done completely by ssh.

root account:

If the root account has not been enabled, it will need to be enabled and have a pasword set

sudo passwd root

sudo passwd -u root

Install prerequisites:

sudo apt-get install alien libstdc++5  rcconf

You also need to install at least Java 7, I am using Java8. I followed the procedure found at: http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html and just changed java7 in the command line to java8

 

You need to download the Linux  build from LSI (http://www.lsi.com/support/pages/download-results.aspx?component=Storage+Component&productfamily=RAID+Controllers&productcode=P00066&assettype=Management+Software+and+Tools&productname=MegaRAID+SAS+9260-8i). I initially tried the latest but had some problems with it. It could very well have been a fluk but I just went back to the 13.11.01.00 version that worked just fine.

mkdir ~/LSI

cp 13.11.01.00_Linux_x64_MSM.gz ~/LSI/

cd ~/LSI/

tar xzvf 13.11.01.00_Linux_x64_MSM.gz

cd disk

sudo alien --scripts *.rpm

install deb packages

sudo dpkg --install lib-utils2_1.00-6_all.deb

sudo dpkg --install megaraid-storage-manager_13.11.01-1_all.deb

edit /etc/init.d/vivaldiframeworkd and replace the line

for ((i=0, i < 20, i++))

with

for i in `seq 0 19`

edit "/usr/local/MegaRAID Storage Manager/Framework/startupui.sh" and replace

LD_LIBRARY_PATH=`pwd`:/opt/lsi/Apache:/opt/lsi/Pegasus:/opt/lsi/openssl;export LD_LIBRARY_PATH

with

LD_LIBRARY_PATH=`pwd`:/opt/lsi/Pegasus:/usr/sbin/openssl;export LD_LIBRARY_PATH

configure the service to start automatically:

sudo rcconf

arrow down to the vivaldiframeworkd, if it does not have an "*" in it , hit the space bar to select it, then hit enter or tab to OK

 

Restart the vivaldiframeworkd service:

sudo /etc/init.d/vivaldiframeworkd restart

class="lightbox-processed" href="http://www.ithierarchy.com/ITH/sites/default/files/u72/LSIAutoStart.JPG" rel="lightbox">

if you want to use the Graphical desktop installed on you box you can access the GUI with

cd "/usr/local/MegaRAID Storage Manager"

./startupui.sh

 

转:https://my.oschina.net/u/2266513/blog/3083003

 

目前Proxmox中文社区源已正式提供镜像服务,镜像更新频率为每10小时,镜像站机房存放在法国巴黎online机房使用阿里云、华为云融合提供国内CDN加速服务。 地址 http://download.proxmox.wiki

class="hljs shell">class="hljs-meta">#class="bash"> 删除企业源
rm -rf /etc/apt/sources.list.d/pve-enterprise.list
class="hljs-meta">#class="bash">下载秘钥
wget http://download.proxmox.com/debian/proxmox-ve-release-6.x.gpg -O /etc/apt/trusted.gpg.d/proxmox-ve-release-6.x.gpg
class="hljs-meta">#class="bash"> 添加社区源
echo "deb http://download.proxmox.wiki/debian/pve stretch pve-no-subscription" >/etc/apt/sources.list.d/pve-install-repo.list

建议同时使用国内debian源

class="hljs shell">deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-data-original http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb-data-original http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-data-original http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-data-original http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib

最后执行

class="hljs shell">apt update
class="hljs-meta">#class="bash">apt update&&apt dist-upgrade class="hljs-comment">#如需升级pve,则执行该命令

最近入了一台独立服务器,如果直接拿来跑项目的话就太浪费资源了。于是打算使用Proxmox VE这款虚拟化管理软件进行VPS管理。

Proxmox VE是一款套开源的虚拟化管理软件,用户可通过网页的方式来管理服务器上使用 kvm 以及 lxc 技术运行的虚拟机。同时提供了一些先进功能的支持,如集群、HA等。

0x00 安装

Proxmox VE是基于Debian进行开发的,主要有两种安装方式。
其一是通过官方提供的iso作为一个全新的系统安装
另一种方式是在已有的Debian系统上安装
手动安装时请务必保证网卡配置正确,若出错的话在不带IPMI的机子上很难处理。

安装完成后即可通过https://ip:8006/访问管理页面

另外,这里记录一下版本升级的方法。由于Proxmox VE是一家商业公司在运营,所以一些功能是需要购买订阅才能使用的,例如说版本更新功能。但是可以通过一些方法绕过限制。注意这些更新方法请勿用于生产环境中。

将软件源更改为测试源

修改/etc/apt/sources.list.d/pve-install-repo.list, 将 pve-no-subscription 修改为pvetest
然后apt三连即可更新为新版本。

class="hljs sql">apt-get class="hljs-keyword">update
apt-class="hljs-keyword">get class="hljs-keyword">upgrade
apt-class="hljs-keyword">get dist-class="hljs-keyword">upgrade

0x01 相关设定

对于kvm虚拟化的虚拟机,若想上传需要用到的iso文件,可以直接通过网页端上传,也可以直接将文件放入/var/lib/vz/template/iso/
如果想对kvm虚拟机的启动参数进行调整,官方提供了api:qm set,具体可参照官方文档
对于lxc虚拟化的虚拟机,可以直接从系统中下载对应发行版的模板,无需自行下载。
可以直接使用LXC自带的api对lxc虚拟机进行管理,注意-n为虚拟机的id。

0x02 网络配置

对于多ip的服务器,本身官方就是按照桥接的方式做好网络配置的,直接在虚拟机中填写分配的ip即可。
对于单ip服务器,可以采用NAT的方法让虚拟机连上外部网络。这里介绍俩种方式。

采用QEMU自带的NAT

对于KVM虚拟机,可以直接在创建虚拟机的时候勾上NAT,这时候就会自动为虚拟机分配一个虚拟的子网并且虚拟机可以通过nat连接到外部网络,基本上是开箱即用。同时也支持端口映射,具体可参考官方wiki下的QEMU port redirection。但之前在使用的过程中,发现这个端口映射并不是很稳定。同时虽然这种方法很简单,但是虚拟机之间是隔离的,无法互通数据,这样就非常不灵活。
同时,LXC虚拟机是没有这种开箱即用的NAT的。

配置iptables创建子网以实现nat

主要思路是创建一个虚拟桥接设备并创建一个子网,然后将所有虚拟机包括宿主机都连接到这个子网内,再开启iptables的NAT功能。
编辑配置文件/etc/interfaces,以下是参考配置

class="hljs nginx">class="hljs-attribute">auto vmbr2
iface vmbr2 inet static
    address class="hljs-number">10.0.0.254
    netmask class="hljs-number">255.255.255.0
    bridge_ports class="hljs-literal">none
    bridge_stp class="hljs-literal">off
    bridge_fd class="hljs-number">0
    post-up echo class="hljs-number">1 > /proc/sys/net/ipv4/ip_forward
    post-up iptables -t nat -A POSTROUTING -s class="hljs-string">'10.0.0.0/24' -o vmbr0 -j MASQUERADE
    post-down iptables -t nat -D POSTROUTING -s class="hljs-string">'10.0.0.0/24' -o vmbr0 -j MASQUERADE

以上配置创建了vmbr2并且分配了一个子网10.0.0.0/24,同时宿主机(同时亦为网关)在这个子网内的ip为10.0.0.254。然后开启了内核的转发功能与iptables的NAT功能(其中vmbr0为通向外部网络的设备)。
若想添加端口转发直接在iptables中增加相关条目即可。
例如想要将宿主机vmbr0的80端口的tcp连接转发到10.0.0.102的80端口上:
iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to 10.0.0.102:80
如果想保存转发规则,使之重启后依然有效,则需要在/etc/interfaces相应位置加入

class="hljs css">class="hljs-selector-tag">post-up class="hljs-selector-tag">iptables class="hljs-selector-tag">-t class="hljs-selector-tag">nat class="hljs-selector-tag">-A class="hljs-selector-tag">PREROUTING class="hljs-selector-tag">-i class="hljs-selector-tag">vmbr0 class="hljs-selector-tag">-p class="hljs-selector-tag">tcp class="hljs-selector-tag">--dport 80 class="hljs-selector-tag">-j class="hljs-selector-tag">DNAT class="hljs-selector-tag">--to 10class="hljs-selector-class">.0class="hljs-selector-class">.0class="hljs-selector-class">.102class="hljs-selector-pseudo">:80
class="hljs-selector-tag">post-down class="hljs-selector-tag">iptables class="hljs-selector-tag">-t class="hljs-selector-tag">nat class="hljs-selector-tag">-D class="hljs-selector-tag">PREROUTING class="hljs-selector-tag">-i class="hljs-selector-tag">vmbr0 class="hljs-selector-tag">-p class="hljs-selector-tag">tcp class="hljs-selector-tag">--dport 80 class="hljs-selector-tag">-j class="hljs-selector-tag">DNAT class="hljs-selector-tag">--to 10class="hljs-selector-class">.0class="hljs-selector-class">.0class="hljs-selector-class">.102class="hljs-selector-pseudo">:80

通过以上方法就能组建一个灵活的子网了,kvm虚拟机和lxc虚拟机都可接入,并且都可以有端口转发。由于没有DHCP服务器所以要自行分配ip。注意创建虚拟机的时候将其挂载到vmbr2端口下。
我的服务器只有一个ip,所以内部组网就只能采取这种这种的方法了hhhh。为了充分利用资源,我将80,443端口转发到内部一台虚拟机上,这台虚拟机再使用nginx反代到内网的其它虚拟机,以充分利用单个ip。

启用BBR优化网络

目前的Proxmox VE版本的linux内核版本比较新,已经包含了bbr模块了。

修改sysctl.conf

class="hljs ruby">echo class="hljs-string">"net.core.default_qdisc=fq" class="hljs-meta">>> /etc/sysctl.conf
echo class="hljs-string">"net.ipv4.tcp_congestion_control=bbr" class="hljs-meta">>> /etc/sysctl.conf

保存生效

class="hljs nginx">class="hljs-attribute">sysctl -p

检测是否已启用bbr模块

class="hljs nginx">class="hljs-attribute">lsmod | grep bbr

如果含有bbr即说明内核内已启用bbr模块

实测有效方法:压缩你的镜像

方法:试着用命令或工具压缩你的镜像。

docker 自带的一些命令还能协助压缩镜像,比如 export 和 import

class="syntaxhighlighter nogutter plain">

class="code">

class="container">

class="line number1 index0 alt2">class="plain plain">$ docker run -d redis:lab-3
class="line number2 index1 alt1">
class="line number3 index2 alt2">class="plain plain">$ docker export 71b1c0ad0a2b | docker import - redis:lab-4

但麻烦的是需要先将容器运行起来,而且这个过程中你会丢失镜像原有的一些信息,比如:导出端口,环境变量,默认指令。

 

class="aligncenter size-full wp-image-3329" data-original="/app/get_remote_pic.php?file=http://img.dockerinfo.net/2016/10/20161027203227.jpg" sizes="(max-width: 650px) 100vw, 650px" data-originalset="http://img.dockerinfo.net/2016/10/20161027203227.jpg 650w, http://img.dockerinfo.net/2016/10/20161027203227-300x247.jpg 300w" alt="20161027203227" width="650" height="535" data-tag="bdshare" />

介绍

前段时间网易蜂巢曾经推出蜂巢 Logo T恤,用的正是 Docker 镜像制作,最神奇的是,它最终的镜像大小只有 585字节。

class="prettyprint">class="pln">$ docker images class="pun">|class="pln"> grep hubclass="pun">.class="pln">cclass="pun">.class="lit">163.comclass="pun">/class="kwd">publicclass="pun">/class="pln">logo

REPOSITORY                          TAG     IMAGE ID           CREATED      SIZE

hubclass="pun">.class="pln">cclass="pun">.class="lit">163.comclass="pun">/class="kwd">publicclass="pun">/class="pln">logo  latest  class="lit">6fbdd13cd204class="pln">  class="lit">11class="pln"> days ago  class="lit">585class="pln"> B

这其中就用到了不少精简镜像的技术,尤其是针对 C 程序的优化和精简。但我们平常开发肯定不止用 C 语言,甚至有些镜像都不是我们自己来打包的(比如下载公共镜像),那是否有一些通用的精简 Docker 镜像的手段呢? 答案是肯定的 ,甚至有的镜像可以精简 98%。精简镜像大小的好处不言而喻,既节省了存储空间,又能节省带宽,加快传输。那好,接下来就请跟随我来学习怎么一步步精简 Docker 镜像吧。

镜像层(Layers)

在开始制作镜像之前,首先了解下镜像的原理,而这其中最重要的概念就是镜像层(Layers)。镜像层依赖于一系列的底层技术,比如文件系统(filesystems)、写时复制(copy-on-write)、联合挂载(union mounts)等,幸运的是你可以在很多地方学习到这些技术,这里就不再赘述技术细节。

 

class="aligncenter size-full wp-image-3330" data-original="/app/get_remote_pic.php?file=http://img.dockerinfo.net/2016/10/20161027203243.jpg" sizes="(max-width: 545px) 100vw, 545px" data-originalset="http://img.dockerinfo.net/2016/10/20161027203243.jpg 545w, http://img.dockerinfo.net/2016/10/20161027203243-300x241.jpg 300w" alt="20161027203243" width="545" height="438" data-tag="bdshare" />

 

总的来说,你最需要记住这点:

在 Dockerfile 中, 每一条指令都会创建一个镜像层,继而会增加整体镜像的大小。

举例来说:

class="prettyprint">class="pln">FROM busybox

RUN mkdir class="pun">/class="pln">tmpclass="pun">/class="pln">foo

RUN dd class="kwd">ifclass="pun">=class="str">/dev/class="pln">zero ofclass="pun">=class="str">/tmp/class="pln">fooclass="pun">/class="pln">bar bsclass="pun">=class="lit">1048576class="pln"> countclass="pun">=class="lit">100class="pln">

RUN rm class="pun">/class="pln">tmpclass="pun">/class="pln">fooclass="pun">/class="pln">bar

以上 Dockerfile 干了这几件事:

  • 基于一个官方的基础镜像 busybox(只有1M多)
  • 创建一个文件夹(/tmp/foo)和一个文件(bar)
  • 为该文件分配了100M大小
  • 再把这个大文件删除

事实上,它最终什么也没做,我们把它构建成镜像看看(构建可以参考一期):

class="prettyprint">class="pln">docker build class="pun">-class="pln">t busyboxclass="pun">:class="pln">test class="pun">.

再让我们来对比下原生的 busybox 镜像大小和我们生成的镜像大小:

class="prettyprint">class="pln">$ docker images class="pun">|class="pln"> grep

busyboxbusybox    test     class="lit">896c63dbdb96class="pln">    class="lit">2class="pln"> seconds ago    class="lit">106class="pln"> MB

busybox    latest   class="lit">2b8fd9751c4cclass="pln">    class="lit">9class="pln"> weeks ago      class="lit">1.093class="pln"> MB

出乎意料的是,却生成了 106 MB 的镜像。

多出了 100 M,这是为何?这点和 git 类似(都用到了Copy-On-Write技术),我用 git 做了如下两次提交(添加了又删除),请问 A_VERY_LARGE_FILE 还在 git 仓库中吗?

class="prettyprint">class="pln">$ git add  A_VERY_LARGE_FILE

$ git commit

$ git rm  A_VERY_LARGE_FILE

$ git commit

答案是: 在的 ,并且会占用仓库的大小。Git 会保存每一次提交的文件版本,而 Dockerfile 中每一条指令都可能增加整体镜像的大小,即使它最终什么事情都没做。

精简步骤

了解了镜像层知识,有助于我们接下来制作精简镜像。这里开始,以最常用的开源缓存软件 Redis 为例,从一步步试验,来介绍如何制作更精简的 Docker 镜像

步骤 1:初始化构建 Redis 镜像

直接上 Dockerfile :

class="prettyprint">class="pln">FROM ubuntuclass="pun">:class="pln">trusty

ENV VER     class="lit">3.0class="pun">.class="lit">0class="pln">

ENV TARBALL httpclass="pun">:class="com">//download.redis.io/releases/redis-$VER.tar.gz

class="com"># ==> Install curl and helper tools...class="pln">

RUN aptclass="pun">-class="kwd">getclass="pln"> update

RUN aptclass="pun">-class="kwd">getclass="pln"> install class="pun">-class="pln">y  curl make gcc

class="com"># ==> Download, compile, and install...class="pln">

RUN curl class="pun">-class="pln">L $TARBALL class="pun">|class="pln"> tar zxv

WORKDIR  redisclass="pun">-class="pln">$VER

RUN make

RUN make install

class="com">#...

class="com"># ==> Clean up...class="pln">

WORKDIR class="pun">/class="pln">

RUN aptclass="pun">-class="kwd">getclass="pln"> remove class="pun">-class="pln">y class="pun">--class="kwd">autoclass="pun">-class="pln">remove curl make gcc

RUN aptclass="pun">-class="kwd">getclass="pln"> clean

RUN rm class="pun">-class="pln">rf class="pun">/class="kwd">varclass="pun">/class="pln">libclass="pun">/class="pln">aptclass="pun">/class="pln">listsclass="com">/*  /redis-$VER

#...

CMD ["redis-server"]

结合注释,读起来并不困难,用到的都是常规的几个命令,简要介绍如下:

  • FROM:顶头写,指定一个基础镜像,此处基于 ubuntu:trusty
  • ENV:设置环境变量,这里设置了 VER 和 TARBALL 两个环境变量
  • RUN:最常用的 Dockerfile 指令,用于运行各种命令,这里调用了 8 次 RUN 指令
  • WORKDIR:指定工作目录,相当于指令 cd
  • CMD:指定镜像默认执行的命令,此处默认执行 redis-server 命令来启动 redis

执行构建:

class="prettyprint">class="pln">$ docker build  class="pun">-class="pln">t redisclass="pun">:class="pln">labclass="pun">-class="lit">1class="pln">  class="pun">.

注:国内网络,更新下载可能会较慢

查看大小:

 

class="aligncenter size-full wp-image-3332" data-original="/app/get_remote_pic.php?file=http://img.dockerinfo.net/2016/10/20161027203303.jpg" sizes="(max-width: 435px) 100vw, 435px" data-originalset="http://img.dockerinfo.net/2016/10/20161027203303.jpg 435w, http://img.dockerinfo.net/2016/10/20161027203303-300x62.jpg 300w" alt="20161027203303" width="435" height="90" data-tag="bdshare" />

 

动辄就有 300多 M 的大小,不能忍,下面我们开始一步步优化。

步骤 2: 优化基础镜像

方法:选用更小的基础镜像。

常用的 Linux 系统镜像一般有 ubuntu、centos、debian,其中debian 更轻量,而且够用,对比如下:

class="prettyprint">class="pln">REPOSITORY     TAG        IMAGE ID           VIRTUAL SIZE

class="pun">---------------class="pln">           class="pun">------class="pln">          class="pun">------------class="pln">                class="pun">------------class="pln">

centos              class="lit">7class="pln">               class="lit">214a4932132aclass="pln">     class="lit">215.7class="pln"> MB

centos              class="lit">6class="pln">               f6808a3e4d9e      class="lit">202.6class="pln"> MB

ubuntu              trusty       d0955f21bf24      class="lit">188.3class="pln"> MB

ubuntu              precise    class="lit">9c5e4be642b7class="pln">     class="lit">131.9class="pln"> MB

debian              jessie       class="lit">65688f7c61c4class="pln">      class="lit">122.8class="pln"> MB

debian              wheezy    class="lit">1265e16d0c28class="pln">      class="lit">84.96class="pln"> MB

替换 debian:jessie 作为我们的基础镜像。

优化 Dockerfile:

class="prettyprint">class="pln">FROM debianclass="pun">:class="pln">jessie

class="com">#...

执行构建:

class="prettyprint">class="pln">$ docker build  class="pun">-class="pln">t redisclass="pun">:class="pln">labclass="pun">-class="lit">2class="pln">  class="pun">.

查看大小:

 

class="aligncenter size-full wp-image-3331" data-original="/app/get_remote_pic.php?file=http://img.dockerinfo.net/2016/10/20161027203254.jpg" sizes="(max-width: 441px) 100vw, 441px" data-originalset="http://img.dockerinfo.net/2016/10/20161027203254.jpg 441w, http://img.dockerinfo.net/2016/10/20161027203254-300x91.jpg 300w" alt="20161027203254" width="441" height="134" data-tag="bdshare" />

 

减少了42M,稍有成效,但并不明显。细心的同学应该发现,只有 122 MB 的 debian 基础镜像,构建后增加到了 305 MB,看来这里面肯定有优化的空间,如何优化就要用到我们开头说到的 Image Layer 知识了。

步骤 3:串联 Dockerfile 指令

方法: 串联你的 Dockerfile 指令(一般是 RUN 指令)。

Dockerfile 中的 RUN 指令通过 && 和 / 支持将命令串联在一起,有时能达到意想不到的精简效果。

优化 Dockerfile:

class="prettyprint">class="pln">FROM debianclass="pun">:class="pln">jessie

ENV VER     class="lit">3.0class="pun">.class="lit">0class="pln">

ENV TARBALL httpclass="pun">:class="com">//download.redis.io/releases/redis-$VER.tar.gzclass="pln">




RUN echo class="str">"==> Install curl and helper tools..."class="pln">  class="pun">&&class="pln"> \     aptclass="pun">-class="kwd">getclass="pln"> update                      class="pun">&&class="pln"> \   

  aptclass="pun">-class="kwd">getclass="pln"> install class="pun">-class="pln">y  curl make gcc   class="pun">&&class="pln"> \  

  \   

  echo class="str">"==> Download, compile, and install..."class="pln">  class="pun">&&class="pln"> \  

  curl class="pun">-class="pln">L $TARBALL class="pun">|class="pln"> tar zxv  class="pun">&&class="pln"> \   

  cd redisclass="pun">-class="pln">$VER               class="pun">&&class="pln"> \   

  make                        class="pun">&&class="pln"> \   

  make install                class="pun">&&class="pln"> \   

  class="pun">...class="pln">   

  echo class="str">"==> Clean up..."class="pln">  class="pun">&&class="pln"> \   

  aptclass="pun">-class="kwd">getclass="pln"> remove class="pun">-class="pln">y class="pun">--class="kwd">autoclass="pun">-class="pln">remove curl make gcc  class="pun">&&class="pln"> \

  aptclass="pun">-class="kwd">getclass="pln"> clean                                  class="pun">&&class="pln"> \   

  rm class="pun">-class="pln">rf class="pun">/class="kwd">varclass="pun">/class="pln">libclass="pun">/class="pln">aptclass="pun">/class="pln">listsclass="com">/*  /redis-$VER




#...

CMD ["redis-server"]

构建:

class="prettyprint">class="pln">$ docker build  class="pun">-class="pln">t redisclass="pun">:class="pln">labclass="pun">-class="lit">3class="pln">  class="pun">.

查看大小:

 

class="aligncenter size-full wp-image-3333" data-original="/app/get_remote_pic.php?file=http://img.dockerinfo.net/2016/10/20161027203318.jpg" sizes="(max-width: 437px) 100vw, 437px" data-originalset="http://img.dockerinfo.net/2016/10/20161027203318.jpg 437w, http://img.dockerinfo.net/2016/10/20161027203318-300x117.jpg 300w" alt="20161027203318" width="437" height="170" data-tag="bdshare" />

 

哇!一下子减少了 50%,效果明显啊!这是最常用的一个精简手段了。

步骤 4:压缩你的镜像

方法:试着用命令或工具压缩你的镜像。

docker 自带的一些命令还能协助压缩镜像,比如 export 和 import

class="prettyprint">class="pln">$ docker run class="pun">-class="pln">d redisclass="pun">:class="pln">labclass="pun">-class="lit">3class="pln">

$ docker class="kwd">export class="lit">71b1c0ad0a2b class="pun">|class="pln"> docker class="kwd">import class="pun">-class="pln"> redisclass="pun">:class="pln">labclass="pun">-class="lit">4

但麻烦的是需要先将容器运行起来,而且这个过程中你会丢失镜像原有的一些信息,比如:导出端口,环境变量,默认指令。

所以一般通过命令行来精简镜像都是实验性的,那么这里再推荐一个小工具: docker-squash。用起来更简单方便,并且不会丢失原有镜像的自带信息。

下载安装:

https://github.com/jwilder/docker-squash#installation(复制此链接到浏览器打开)

压缩操作:

class="prettyprint">class="pln">$ docker save redisclass="pun">:class="pln">labclass="pun">-class="lit">3class="pln"> \ 

  class="pun">|class="pln"> sudo dockerclass="pun">-class="pln">squash class="pun">-class="pln">verbose class="pun">-class="pln">t redisclass="pun">:class="pln">labclass="pun">-class="lit">4class="pln">  \ 

  class="pun">|class="pln"> docker load

注: 该工具在 Mac 下并不好使,请在 Linux 下使用

对比大小:

 

class="aligncenter size-full wp-image-3334" data-original="/app/get_remote_pic.php?file=http://img.dockerinfo.net/2016/10/20161027203328.jpg" sizes="(max-width: 435px) 100vw, 435px" data-originalset="http://img.dockerinfo.net/2016/10/20161027203328.jpg 435w, http://img.dockerinfo.net/2016/10/20161027203328-300x141.jpg 300w" alt="20161027203328" width="435" height="204" data-tag="bdshare" />

 

好吧,从这里看起来并没有太大作用,所以我只能说试着,而不要报太大期望。

总结

本期我们介绍了镜像层的知识,并且通过实验,介绍三种如何精简镜像的技巧(下期还有更强大的技巧)。这里主要介绍了三种精简方法:选用更精小的镜像,串联 Dockerfile 运行指令,以及试着压缩你的镜像。通过这几个技巧,已经可以将 300M 大小的镜像压缩到 150M,压缩率50%,效果还是不错。但这还远远不够,下篇我们将介绍一些终极手段,压缩效果可以达到 98%哦!

class="tag_link" title="View all posts in Let's Encrypt" href="http://www.laozuo.org/tag/lets-encrypt" target="_blank">Let's Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等组织人员发起,主要的目的也是为了推进网站从HTTP向HTTPS过度的进程,目前已经有越来越多的商家加入和赞助支持。

class="tag_link" title="View all posts in Let's Encrypt免费SSL" href="http://www.laozuo.org/tag/lets-encrypt%e5%85%8d%e8%b4%b9ssl" target="_blank">Let's Encrypt免费SSL证书的出现,也会对传统提供付费SSL证书服务的商家有不小的打击。到目前为止,Let's Encrypt获得IdenTrust交叉签名,这就是说可以应用且支持包括FireFox、Chrome在内的主流浏览器的兼容和支持,虽然目前是公测阶段,但是也有不少的用户在自有网站项目中正式使用起来。

class="alignnone size-full wp-image-7680" data-original="/app/get_remote_pic.php?file=https://images.laozuo.org/wp-content/uploads/2015/12/letsencrypt-1.jpg" alt="实战申请Let's Encrypt永久免费SSL证书过程教程及常见问题" width="600" height="450" />

在今年黑色星期五的时候,Namecheap各种促销活动中也包括年费0.88美元的SSL证书,当时老左也有购买了2个备用学习和适当的放到一些网站中看看效果(据说英文网站谷歌会很喜欢),当时冷雨同学就建议到时候直接使用class="tag_link" title="View all posts in Let's Encrypt免费SSL" href="http://www.laozuo.org/tag/lets-encrypt%e5%85%8d%e8%b4%b9ssl" target="_blank">Let's Encrypt免费SSL,毕竟有很多大公司支持的,比一些小公司提供的免费SSL证书靠谱很多。

虽然目前Let's Encrypt免费SSL证书默认是90天有效期,但是我们也可以到期自动续约,不影响我们的尝试和使用,为了考虑到文章的真实性和以后的实战性,老左准备利用一些时间分篇幅的展现在应用Let's Encrypt证书的过程,这篇文章分享申请的方法教程。

第一、安装Let's Encrypt前的准备工作

根据官方的要求,我们在VPS、服务器上部署Let's Encrypt免费SSL证书之前,需要系统支持Python2.7以上版本以及支持GIT工具。这个需要根据我们不同的系统版本进行安装和升级,因为有些服务商提供的版本兼容是完善的,尤其是debian环境兼容性比CentOS好一些。

比如CentOS 6 64位环境不支持GIT,我们还可以参考"Linux CentOS 6 64位系统安装Git工具环境教程"和"9步骤升级CentOS5系统Python版本到2.7"进行安装和升级。最为 简单的就是Debian环境不支持,可以运行"apt-get -y install git"直接安装支持,如果是CentOS直接运行"yum -y install git-core"支持。这个具体遇到问题在讨论和搜索解决方案,因为每个环境、商家发行版都可能不同。在这篇文章中,老左采用的是debian 7 环境。

第二、快速获取Let's Encrypt免费SSL证书

在之前的博文中老左也分享过几篇关于SSL部署的过程,我自己也搞的晕乎晕乎的,获取证书和布局还是比较复杂的,Let's Encrypt肯定是考虑到推广HTTPS的普及型会让用户简单的获取和部署SSL证书,所以可以采用下面简单的一键部署获取证书。

PS:在获取某个站点证书文件的时候,我们需要在安装PYTHON2.7以及GIT,更需要将域名解析到当前VPS主机IP中。

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto certonly --standalone --email admin@laozuo.org -d laozuo.org -d www.laozuo.org

然后执行上面的脚本,我们需要根据自己的实际站点情况将域名更换成自己需要部署的。

class="alignnone size-full wp-image-7681" data-original="/app/get_remote_pic.php?file=https://images.laozuo.org/wp-content/uploads/2015/12/letsencrypt-2.jpg" alt="快速获取Let's Encrypt免费SSL证书" width="648" height="375" />

看到这个界面,直接Agree回车。

class="alignnone size-full wp-image-7682" data-original="/app/get_remote_pic.php?file=https://images.laozuo.org/wp-content/uploads/2015/12/letsencrypt-3.jpg" alt="Let's Encrypt安装成功" width="648" height="280" />

然后看到这个界面表示部署成功。目前根据大家的反馈以及老左的测试,如果域名是用的国内DNS,包括第三那方DNSPOD等,都可能获取不到域名信息。

class="alignnone wp-image-7683 size-full" data-original="/app/get_remote_pic.php?file=https://images.laozuo.org/wp-content/uploads/2015/12/letsencrypt-4.jpg" alt="Let's Encrypt国内域名DNS不支持" width="648" height="134" />

这里我们可以看到有"The server could not connect to the client to verify the  domain"的错误提示信息,包括也有其他提示错误,"The server experienced an internal error :: Error creating new registration"我们在邮局的时候不要用国内免费邮局。所以,如果我们是海外域名就直接先用域名自带的DNS。

第三、Let's Encrypt免费SSL证书获取与应用

在完成Let's Encrypt证书的生成之后,我们会在"/etc/letsencrypt/live/laozuo.org/"域名目录下有4个文件就是生成的密钥证书文件。

cert.pem  - Apache服务器端证书
chain.pem  - Apache根证书和中继证书
fullchain.pem  - Nginx所需要ssl_certificate文件
privkey.pem - 安全证书KEY文件

如果我们使用的Nginx环境,那就需要用到fullchain.pem和privkey.pem两个证书文件,在部署Nginx的时候需要用到(参考:LNMP一键包环境安装SSL安全证书且部署HTTPS网站URL过程)。在这篇文章中老左就不详细演示Let's Encrypt证书证书的安装,后面再重新折腾一篇文章详细的部署证书的安装Nginx和Apache。

ssl_certificate /etc/letsencrypt/live/laozuo.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/laozuo.org/privkey.pem;

比如我们在Nginx环境中,只要将对应的ssl_certificate和ssl_certificate_key路径设置成我们生成的2个文件就可以,最好不要移动和复制文件,因为续期的时候直接续期生成的目录文件就可以,不需要再手工复制。

第四、解决Let's Encrypt免费SSL证书有效期问题

我们从生成的文件中可以看到,Let's Encrypt证书是有效期90天的,需要我们自己手工更新续期才可以。

./letsencrypt-auto certonly --renew-by-default --email admin@laozuo.org -d laozuo.org -d www.laozuo.org

这样我们在90天内再去执行一次就可以解决续期问题,这样又可以继续使用90天。如果我们怕忘记的话也可以制作成定时执行任务,比如每个月执行一次。

第五、关于Let's Encrypt免费SSL证书总结

通过以上几个步骤的学习和应用,我们肯定学会了利用Let's Encrypt免费生成和获取SSL证书文件,随着Let's Encrypt的应用普及,SSL以后直接免费不需要购买,因为大部分主流浏览器都支持且有更多的主流商家的支持和赞助,HTTPS以后看来也是趋势。在Let's Encrypt执行过程在中我们需要解决几个问题。

A - 域名DNS和解析问题。在配置Let's Encrypt免费SSL证书的时候域名一定要解析到当前VPS服务器,而且DNS必须用到海外域名DNS,如果用国内免费DNS可能会导致获取不到错误。

B - 安装Let's Encrypt部署之前需要服务器支持PYTHON2.7以及GIT环境,要不无法部署。

C - Let's Encrypt默认是90天免费,需要手工或者自动续期才可以继续使用。

本文固定链接: http://www.laozuo.org/7676.html | 老左博客

转:http://www.senra.me/remove-proxmox-ve-dont-have-valid-subscription-notice/

一.问

最近把我的OVH独服重装了下,打算用Proxmox开点VM来用,省得一直吃灰(雾,安装很简单,毕竟是OVH提供的模板,但是,这玩意每次登陆都会有个蛋疼的提示(You do not have a valid subscription for this server. Please visit www.class="st_tag internal_tag" title="Posts tagged with proxmox" href="http://www.senra.me/tag/proxmox/" rel="tag">proxmox.com to get a list of available options.),而且找了半天没找到有关的地方,然后去官网看了下订阅的价格,呵呵呵,我还是自己想办法吧……

class="alignnone size-full wp-image-454 sl_lazyimg" data-original="/app/get_remote_pic.php?file=http://ucdn.senra.me/2017/04/proxmoxve_invalid_sub_notice.png" alt="" width="679" height="204" />

二.解

对于一个网页,要明白它到底发生了什么,那当然是直接F12怼一波,看了下控制台发现有个pvemanagerlib.js,看看名字就觉得很像是这玩意在搞事啊,右击在新页面打开,看看内容,首先根据之前的提示文字来搜索

class="alignnone size-full wp-image-456 responsively-lazy" data-original="/app/get_remote_pic.php?file=http://ucdn.senra.me/2017/04/pve_warn_text.png" sizes="(max-width: 1589px) 100vw, 1589px" data-originalset="http://cdn.senra.me/wp-content/uploads/2017/04/pve_warn_text-768x100.png" alt="" width="1589" height="206" data-data-originalset="http://cdn.senra.me/wp-content/uploads/2017/04/pve_warn_text.png 1589w, http://cdn.senra.me/wp-content/uploads/2017/04/pve_warn_text-768x100.png 768w" />

很好,找到目标,然后再次搜索noSubKeyHtml

class="alignnone size-full wp-image-457 sl_lazyimg" data-original="/app/get_remote_pic.php?file=http://ucdn.senra.me/2017/04/pve_warn_action.png" alt="" width="641" height="461" />

一切顺利,找到了执行订阅检测的地方,现在简单了,直接改判断条件或者怼掉show操作都行,问题来了,这个文件在浏览器里又不能改,它到底在哪?

其实很简单,随便locate一下就找到了,我们先用cp备份一下,然后开始修改这个文件

class="alignnone size-full wp-image-455 sl_lazyimg" data-original="/app/get_remote_pic.php?file=http://ucdn.senra.me/2017/04/pvemanagerlibjs_loc.png" alt="" width="371" height="82" />

然后注销重新登录,一切OK,世界清静

转:http://www.senra.me/add-internal-adapter-for-proxmox-to-secure-intranet-communication/

一.锲子

最近在配置hadoop过程中为了让各节点使用内网通信,研究了下怎么在proxmox下添加内网地址,一开始觉得挺容易,然后发现有点小坑,记录下。

二.Here We Go

首先需要在宿主机上添加个内网网卡,可以使用Proxmox添加,也可以直接改配置文件,效果一样,面板如下,vlan aware随意

class="alignnone size-full wp-image-463 sl_lazyimg" data-original="/app/get_remote_pic.php?file=http://ucdn.senra.me/2017/04/proxmox_internal_br.png" alt="" width="598" height="294" />

编辑文件的话需要修改/etc/network/interfaces ,添加如下,同样vlan aware 随意

class="crayon-syntax crayon-theme-sublime-text crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" minimize scroll-mouseover disable-anim wrap">

class="crayon-plain-wrap">
class="crayon-main">

class="crayon-table">

class="crayon-row">

class="crayon-nums " data-settings="show">

class="crayon-nums-content">

class="crayon-num" data-line="crayon-591f5d6631ec0066478681-1">1
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-2">2
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-3">3
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-4">4
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-5">5
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-6">6
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-7">7
class="crayon-num" data-line="crayon-591f5d6631ec0066478681-8">8
class="crayon-code">

class="crayon-pre">

class="crayon-line">class="crayon-e">auto class="crayon-e">vmbr2
class="crayon-line">class="crayon-e">iface class="crayon-e">vmbr2 class="crayon-e">inet class="crayon-m">static
class="crayon-line">class="crayon-i">address class="crayon-cn">10.10.10.254
class="crayon-line">class="crayon-i">netmask class="crayon-cn">255.255.255.0
class="crayon-line">class="crayon-e">bridge_ports class="crayon-e">none
class="crayon-line">class="crayon-e">bridge_stp class="crayon-e">off
class="crayon-line">class="crayon-v">bridgeclass="crayon-sy">_fd class="crayon-cn">0
class="crayon-line">class="crayon-e">bridge_vlan_aware class="crayon-v">yes

之后我们便为宿主机添加了一个内网网卡,地址为10.10.10.254

之后我们在创建的容器或是虚拟机上同样添加一个网卡,mac地址会自动生成,网关就写宿主机的,桥接写我们添加的那个网卡,然后就可以了

class="alignnone size-full wp-image-464 sl_lazyimg" data-original="/app/get_remote_pic.php?file=http://ucdn.senra.me/2017/04/proxmox_vm_internal_eth.png" alt="" width="600" height="265" />

PS.需要注意的有一点,先加内网地址后加外网地址,否则默认路由会是内网,这个是个坑,我一开始没在意然后发现怎么也访问不了

转:http://www.senra.me/add-tun-tap-support-for-proxmox-ve-4-lxc-containers/

一.为什么

class="st_tag internal_tag" title="Posts tagged with proxmox" href="http://www.senra.me/tag/proxmox/" rel="tag">Proxmox VE 4将3代的OpenVZ支持去除换成了LXC,算是跟随趋势吧,但是LXC和OpenVZ还是有挺多不同的,在权限上更是如此,而网上最多的还是OVZ相关的教程,LXC的是真的少,不过一直以来没需求,所以没怎么折腾,最近在搞内网,所以为了用Tunnel还是得把TUN/TAP支持打开。

二.怎么办

首先当然是谷歌咯,关键词选得好马上出结果,proxmox官方论坛讨论贴 https://forum.class="st_tag internal_tag" title="Posts tagged with proxmox" href="http://www.senra.me/tag/proxmox/" rel="tag">proxmox.com/threads/class="st_tag internal_tag" title="Posts tagged with tun" href="http://www.senra.me/tag/tun/" rel="tag">tun-devices-in-ve-4-class="st_tag internal_tag" title="Posts tagged with lxc" href="http://www.senra.me/tag/lxc/" rel="tag">lxc.23473

总结一下

①.如果需要对所有(之后创建的)LXC容器全部开启tun/class="st_tag internal_tag" title="Posts tagged with tap" href="http://www.senra.me/tag/tap/" rel="tag">tap

那么需要修改/etc/class="st_tag internal_tag" title="Posts tagged with lxc" href="http://www.senra.me/tag/lxc/" rel="tag">lxc/default.conf,添加lxc.cgroup.devices.allow = c 10:200 rwm

当然,也可以创建/usr/share/class="st_tag internal_tag" title="Posts tagged with lxc" href="http://www.senra.me/tag/lxc/" rel="tag">lxc/config/common.conf.d/02-tuntap.conf 这样的配置文件来取得同样的效果

②.而如果只要对指定容器有效,则需要修改/etc/pve/class="st_tag internal_tag" title="Posts tagged with lxc" href="http://www.senra.me/tag/lxc/" rel="tag">lxc/[ID].conf , [ID]为你的容器编号

还没完,这样只是给了权限,实际上还没好,需要在容器的/etc/rc.local 自启动文件中添加如下

class="crayon-syntax crayon-theme-sublime-text crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" minimize scroll-mouseover disable-anim wrap">

class="crayon-plain-wrap">
class="crayon-main">

class="crayon-table">

class="crayon-row">

class="crayon-nums " data-settings="show">

class="crayon-nums-content">

class="crayon-num" data-line="crayon-591f5d6797a17631646175-1">1
class="crayon-num" data-line="crayon-591f5d6797a17631646175-2">2
class="crayon-num" data-line="crayon-591f5d6797a17631646175-3">3
class="crayon-num" data-line="crayon-591f5d6797a17631646175-4">4
class="crayon-code">

class="crayon-pre">

class="crayon-line">class="crayon-st">if class="crayon-o">! class="crayon-sy">[ class="crayon-o">-class="crayon-i">c class="crayon-o">/class="crayon-v">devclass="crayon-o">/class="crayon-v">netclass="crayon-o">/class="crayon-i">tun class="crayon-sy">]class="crayon-sy">; class="crayon-st">then
class="crayon-line"> class="crayon-i">mkdir class="crayon-o">-class="crayon-i">p class="crayon-o">/class="crayon-v">devclass="crayon-o">/class="crayon-i">net
class="crayon-line"> class="crayon-i">mknod class="crayon-o">-class="crayon-i">m class="crayon-cn">666 class="crayon-o">/class="crayon-v">devclass="crayon-o">/class="crayon-v">netclass="crayon-o">/class="crayon-i">tun class="crayon-i">c class="crayon-cn">10 class="crayon-cn">200
class="crayon-line">class="crayon-v">fi

这样你执行需要tun/tap的程序时就不会出问题了

三.附录(记如何在v3版本的ovz下开启tun/class="st_tag internal_tag" title="Posts tagged with tap" href="http://www.senra.me/tag/tap/" rel="tag">tap)

a. 编辑vz.conf文件,添加iptable_nat ipt_state这2个东西

class="crayon-syntax crayon-theme-sublime-text crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" minimize scroll-mouseover disable-anim wrap">

class="crayon-plain-wrap">
class="crayon-main">

class="crayon-table">

class="crayon-row">

class="crayon-nums " data-settings="show">

class="crayon-nums-content">

class="crayon-num" data-line="crayon-591f5d6797a28457795064-1">1
class="crayon-num" data-line="crayon-591f5d6797a28457795064-2">2
class="crayon-num" data-line="crayon-591f5d6797a28457795064-3">3
class="crayon-code">

class="crayon-pre">

class="crayon-line">class="crayon-v">vi class="crayon-o">/class="crayon-v">etcclass="crayon-o">/class="crayon-v">vzclass="crayon-o">/class="crayon-v">vzclass="crayon-sy">.class="crayon-e">conf
class="crayon-line">class="crayon-v">IPTABLESclass="crayon-o">=class="crayon-s">" ***" 这一行的引号内添加class="crayon-cn">2个模块
class="crayon-line">class="crayon-e">iptable_nat class="crayon-v">ipt_state

b. 手动关闭所有小鸡,重启openvz模块
/etc/init.d/vz restart

c. 对小鸡进行必要的设置(这里以小鸡100为例,100是指PID,WEB控制面板里可以看到)

class="crayon-syntax crayon-theme-sublime-text crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" minimize scroll-mouseover disable-anim wrap">

class="crayon-plain-wrap">
class="crayon-main">

class="crayon-table">

class="crayon-row">

class="crayon-nums " data-settings="show">

class="crayon-nums-content">

class="crayon-num" data-line="crayon-591f5d6797a30036159179-1">1
class="crayon-num" data-line="crayon-591f5d6797a30036159179-2">2
class="crayon-code">

class="crayon-pre">

class="crayon-line">class="crayon-e">vzctl class="crayon-i">set class="crayon-cn">100 class="crayon-o">--class="crayon-i">devices class="crayon-v">cclass="crayon-o">:class="crayon-cn">10class="crayon-o">:class="crayon-cn">200class="crayon-o">:class="crayon-v">rw class="crayon-o">--class="crayon-e">save
class="crayon-line">class="crayon-e">vzctl class="crayon-i">set class="crayon-cn">100 class="crayon-o">--class="crayon-e">capability class="crayon-v">net_adminclass="crayon-o">:class="crayon-v">on class="crayon-o">--class="crayon-v">save

d. 母鸡加载一次这些

class="crayon-syntax crayon-theme-sublime-text crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" minimize scroll-mouseover disable-anim wrap">

class="crayon-plain-wrap">
class="crayon-main">

class="crayon-table">

class="crayon-row">

class="crayon-nums " data-settings="show">

class="crayon-nums-content">

class="crayon-num" data-line="crayon-591f5d6797a38622110841-1">1
class="crayon-num" data-line="crayon-591f5d6797a38622110841-2">2
class="crayon-num" data-line="crayon-591f5d6797a38622110841-3">3
class="crayon-num" data-line="crayon-591f5d6797a38622110841-4">4
class="crayon-num" data-line="crayon-591f5d6797a38622110841-5">5
class="crayon-num" data-line="crayon-591f5d6797a38622110841-6">6
class="crayon-num" data-line="crayon-591f5d6797a38622110841-7">7
class="crayon-num" data-line="crayon-591f5d6797a38622110841-8">8
class="crayon-num" data-line="crayon-591f5d6797a38622110841-9">9
class="crayon-num" data-line="crayon-591f5d6797a38622110841-10">10
class="crayon-num" data-line="crayon-591f5d6797a38622110841-11">11
class="crayon-num" data-line="crayon-591f5d6797a38622110841-12">12
class="crayon-num" data-line="crayon-591f5d6797a38622110841-13">13
class="crayon-num" data-line="crayon-591f5d6797a38622110841-14">14
class="crayon-num" data-line="crayon-591f5d6797a38622110841-15">15
class="crayon-num" data-line="crayon-591f5d6797a38622110841-16">16
class="crayon-num" data-line="crayon-591f5d6797a38622110841-17">17
class="crayon-num" data-line="crayon-591f5d6797a38622110841-18">18
class="crayon-num" data-line="crayon-591f5d6797a38622110841-19">19
class="crayon-code">

class="crayon-pre">

class="crayon-line">class="crayon-e">modprobe class="crayon-e">ipt_mark
class="crayon-line">class="crayon-e">modprobe class="crayon-e">ipt_MARK
class="crayon-line">class="crayon-e">modprobe class="crayon-e">ip_nat_pptp
class="crayon-line">class="crayon-e">modprobe class="crayon-e">nf_nat_pptp
class="crayon-line">class="crayon-e">modprobe class="crayon-e">tun
class="crayon-line">class="crayon-e">modprobe class="crayon-e">ppp_async
class="crayon-line">class="crayon-e">modprobe class="crayon-v">pppclass="crayon-sy">_deflate
class="crayon-line">
class="crayon-line">或者
class="crayon-line">class="crayon-v">vi class="crayon-o">/class="crayon-v">etcclass="crayon-o">/class="crayon-e">modules
class="crayon-line">class="crayon-e">ipt_mark
class="crayon-line">class="crayon-e">ipt_MARK
class="crayon-line">class="crayon-e">ip_nat_pptp
class="crayon-line">class="crayon-e">nf_nat_pptp
class="crayon-line">class="crayon-e">tun
class="crayon-line">class="crayon-e">ppp_async
class="crayon-line">class="crayon-v">pppclass="crayon-sy">_deflate
class="crayon-line">查看是否启用模块
class="crayon-line">class="crayon-v">lsmod class="crayon-o">| class="crayon-e">grep class="crayon-v">nf_nat_pptp

e. 启动小鸡输入以下命令

class="crayon-syntax crayon-theme-sublime-text crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" minimize scroll-mouseover disable-anim wrap">

class="crayon-plain-wrap">
class="crayon-main">

class="crayon-table">

class="crayon-row">

class="crayon-nums " data-settings="show">

class="crayon-nums-content">

class="crayon-num" data-line="crayon-591f5d6797a40794958489-1">1
class="crayon-num" data-line="crayon-591f5d6797a40794958489-2">2
class="crayon-num" data-line="crayon-591f5d6797a40794958489-3">3
class="crayon-code">

class="crayon-pre">

class="crayon-line">class="crayon-v">mkdir class="crayon-o">-class="crayon-v">p class="crayon-o">/class="crayon-v">devclass="crayon-o">/class="crayon-e">net
class="crayon-line">class="crayon-v">mknod class="crayon-o">/class="crayon-v">devclass="crayon-o">/class="crayon-v">netclass="crayon-o">/class="crayon-i">tun class="crayon-i">c class="crayon-cn">10 class="crayon-cn">200
class="crayon-line">class="crayon-i">chmod class="crayon-cn">600 class="crayon-o">/class="crayon-v">devclass="crayon-o">/class="crayon-v">netclass="crayon-o">/class="crayon-v">tun
class="st-post-tags">