ubuntu + 青云, 配置 Virtual SAN

访问量: 1240

refer to:  https://docs.qingcloud.com/guide/vsan.html

一直都很简单, 就是 "创建目标门户组" 的时候, 要在生成的名字后面, 补上一个名字. 

然后新建一个硬盘 .  把它挂到 Virtual SAN上面去. 即可. 

这样的话, 所有的 上传图片就可以放在一个地方了. 

但是青云的文档没有给出如何在ubuntu上配置 iSCSI , 参考:   https://help.ubuntu.com/lts/serverguide/iscsi-initiator.html

 $ sudo apt-get install open-iscsi 

然后修改配置文件, 让它自动启动: ( /etc/iscsi/iscsid.conf )

node.startup = automatic (记得删掉下面的 = manual )
然后, 尝试连接:  ( 这个iSCSI 的ip 是 .50) 

$ sudo iscsiadm -m discovery -t st -p 192.168.66.50

# 看到结果:  说明可以连接到 这个 SCSI . 
192.168.66.50:3260,1 iqn.2014-12.com.qingcloud.s2:sn.xx   

# 开始登录: 
$ sudo iscsiadm -m node --login
Logging in to [iface: default, target: iqn.2014-12.com.qingcloud.s2:sn.xx, portal: 192.168.66.50,3260] (multiple)
Login to [iface: default, target: iqn.2014-12.com.qingcloud.s2:sn.xx, portal: 192.168.66.50,3260] successful.

下面的步骤, 前提是你的硬盘没有做过任何分区( fdisk) , 也没有为它做任何文件系统( mkfs )

# 查看这个 iSCSI 是否已经成功加载:    (上面的 sdb 就是 新的scsi , 因为: sdb: unknown partition table )
$ dmesg | grep sd 

[    4.322384] sd 2:0:0:0: Attached scsi generic sg1 type 0
[    4.322797] sd 2:0:0:0: [sda] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
[    4.322843] sd 2:0:0:0: [sda] Write Protect is off
[    4.322846] sd 2:0:0:0: [sda] Mode Sense: 03 00 00 00
[    4.322896] sd 2:0:0:0: [sda] Cache data unavailable
[    4.322899] sd 2:0:0:0: [sda] Assuming drive cache: write through
[    4.323230] sd 2:0:0:0: [sda] Cache data unavailable
[    4.323233] sd 2:0:0:0: [sda] Assuming drive cache: write through
[    4.325312]  sda: sda1 sda2 < sda5 >
[    4.325729] sd 2:0:0:0: [sda] Cache data unavailable
[    4.325732] sd 2:0:0:0: [sda] Assuming drive cache: write through
[    4.325735] sd 2:0:0:0: [sda] Attached SCSI disk
[ 2486.941805] sd 4:0:0:3: Attached scsi generic sg3 type 0
[ 2486.952093] sd 4:0:0:3: [sdb] 1126400000 512-byte logical blocks: (576 GB/537 GiB)
[ 2486.954195] sd 4:0:0:3: [sdb] Write Protect is off
[ 2486.954200] sd 4:0:0:3: [sdb] Mode Sense: 8f 00 00 08
[ 2486.954692] sd 4:0:0:3: [sdb] Write cache: disabled, read cache: enabled, doesn't
 support DPO or FUA
[ 2486.960577]  sdb: sdb1
[ 2486.964862] sd 4:0:0:3: [sdb] Attached SCSI disk

$ sudo iscsiadm -m session -o show
tcp: [1] 192.168.88.50:3260,1 iqn.2014-12.com.qingcloud.s2:sn.store
# 查看目前已有的分区.  因为 ISCSI 挂载了一个100G的硬盘, 所以, :  sdc 就是了. 
$ cat /proc/partitions 
major minor  #blocks  name

   8        0   20971520 sda
   8        1   20969472 sda1
   8       16    1048576 sdb
   8       17          1 sdb1
   8       32  104857600 sdc
   8       33          1 sdc1

但是我输入 $ df -kh , 发现它还是不能使用. 需要给它 mount 一下: 
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  3.4G   16G  19% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            487M  4.0K  487M   1% /dev
tmpfs           100M  448K   99M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            497M     0  497M   0% /run/shm
none            100M     0  100M   0% /run/user

$ lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda          8:0    0    20G  0 disk 
└─sda1   8:1    0    20G  0 part /
sdb          8:16   0     1G  0 disk 
└─sdb1   8:17   0     1K  0 part 
sdc          8:32   0   100G  0 disk 
└─sdc1   8:33   0     1K  0 part

其他操作:

注解 如果你想在客户端重启时自动登录,请执行下面的命令:
$ iscsiadm -m node -T <目标IQN> -p  --op update -n node.startup -v automatic
卸载、登出、删除目标

$ umount /data (/data是共享存储挂载的目录)
$ iscsiadm -m node -T <目标IQN> -p  --logout
$ iscsiadm -m node -T <目标IQN> -p  --op=delete
注解 如果你想登出所有的目标,请执行下面的命令:
$ iscsiadm -m node --logout

查看 所有挂载的硬盘情况

$ sudo fdisk -l   ( 记得这里要加sudo ,否则会啥内容都没有) 

ubuntu@i-nmtx8glr:~$ sudo fdisk -l   ( 可以看出, 有 /dev/sda,  /dev/sdb/ dev/sdc 三个分区) 

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e0afd

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    41940991    20969472   83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
6 heads, 33 sectors/track, 10591 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x188f989b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2097151     1047552    5  Extended

Disk /dev/sdc: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table  # 注意这句了没有, 它还没分区.

所以,我们需要: 为它重新分区.
$ sudo fdisk /dev/sdc

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e   # 选择e ,表示用extend分区. 
Partition number (1-4, default 2): 
Using default value 2
No free sectors available

Command (m for help): w   # 让改动生效. 
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
然后,我们 $ sudo fdisk -l , 就可以看到改动生效了:
Disk /dev/sdc: 107.4 GB, 107374182400 bytes
43 heads, 44 sectors/track, 110843 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
Disk identifier: 0xeb0534b0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1           65528   209715199   104824836   83  Linux

接下来,为它做 格式化. 
$ sudo mkfs.ext4 /dev/sdc1

mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=8191 blocks
6553600 inodes, 26206209 blocks
1310310 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done  

硬盘可以使用了, mount( 挂载) 它.

$ sudo mkdir /data 
$ sudo mount /dev/sdc1 /data

$ df -kh
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  3.4G   16G  19% /
..... 
/dev/sdc1        99G   60M   94G   1% /data

可以看到,    这个100G的硬盘, 已经挂载到了 /data上. 

最后, 修改配置文件,让系统每次启动都自动加载: 

$ sudo blkid  # 查看所有的设备的UUID
/dev/sda1: UUID="fe5d9ef3-0382-4b4d-9057-f09962f7d00d" TYPE="ext4" 
/dev/sdb: LABEL="YUNIFYSWAP" UUID="b800ddd7-2e70-4b4a-b2e9-5c71ed6bff1f" TYPE="swap" 
/dev/sdc1: UUID="56e6983b-da6d-4063-8b49-be88768c731f" TYPE="ext4"

# 修改文件,  /etc/fstab  , 增加这一行:  
UUID=56e6983b-da6d-4063-8b49-be88768c731f /data ext4  defaults,auto,_netdev 0 0

订阅/RSS Feed

Subscribe

分类/category