Top

iocage

——另一个jail管理器

iocage是FreeNAS使用的jail管理系统。
学习教程主要来自:
iocage 1.2 documentation
iocage@github

快速入门

安装

安装方法有三种(以下是我喜欢的排序):

首次使用


一些配置文件

/zroot/iocage/default_rc.conf

这是新jail默认会包含的内容。
主要是禁用sendmail、使用安全的系统日志、启用ipv6。新jail创建后会追加一行hostname。

/zroot/iocage/defauls.json

针对jail的默认配置,若与具体某个jail的配置冲突,则以具体某个jail的配置为准。
例如,emby的安装文档中提到:
If you're installing Emby Server into a jail, update jail.conf:
allow.mlock = 1;
ip6 = inherit;
而此文档中有"allow_mlock": 0,,所以可以修改/zroot/iocage/jails/myjail/config.json文件,加入以下行:
"allow_mlock": 1,

/zroot/iocage/jails/jailname/config.json

针对具体jail的配置,里面主要包含:
{
    "allow_mlock": 1,                             为emby手动添加
    "boot": 1,                                    自动启动,在创建jail时使用了boot=on选项
    "cloned_release": "13.1-RELEASE",             其余都是创建jail时自动添加的
    "host_hostname": "emby",
    "host_hostuuid": "emby",
    "ip4_addr": "em0|192.168.0.121/24",
    "jail_zfs_dataset": "iocage/jails/emby/data",
    "last_started": "2022-08-03 07:22:15",
    "release": "13.1-RELEASE"
}

jail的属性

使用iocage get -a jailname | UUID可以查询jail的属性:
# iocage get -a debjail
CONFIG_VERSION:27
allow_chflags:0
allow_mlock:0
allow_mount:0
allow_mount_devfs:0
allow_mount_fusefs:0
allow_mount_nullfs:0
allow_mount_procfs:0
allow_mount_tmpfs:0
allow_mount_zfs:0
allow_quotas:0
allow_raw_sockets:0
allow_set_hostname:1
allow_socket_af:0
allow_sysvipc:0
allow_tun:0
allow_vmm:0
assign_localhost:0
available:readonly
basejail:0
boot:0
bpf:0
children_max:0
cloned_release:EMPTY
comment:none
compression:lz4
compressratio:readonly
coredumpsize:off
count:1
cpuset:off
cputime:off
datasize:off
dedup:off
defaultrouter:auto
defaultrouter6:auto
depends:none
devfs_ruleset:4
dhcp:0
enforce_statfs:2
exec_clean:1
exec_created:/usr/bin/true
exec_fib:0
exec_jail_user:root
exec_poststart:/usr/bin/true
exec_poststop:/usr/bin/true
exec_prestart:/usr/bin/true
exec_prestop:/usr/bin/true
exec_start:/bin/true
exec_stop:/bin/true
exec_system_jail_user:0
exec_system_user:root
exec_timeout:60
host_domainname:none
host_hostname:debjail
host_hostuuid:debjail
host_time:1
hostid:093476f8-177e-11ed-a8bf-6cb31140491c
hostid_strict_check:0
interfaces:vnet0:bridge0
ip4:new
ip4_addr:re0|192.168.5.141
ip4_saddrsel:1
ip6:new
ip6_addr:none
ip6_saddrsel:1
ip_hostname:0
jail_zfs:0
jail_zfs_dataset:iocage/jails/debjail/data
jail_zfs_mountpoint:none
last_started:2022-08-09 03:38:17
localhost_ip:none
login_flags:-f root
mac_prefix:00e04c
maxproc:off
memorylocked:off
memoryuse:off
min_dyn_devfs_ruleset:1000
mount_devfs:1
mount_fdescfs:1
mount_linprocfs:0
mount_procfs:0
mountpoint:readonly
msgqqueued:off
msgqsize:off
nat:0
nat_backend:ipfw
nat_forwards:none
nat_interface:none
nat_prefix:172.16
nmsgq:off
notes:none
nsem:off
nsemop:off
nshm:off
nthr:off
openfiles:off
origin:readonly
owner:root
pcpu:off
plugin_name:none
plugin_repository:none
priority:99
pseudoterminals:off
quota:none
readbps:off
readiops:off
release:EMPTY
reservation:none
resolver:/etc/resolv.conf
rlimits:off
rtsold:0
securelevel:2
shmsize:off
stacksize:off
state:down
stop_timeout:30
swapuse:off
sync_state:none
sync_target:none
sync_tgt_zpool:none
sysvmsg:new
sysvsem:new
sysvshm:new
template:0
type:jail
used:readonly
vmemoryuse:off
vnet:0
vnet0_mac:none
vnet1_mac:none
vnet2_mac:none
vnet3_mac:none
vnet_default_interface:auto
vnet_interfaces:none
wallclock:off
writebps:off
writeiops:off
或者使用property_name选项获取指定的属性:
# iocage get ip4_addr debjail
re0|192.168.5.141

使用iocage set property_name="value" jail_name|UUID命令可以设置某项属性的值:
root@T1:~ # iocage set ip4_addr="re0|192.168.5.144/20" debjail
ip4_addr: re0|192.168.5.141/20 -> re0|192.168.5.144/20
root@T1:~ # iocage get ip4_addr debjail
re0|192.168.5.144
root@T1:~ # iocage list
+-----+---------+-------+---------+---------------+
| JID |  NAME   | STATE | RELEASE |      IP4      |
+=====+=========+=======+=========+===============+
| -   | debjail | down  | EMPTY   | 192.168.5.144 |
+-----+---------+-------+---------+---------------+
即使是jail在活动时也可以修改属性,且会同时修改该jail的config.json文件。
注意,修改ip时要带子网掩码,尽管list时不显示,但会影响到jail内访问网络。 某些属性不能修改,例如release,会收到如下提示:
root@T1:~ # iocage set release="Debian11" debjail
release cannot be changed by the user.

重命名jail

ezjail不能对jail进行重命名,只能使用克隆的方法来实现。而iocage却可以使用rename子命令对jail进行重命名:
# iocage rename debian11 debian-test
Jail: debian11 renamed to debian-test
但重命名后的jail处于停止状态,需要手动启动它。

更新与升级

更新和升级都是由freebsd-update来处理的。
iocage update [UUID] | [jail_name]命令会自动创建jail的备份快照。当更新完成且jail能正常运行时,可以删除快照:
# iocage update debian-test
Snapshot: zroot/iocage/jails/debian-test@ioc_update_EMPTY_2022-08-09_15-19-10 created.
Updating jail...

* Updating debian-test to the latest patch level...
Updated jail successfully.

debian-test updates have been applied successfully.
# iocage snaplist debian-test
+-------------------------------------------+-----------------------+-------+------+
|                   NAME                    |        CREATED        | RSIZE | USED |
+===========================================+=======================+=======+======+
| ioc_update_EMPTY_2022-08-09_15-19-10      | Tue Aug  9 15:19 2022 | 112K  | 0B   |
+-------------------------------------------+-----------------------+-------+------+
| ioc_update_EMPTY_2022-08-09_15-19-10/root | Tue Aug  9 15:19 2022 | 276M  | 112K |
+-------------------------------------------+-----------------------+-------+------+
# iocage snapremove -n ioc_update_EMPTY_2022-08-09_15-19-10 debian-test    此处与说明文档略有不同
Snapshot: zroot/iocage/jails/debian-test@ioc_update_EMPTY_2022-08-09_15-19-10 destroyed
# iocage snaplist debian-test
+------+---------+-------+------+
| NAME | CREATED | RSIZE | USED |
+======+=========+=======+======+
+------+---------+-------+------+

升级jail时必须为jail提供新的版本,例如:
# iocage upgrade testjail -r 13.2-RELEASE
建议使jail与宿主机保持版本同步。

克隆

从www01克隆出www02:
# iocage clone www01 --name www02
从快照克隆:
# iocage clone www01@snapshotname --name www03
升级克隆:
# iocage promote www02
这将反转克隆和源的关系。