在当前用户下执行sudo passwd,要求先输入当前用户的密码,再输入新密码,最后是确认密码,完成后就是root密码,可以与当前用户密码一致,完成后执行su root切换到root用户下,或者exit退出,以root身份登录
最近刚开始接触Linux,在虚拟机中装了个Ubuntu,当前的版本是Ubuntu 11.10,装好后自然少不了安装一些软件,在设置了软件的源后,就开始了 sudo apt-get install,结果出现了下面的Unable to locate package错误:
1.letuknowit@ubuntu:~$ sudo apt-get install mysql-server mysql-client
2.[sudo] password for letuknowit:
3.Reading package lists… Done
4.Building dependency tree
5.Reading state information… Done
6.E: Unable to locate package mysql-server
7.E: Unable to locate package mysql-client
8.letuknowit@ubuntu:~$
这叫一个郁闷啊,出师不利,不带这么吓唬刚玩Ubuntu的小朋友吧~于是赶紧找资料,又回顾下前面的操作,最后发现问题出在执行sudo apt-get install之前更换了软件源,但是却忘了update下了,于是执行下面的命令:
1.sudo apt-get update
等上面命令执行完后,再执行sudo apt-get install就可以了!其实错误信息已经很明确了,Unable to locate packet就是无法找到包嘛,那还不赶紧sudo apt-get update下!
安装iscsi
当前Linux主流iSCSI项目为open-iscsi,Linux-iSCSI项目已于2005年和open-iscsi合并。
一、安装iSCSI initiator
$ sudo apt-get install open-iscsi
二、修改iscsid.conf配置文件(重要!)
$ sudo vim/etc/iscsi/iscsid.conf
设置node.starup为automatic:
node.startup = automatic
三、查找iSCSI targets主机的target name
$ sudo iscsiadm --mode discovery --type sendtargets --portal 192.168.0.9
注:假设target主机ip为192.168.0.9
四、login target
$ sudo iscsiadm --mode node --targetname iqn.renyuannetdisk --portal 192.168.0.9:3260 --login
注:假设target name为iqn.renyuannetdisk,3260为iSCSI服务默认端口
五、iSCSI target端设置
initiator客户端执行login命令后,在target服务器端可以发现新通道。把要分配给initiator客户端的卷通过该通道映射给initiator。
六、重启客户端iscsi initiator 服务
$sudo /etc/init.d/open-iscsi restart
七、查看iscsi targets映射过来的卷
$ sudo fdisk -l
或 用dmesg 或tail -f /var/log/messages 命令查看
八、创建分区
$ sudo fdisk /dev/sdb
在提示行后输入m查看fdisk命令,输入n新建分区。
注:假设映射过来的卷设备名为sdb
九、格式化分区
$ sudo mkfs.ext3 /dev/sdb1
十、挂载文件系统
$ sudo mkdir /mnt/iscsi
$ sudo mount /dev/sdb1 /mnt/iscsi
十一、注销iSCSI initiator登录
不需要时可以注销iSCSI initiator登录,先umount文件系统,再把第四步命令的login参数改成logout执行即可:
$ sudo umount /mnt/iscsi
$ sudo iscsiadm --mode node --targetname iqn.renyuannetdisk --portal 192.168.0.9:3260 --logout
十二、删除指定Target
用logout只是暂时登出,发现的target信息会保存在数据库中,下次重启iscsi服务时(service iscsi restart),仍会找回该Target卷。如果想从数据库中删除该Target,需用以下命令:
查询数据库中Target内容:
$ sudo iscsiadm -m node
删除指定的Target:
$ sudo iscsiadm --mode node -o delete --targetnameiqn.renyuannetdisk --portal 192.168.0.9:3260
1.实验环境:
主机Win7 32位系统,Virtual Box 虚拟机Ubuntu 14.04 32位,SSH登录操作。环境问题Target和Initiator都是在同一台机器上,实际环境是可以完全分开分布于多个服务器。
2.安装Target软件:
[plain] view plaincopy
1.root@king:~# apt-cache search tgt
2....
3....
4.nagios-plugins-basic - Plugins for nagios compatible monitoring systems
5.tgt - Linux SCSI target user-space tools
6.epiphany-browser - Intuitive GNOME web browser
7....
8.python-webkit-dev - WebKit/Gtk Python bindings: development files
当系统update后可通过search查看tgt软件
[plain] view plaincopy
1.root@king:~# apt-get install tgt
2.Reading package lists... Done
3.Building dependency tree
4.Reading state information... Done
5.The following extra packages will be installed:
6. libboost-system1.54.0 libboost-thread1.54.0 libconfig-general-perl
7. libibverbs1 libnspr4 libnss3 libnss3-nssdb librados2 librbd1 librdmacm1
8. libsgutils2-2 sg3-utils
9.The following NEW packages will be installed:
10. libboost-system1.54.0 libboost-thread1.54.0 libconfig-general-perl
11. libibverbs1 libnspr4 libnss3 libnss3-nssdb librados2 librbd1 librdmacm1
12. libsgutils2-2 sg3-utils tgt
13.0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
14.Need to get 3,858 kB of archives.
15.After this operation, 13.9 MB of additional disk space will be used.
16.Do you want to continue? [Y/n] y
安装完毕后检查tgt运行状态
[plain] view plaincopy
1.Processing triggers for libc-bin (2.19-0ubuntu6) ...
2.Processing triggers for ureadahead (0.100.0-16) ...
3.root@king:~# service tgt status
4.tgt start/running, process 1690
tgt服务正在运行进程号1690
[plain] view plaincopy
1.root@king:~# ps aux |grep 1690
2.root 1690 0.0 0.3 167 3140 ? Ss 21:47 0:00 tgtd
3.root 1716 0.0 0.0 4676 824 pts/0 S+ 21:54 0:00 grep --color=auto 1690
tgtadmin help查看tgtadmin 命令参数
[plain] view plaincopy
1.root@king:~# tgtadm --help
2.Linux SCSI Target administration utility, version 1.0.43
3.
4.Usage: tgtadm [OPTION]
5.--lld 6. add a new target with 7.--lld 8. delete the specific target with 9. With force option, the specific target is deleted 10. even if there is an activity. 11.--lld 12. show all the targets. 13.--lld 14. show the specific target's parameters. 15.--lld 16. change the target parameters of the target with 17.--lld 18.--lld 19. enable the target to accept the specific initiators. 20.--lld 21.--lld 22. disable the specific permitted initiators. 23.--lld 24. --backing-store 25. add a new logical unit with 26. target with 27. to the initiators. 28. (including LVM and RAID devices) or regular files. 29. bstype option is optional. 30. bsopts are specific to the bstype. 31. bsoflags supported options are sync and direct 32. (sync:direct for both). 33.--lld 34. delete the specific logical unit with 35. the target with 36.--lld 37. add a new account with 38.--lld 39. delete the specific account having 40.--lld 41. add the specific account having 42. the specific target with 43. 44. If you use --outgoing option, the account will 45. be added as an outgoing account. 46.--lld 47. delete the specific account having 48. target. The --outgoing option must be added if you 49. delete an outgoing account. 50.--lld 51. Start the specified lld without restarting the tgtd process. 52.--control-port 53.--help 54. display this help and exit 55. 56.Report bugs to 3.创建Target tgtadmin中关于target命令如 下 [plain] view plaincopy 1.--lld 2. add a new target with 3.--lld 4. delete the specific target with 5. even if there is an activity. 6.--lld 7. show all the targets. 创建target root@king:~# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2014-0728.com:longtang [plain] view plaincopy 1.#--lld iscsi 固定参数驱动iscsi 2.#--mode target 模式target 3.#--op new 操作new新创建 4.#--tid 1 target id号 5.#--targetname ...target名称 6.#查看Target记录 [plain] view plaincopy 1. 2.root@king:~# tgtadm --lld iscsi --mode target --op show 3.Target 1: iqn.2014-0728.com:longtang 4. System information: 5. Driver: iscsi 6. State: ready 7. I_T nexus information: 8. LUN information: 9. LUN: 0 10. Type: controller 11. SCSI ID: IET 00010000 12. SCSI SN: beaf10 13. Size: 0 MB, Block size: 1 14. Online: Yes 15. Removable media: No 16. Prevent removal: No 17. Readonly: No 18. SWP: No 19. Thin-provisioning: No 20. Backing store type: null 21. Backing store path: None 22. Backing store flags: 23. Account information: 24. ACL information: 相关参数会列出,会默认创建LUN号为0的逻辑单元。 绑定initiator name,如果不操作后续Initiator可能无法发现target。 [plain] view plaincopy 1.root@king:~# tgtadm --lld iscsi --mode target --op bind --tid 1 -I ALL 上述命令为任何initiator都可以连接该target。 4.为Target新增逻辑单元 [plain] view plaincopy 1.--lld 2. --backing-store 3. add a new logical unit with 4. target with 5. to the initiators. 6. (including LVM and RAID devices) or regular files. 7. bstype option is optional. 8. bsopts are specific to the bstype. 9. bsoflags supported options are sync and direct 10. (sync:direct for both). 11.--lld 12. delete the specific logical unit with 13. the target with 命令规范如上 [plain] view plaincopy 1.root@king:~# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 -b /dev/my_volume_group/kinglv 2.root@king:~# tgtadm --lld iscsi --mode target --op show 3.Target 1: iqn.2014-0728.com:longtang 4. System information: 5. Driver: iscsi 6. State: ready 7. I_T nexus information: 8. LUN information: 9. LUN: 0 10. ... 11. Backing store flags: 12. LUN: 1 13. Type: disk 14. SCSI ID: IET 00010001 15. SCSI SN: beaf11 16. Size: 105 MB, Block size: 512 17. Online: Yes 18. Removable media: No 19. Prevent removal: No 20. Readonly: No 21. SWP: No 22. Thin-provisioning: No 23. Backing store type: rdwr 24. Backing store path: /dev/my_volume_group/kinglv 25. Backing store flags: 26. Account information: 27. ACL information: 创建逻辑单元号为1的逻辑单元,路径可以为LVM设备或者RAID设备,或者是文件。有时利用dd创建模拟文件可以作为path。 5.安装客户端软件 [plain] view plaincopy 1.root@king:~# apt-get install open-iscsi 2.Reading package lists... Done 3.Building dependency tree 4.... 检查客户端运行状态,如果未运行则开启 [plain] view plaincopy 1.root@king:~# service open-iscsi status 2.Current active iSCSI sessions: 3.iscsiadm: No active sessions. 4.root@king:~# service open-iscsi start 5. * Starting iSCSI initiator service iscsid 6.iSCSI daemon already running 6.iSCSI客户端连接Target 发现Target [plain] view plaincopy 1.root@king:~# iscsiadm -m discovery -t sendtargets -p 192.168.1.120 2.192.168.1.120:3260,1 iqn.2014-0728.com:longtang 如果上述target 的initiator name不绑定为all此处会无法发现target。 显示已发现target [plain] view plaincopy 1.root@king:~# iscsiadm -m node 2.192.168.1.120:3260,1 iqn.2014-0728.com:longtang 连接Target [plain] view plaincopy 1.root@king:~# iscsiadm -m node -p 192.168.1.120 --login 2.Logging in to [iface: default, target: iqn.2014-0728.com:longtang, portal: 192.168.1.120,3260] (multiple) 3.Login to [iface: default, target: iqn.2014-0728.com:longtang, portal: 192.168.1.120,3260] successful. 查看磁盘设备 [plain] view plaincopy 1.root@king:~# ls /dev/sd* 2./dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 /dev/sdc 3.root@king:~# fdisk -l /dev/sdc 4. 5.Disk /dev/sdc: 104 MB, 104857600 bytes 6.4 heads, 50 sectors/track, 1024 cylinders, total 204800 sectors 7.Units = sectors of 1 * 512 = 512 bytes 8.Sector size (logical/physical): 512 bytes / 512 bytes 9.I/O size (minimum/optimal): 512 bytes / 512 bytes 10.Disk identifier: 0x00000000 11. 12.Disk /dev/sdc doesn't contain a valid partition table 断开Target [plain] view plaincopy 1.root@king:~# iscsiadm -m node -p 192.168.1.120 --logout 2.Logging out of session [sid: 1, target: iqn.2014-0728.com:longtang, portal: 192.168.1.120,3260] 3.Logout of [sid: 1, target: iqn.2014-0728.com:longtang, portal: 192.168.1.120,3260] successful. 4.root@king:~# ls /dev/sd* 5./dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 发现连接和断开之间设备相差一个/dev/sdc 大小在104MB。我们底层实际存储设备LVM逻辑卷kinglv大小相近。 [plain] view plaincopy 1.root@king:~# lvdisplay /dev/my_volume_group/kinglv 2. --- Logical volume --- 3. LV Path /dev/my_volume_group/kinglv 4. LV Name kinglv 5. VG Name my_volume_group 6. LV UUID lAT5Te-obE1-Q3dY-pU4r-YYDt-rSRu-hgmKQP 7. LV Write Access read/write 8. LV Creation host, time king, 2014-07-27 14:43:41 +0800 9. LV Status available 10. # open 1 11. LV Size 100.00 MiB 12. Current LE 25 13. Segments 1 14. Allocation inherit 15. Read ahead sectors auto 16. - currently set to 256 17. Block device 252:1 如果怕指定IP什么太烦,直接连接所有Target [plain] view plaincopy 1.root@king:~# iscsiadm -m node --login all 2.Logging in to [iface: default, target: iqn.2014-0728.com:longtang, portal: 192.168.1.120,3260] (multiple) 3.Login to [iface: default, target: iqn.2014-0728.com:longtang, portal: 192.168.1.120,3260] successful. 7.iSCSI 端口号 [plain] view plaincopy 1.root@king:~# netstat -anl | grep 3260 2.tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 3.tcp6 0 0 :::3260 :::* LISTEN /etc/service 中也存在默认端口号 [plain] view plaincopy 1.... 2.icpv2 3130/tcp icp # Internet Cache Protocol 3.icpv2 3130/udp icp 4.iscsi-target 3260/tcp 5.mysql 3306/tcp 6.mysql 3306/udp 7.... 上述只是简单介绍了iSCSI的使用,方便快速建立一个基于网络的存储服务,但个Target是可以供多个Initiator连接的。更多更详细的操作大家可以自己实践。