{"id":19673,"date":"2017-08-18T06:56:14","date_gmt":"2017-08-17T22:56:14","guid":{"rendered":"https:\/\/2blog.ilc.edu.tw\/25793\/2017\/08\/18\/%e5%9c%a8-centos-7-%e4%b8%8b%e5%ae%89%e8%a3%9d-iscsi-target\/"},"modified":"2021-03-18T17:25:07","modified_gmt":"2021-03-18T09:25:07","slug":"%e5%9c%a8-centos-7-%e4%b8%8b%e5%ae%89%e8%a3%9d-iscsi-target","status":"publish","type":"post","link":"https:\/\/2blog.ilc.edu.tw\/25793\/2017\/08\/18\/%e5%9c%a8-centos-7-%e4%b8%8b%e5%ae%89%e8%a3%9d-iscsi-target\/","title":{"rendered":"\u5728 CentOS 7 \u4e0b\u5b89\u88dd iSCSI Target"},"content":{"rendered":"<p>\u53c3\u8003\u7db2\u7ad9\uff1a<br \/><a href=\"https:\/\/www.server-world.info\/en\/note?os=CentOS_7&amp;p=iscsi\" target=\"_blank\" rel=\"noopener noreferrer\">CentOS 7 : Configure iSCSI Target : Server World<\/a><br \/><a href=\"http:\/\/sc8log.blogspot.tw\/2017\/03\/centos-7-iscsi-server.html\" target=\"_blank\" rel=\"noopener noreferrer\">CentOS 7 \u5b89\u88dd iSCSI Server<\/a><br \/><a href=\"http:\/\/www.itzgeek.com\/how-tos\/linux\/centos-how-tos\/configure-iscsi-target-initiator-on-centos-7-rhel7.html\" target=\"_blank\" rel=\"noopener noreferrer\">Configure iSCSI Target &amp; Initiator on CentOS 7 \/ RHEL7<\/a><\/p>\n<p>1. \u5b89\u88dd targetcli \u5957\u4ef6<br \/># <span style=\"color: #ff0000\">yum -y install targetcli<\/span><\/p>\n<p>2. \u5efa\u7acb\u76ee\u9304<br \/># <span style=\"color: #ff0000\">mkdir \/iscsi_disks<\/span>[@more@]<br \/>3. \u9032\u5165 iscsi \u7ba1\u7406\u4ecb\u9762<br \/>#<span style=\"color: #ff0000\"> \/usr\/bin\/targetcli<\/span><br \/><span style=\"color: #0000ff\">Warning: Could not load preferences file \/root\/.targetcli\/prefs.bin.<\/span><br \/><span style=\"color: #0000ff\">targetcli shell version 2.1.fb41<\/span><br \/><span style=\"color: #0000ff\">Copyright 2011-2013 by Datera, Inc and others.<\/span><br \/><span style=\"color: #0000ff\">For help on commands, type &#8216;help&#8217;.<\/span><\/p>\n<p><span style=\"color: #0000ff\">\/&gt;<\/span> <span style=\"color: #ff0000\">cd backstores\/fileio<\/span><br \/><span style=\"color: #0000ff\">\/backstores\/fileio&gt;<\/span> <span style=\"color: #ff0000\">create linux-disk \/iscsi_disks\/linux-disk.img 10G<\/span><br \/><span style=\"color: #0000ff\">Created fileio linux-disk with size 10737418240<\/span><br \/><span style=\"color: #0000ff\">\/backstores\/fileio&gt;<\/span> <span style=\"color: #ff0000\">cd \/iscsi<\/span><br \/><span style=\"color: #0000ff\">\/iscsi&gt;<\/span> <span style=\"color: #ff0000\">create iqn.2017-04.tces.test:linux.disk<\/span><br \/><span style=\"color: #0000ff\">Created target iqn.2017-04.tces.test:linux.disk.<\/span><br \/><span style=\"color: #0000ff\">Created TPG 1.<\/span><br \/><span style=\"color: #0000ff\">Global pref auto_add_default_portal=true<\/span><br \/><span style=\"color: #0000ff\">Created default portal listening on all IPs (0.0.0.0), port 3260.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi&gt;<\/span> <span style=\"color: #ff0000\">cd iqn.2017-04.tces.test:linux.disk\/tpg1\/luns<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/luns&gt;<\/span> <span style=\"color: #ff0000\">create \/backstores\/fileio\/linux-disk<\/span><br \/><span style=\"color: #0000ff\">Created LUN 0.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/luns&gt;<\/span> <span style=\"color: #ff0000\">cd ..\/acls<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/acls&gt;<\/span> <span style=\"color: #ff0000\">create iqn.2017-04.tces.test:linux-pc<\/span><br \/><span style=\"color: #0000ff\">Created Node ACL for iqn.2017-04.tces.test:linux-pc<\/span><br \/><span style=\"color: #0000ff\">Created mapped LUN 0.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/acls&gt;<\/span> <span style=\"color: #ff0000\">cd iqn.2017-04.tces.test:linux-pc<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;test:linux-pc&gt;<\/span> <span style=\"color: #ff0000\">set auth userid=user<\/span><br \/><span style=\"color: #0000ff\">Parameter userid is now &#8216;user.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;test:linux-pc&gt;<\/span> <span style=\"color: #ff0000\">set auth password=password<\/span><br \/><span style=\"color: #0000ff\">Parameter password is now &#8216;password&#8217;.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;test:linux-pc&gt;<\/span> <span style=\"color: #ff0000\">exit<\/span><br \/><span style=\"color: #0000ff\">Global pref auto_save_on_exit=true<\/span><br \/><span style=\"color: #0000ff\">Last 10 configs saved in \/etc\/target\/backup.<\/span><br \/><span style=\"color: #0000ff\">Configuration saved to \/etc\/target\/saveconfig.json<\/span><\/p>\n<p>4. \u6aa2\u67e5\u662f\u5426\u6709\u6b63\u5e38\u57f7\u884c<br \/># <span style=\"color: #ff0000\">ss -napt | grep 3260<\/span><br \/><span style=\"color: #0000ff\">LISTEN\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0 256\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *:3260\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 *:*<\/span><br \/>\u6216<br \/># n<span style=\"color: #ff0000\">etstat -napt | grep 3260<\/span><br \/><span style=\"color: #0000ff\">tcp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0 0 0.0.0.0:3260\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0.0.0.0:*\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LISTE<\/span><\/p>\n<p>5. \u9632\u706b\u7246\u8a2d\u5b9a<br \/># <span style=\"color: #ff0000\">firewall-cmd &#8211;permanent &#8211;add-service=iscsi-target<\/span><br \/># <span style=\"color: #ff0000\">firewall-cmd &#8211;reload<\/span><br \/>\u6216<br \/># <span style=\"color: #ff0000\">firewall-cmd &#8211;permanent &#8211;add-port=3260\/tcp<\/span><br \/># <span style=\"color: #ff0000\">firewall-cmd &#8211;reload<\/span><br \/>\u6216<br \/># <span style=\"color: #ff0000\">iptables -A INPUT -s 192.168.1.0\/24 -p tcp -m state &#8211;state NEW &#8211;dport 3260 -j ACCEPT<\/span><\/p>\n<p>For Windows <br \/>#<span style=\"color: #ff0000\"> \/usr\/bin\/targetcli<\/span><br \/><span style=\"color: #0000ff\">Warning: Could not load preferences file \/root\/.targetcli\/prefs.bin.<\/span><br \/><span style=\"color: #0000ff\">targetcli shell version 2.1.fb41<\/span><br \/><span style=\"color: #0000ff\">Copyright 2011-2013 by Datera, Inc and others.<\/span><br \/><span style=\"color: #0000ff\">For help on commands, type &#8216;help&#8217;.<\/span><\/p>\n<p><span style=\"color: #0000ff\">\/&gt;<\/span> <span style=\"color: #ff0000\">cd backstores\/fileio<br \/><\/span><br \/><span style=\"color: #0000ff\">\/backstores\/fileio&gt;<\/span> <span style=\"color: #ff0000\">create windows-disk \/iscsi_disks\/windows-disk.img 4G<\/span><br \/><span style=\"color: #0000ff\">Created fileio windows-disk with size 4294967296<\/span><br \/><span style=\"color: #0000ff\">\/backstores\/fileio&gt;<\/span> <span style=\"color: #ff0000\">cd \/iscsi<\/span><br \/><span style=\"color: #0000ff\">\/iscsi&gt;<\/span> <span style=\"color: #ff0000\">create iqn.2017-04.tces.test:windows.disk<\/span><br \/><span style=\"color: #0000ff\">Created target iqn.2017-04.tces.test:windows.disk.<\/span><br \/><span style=\"color: #0000ff\">Created TPG 1.<\/span><br \/><span style=\"color: #0000ff\">Global pref auto_add_default_portal=true<\/span><br \/><span style=\"color: #0000ff\">Created default portal listening on all IPs (0.0.0.0), port 3260.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi&gt;<\/span> <span style=\"color: #ff0000\">cd iqn.2017-04.tces.test:windows.disk\/tpg1\/luns<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/luns&gt;<\/span> <span style=\"color: #ff0000\">create \/backstores\/fileio\/windows-disk<\/span><br \/><span style=\"color: #0000ff\">Created LUN 0.<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/luns&gt;<\/span> <span style=\"color: #ff0000\">cd ..\/acls<\/span><br \/><span style=\"color: #0000ff\">\/iscsi\/iqn.20&#8230;isk\/tpg1\/acls&gt;<\/span> <span style=\"color: #ff0000\">create iqn.2017-04.tces.test:windows-pc<\/span><br \/><span style=\"color: #0000ff\">Created Node ACL for iqn.2017-04.tces.test:windows-pc<\/span><br \/><span style=\"color: #0000ff\">Created mapped LUN 0.<br \/>\/iscsi\/iqn.20&#8230;isk\/tpg1\/acls&gt; <span style=\"color: #ff0000\">cd \/iscsi\/iqn.2017-04.tces.test:windows.disk\/tpg1\/<\/span><br \/>\/iscsi\/iqn.20&#8230;ows.disk\/tpg1&gt; <span style=\"color: #ff0000\">set attribute authentication=0<\/span><br \/>Parameter authentication is now &#8216;0&#8217;.<br \/>\/iscsi\/iqn.20&#8230;ows.disk\/tpg1&gt; <span style=\"color: #ff0000\">cd \/iscsi\/iqn.2017-04.tces.test:windows.disk\/tpg1\/<\/span><br \/>\/iscsi\/iqn.20&#8230;ows.disk\/tpg1&gt; <span style=\"color: #ff0000\">set attribute generate_node_acls=0<\/span><br \/>Parameter generate_node_acls is now &#8216;0&#8217;.<br \/>\/iscsi\/iqn.20&#8230;ows.disk\/tpg1&gt; <span style=\"color: #ff0000\">exit<\/span><br \/>Global pref auto_save_on_exit=true<br \/>Last 10 configs saved in \/etc\/target\/backup.<br \/>Configuration saved to \/etc\/target\/saveconfig.json<br \/><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c3\u8003\u7db2\u7ad9\uff1aCentOS 7 : Configure iSCSI Target : Server WorldCe &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/2blog.ilc.edu.tw\/25793\/2017\/08\/18\/%e5%9c%a8-centos-7-%e4%b8%8b%e5%ae%89%e8%a3%9d-iscsi-target\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u5728 CentOS 7 \u4e0b\u5b89\u88dd iSCSI Target\u3009<\/span><\/a><\/p>\n","protected":false},"author":55,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117,187],"tags":[],"class_list":["post-19673","post","type-post","status-publish","format-standard","hentry","category-c-78462","category-c-105646"],"meta_key":{"_pingme":["1"],"_encloseme":["1"],"lt_post_id":["690728"]},"_links":{"self":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19673"}],"collection":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/comments?post=19673"}],"version-history":[{"count":1,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19673\/revisions"}],"predecessor-version":[{"id":21169,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/posts\/19673\/revisions\/21169"}],"wp:attachment":[{"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/media?parent=19673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/categories?post=19673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2blog.ilc.edu.tw\/25793\/wp-json\/wp\/v2\/tags?post=19673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}