unix:freebsd:system_builds:iscsi_target
Differences
This shows you the differences between two versions of the page.
— | unix:freebsd:system_builds:iscsi_target [2019/03/02 01:47] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== iSCSI Target ====== | ||
+ | |||
+ | ===== Set up a couple of volumes to be exported ===== | ||
+ | |||
+ | To build an iSCSI target, we need to create some space on the file system which will be exported. This can be a file, which is slow, a device, or a zfs volume. The latter has several advantages in that it is very fast, and can take advantages of zfs by taking snapshots, using checksums to maintain reliability, | ||
+ | |||
+ | <code bash> | ||
+ | # Set volmode=dev is preferred for iSCSI volumes | ||
+ | # create a zvol with compression on and checksum off. Dangerous | ||
+ | zfs create -V 10G -o volmode=dev -o checksum=off -o compression=on storage/ | ||
+ | # create a ZFS Volume named virtual_2 to be exported. | ||
+ | zfs create -V 10G -o volmode=dev storage/ | ||
+ | # zfs volumes are available under /dev/zvol | ||
+ | zfs list | ||
+ | ls / | ||
+ | </ | ||
+ | |||
+ | ===== Create Configuration File ===== | ||
+ | |||
+ | Now, we need the file which defines what our target will have available to the initiators. This is stored in / | ||
+ | |||
+ | First we define a portal group. This allows us to have the same information for the targets we create below. In this case, we are saying initiators can perform discovery with no authentication, | ||
+ | |||
+ | Following that, we define one or more targets. The target names, by convention, are | ||
+ | |||
+ | // | ||
+ | |||
+ | where domain is reversed (like reverse dns). | ||
+ | |||
+ | I have included some basic information in both targets below, basically allowing any initiator to use the target, then defining a single lun (lun 0 is required). There are many, many other things that can be done here. | ||
+ | |||
+ | <file conf ctl.conf> | ||
+ | portal-group pg0 { | ||
+ | discovery-auth-group no-authentication | ||
+ | listen 0.0.0.0: | ||
+ | listen [::]:3260 | ||
+ | } | ||
+ | |||
+ | target iqn.2019-02.com.example: | ||
+ | alias " | ||
+ | auth-group no-authentication | ||
+ | portal-group pg0 | ||
+ | |||
+ | lun 0 { | ||
+ | path / | ||
+ | } | ||
+ | } | ||
+ | |||
+ | target iqn.2019-02.com.example: | ||
+ | alias " | ||
+ | auth-group no-authentication | ||
+ | portal-group pg0 | ||
+ | |||
+ | lun 0 { | ||
+ | path / | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Start Service ===== | ||
+ | |||
+ | Now that the volumes are created and the configuration file is set up and secure, we are ready to start the iSCSI target for the first time. We'll enable the service at boot, then start it up and get a list of the devices which are available. | ||
+ | |||
+ | <code bash> | ||
+ | # enable iSCSI target on boot | ||
+ | echo ' | ||
+ | # start the service for the first time | ||
+ | service ctld start | ||
+ | # list the devices. Note the -v gives you additional information | ||
+ | ctladm devlist -v | ||
+ | </ | ||
+ | |||
+ | ===== Maintenance ===== | ||
+ | |||
+ | You can add/ | ||
+ | |||
+ | ==== Add new Volume ==== | ||
+ | |||
+ | - Add new volume to file system | ||
+ | - Add new //target// stanza in / | ||
+ | - have ctld reread configuration with **service ctld reload** | ||
+ | |||
+ | ==== Remove existing volume ==== | ||
+ | |||
+ | - Ensure no initiators are actively accessing the volume | ||
+ | - Remove //target// stanza from / | ||
+ | - restart the service with **service ctld reload** | ||
+ | |||
+ | ==== Add space to existing volume ==== | ||
+ | - Add space to volume with **zfs set volsize=15G storage/ | ||
+ | - Restart the service with **service ctld reload** | ||
+ | - Depending on how the target is utilized, you may need to perform tasks on initiators | ||
+ | |||
+ | ==== Take a snapshot of a volume ==== | ||
+ | |||
+ | < | ||
+ | zfs snap storage/ | ||
+ | </ | ||
+ | |||
+ | creates a snapshot of volume storage/ | ||
+ | |||
+ | /// | ||
+ | |||
+ | To roll back the snapshot, you must first stop access to the volume, then rollback, then re-enable access. | ||
+ | |||
+ | <code bash> | ||
+ | # comment out stanza in / | ||
+ | service ctld reload | ||
+ | # virtual_1 no longer exported | ||
+ | zfs rollback storage/ | ||
+ | # uncomment stanza for virtual_1 | ||
+ | service ctld reload | ||
+ | # original version of virtual_1 is now exported. | ||
+ | </ | ||
+ | |||
+ | But be careful doing that on a running system. | ||
+ | |||
+ | ===== References ===== | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
unix/freebsd/system_builds/iscsi_target.txt · Last modified: 2019/03/02 01:47 by 127.0.0.1