2013年9月19日星期四

Linux 下 iSCSI target 安装配置

服务端设定
1. 下载iscsitarget 源码包,解压


2. 编译安装iscsi


3. 修改iscsi target 主配置文件/etc/ietd.conf,最简单配置,只需要修改以下三行,结果如下:


Target iqn.2001-04.com.example:storage.disk2.sys1.xyz #系统生成
Lun 0 Path=/dev/sda4,Type=fileio #根据实际情况修改
Alias Lun0 #根据实际情况修改
关于Path 的设置,看到网上有说使用dd 命令创建空文件,然后挂载这个文件的方式,以下是部分原文:
【建立磁碟檔案】
使用 dd 指令建立空白檔案作為儲存區塊,如 40GB 檔案「lun0」存放於「/home/iscsi」:
dd if=/dev/sda of=/home/iscsi/lun0 bs=1024k count=40960
或者耗時五十分鐘在檔案伺服器建立了 100GB 的儲存空間,以供 VMware ESXi Server 使用:
dd if=/dev/sda of=/home/iscsi/lun1 bs=1024k count=102400
【編輯設定檔】
sudo vi /etc/iet/ietd.conf
設定檔裡的 iqn 是 iSCSI 認證名稱 iSCSI Qualifier Name,這是 iSCSI 裝置的識別方式,一般命名原則為「iqn.日期yyyy-mm.反向網域名稱:主機名稱」,中間不能有空白,可允許最多255個字元。如:

Target iqn.2011-08.com.domain:storage.lun
Lun 0 Path=/home/iscsi/lun0,Type=fileio
4. 启动服务器,添加服务自动启动



客户端连接
1. 使用 Windows 7 自带iSCSI 发起连接工具测试。打开开始菜单,在搜索中输入iscsicpl.exe



2. 点击 目标 ,输入目标IP地址(服务器端地址),点击 快速连接




快速连接后,可以看到状态为 已连接 ,点击 完成



3. 打开 计算机管理 磁盘管理,已经可以看到新的磁盘。


至此你可以使用iSCSI 作为存储。
安全设置
由于以上配置时候,没有任何对客户端限制,所以当多个客户端连接使用同一个target时候,在实际环境中
是很不合理的,因此给target 设定固定用户名和密码,防止客户端随意连接,造成磁盘使用冲突相关问题。
1. 登录到服务器修改 /etc/ietd.conf 文件,在Target 下面找到行IncomingUser ,取消该行注释,修改相应的用户名和密码:
用户名:iqn.1991-05.com.microsoft:forme 密码:123456789012


2. 同样使用Windows 自带的iSCSI 连接程序,可以看到输入IP后默认状态是不活动 的。点连接 按钮


3. 选中 高级


4. 选中 启用CHAP登录,输入之前设置的用户名和密码 ,点击 确定


5. 可以看到目前状态变成 已连接 了。



注:这里密码比较长(12位),不得已而为之(刚开始用默认的用户名和密码,Windows 提示错误)

2013年9月6日星期五

explain 看到同一sql 使用不同索引


同一条 sql, explain 不同, type 的值不同,数据量不一样 
 
c2c2012> explain select count(`out_views`) as o, count(`in_views`) as i, count(`last_out_views`) as lo, count(`last_in_views`) as li, count(`earn_total`) as e, count(`new_earn_total`) as ne from `c2c_cpm_earn_total_log` where 1=1 AND `super` = 1 AND user_type = '5' AND dateline >= '2013-08-30 00:00:00' AND dateline <= '2013-08-30 23:59:59';
+----+-------------+------------------------+-------------+--------------------------+-----------------+---------+------+-------+-----------------------------------------------+
| id | select_type | table                  | type        | possible_keys            | key             | key_len | ref  | rows  | Extra                                         |
+----+-------------+------------------------+-------------+--------------------------+-----------------+---------+------+-------+-----------------------------------------------+
|  1 | SIMPLE      | c2c_cpm_earn_total_log | index_merge | dateline,super,user_type | user_type,super | 1,1     | NULL | 27358 | Using intersect(user_type,super); Using where |
+----+-------------+------------------------+-------------+--------------------------+-----------------+---------+------+-------+-----------------------------------------------+
1 row in set (0.00 sec)

c2c2012> explain select count(`out_views`) as o, count(`in_views`) as i, count(`last_out_views`) as lo, count(`last_in_views`) as li, count(`earn_total`) as e, count(`new_earn_total`) as ne from `c2c_cpm_earn_total_log` where 1=1 AND `super` = 1 AND user_type = '4' AND dateline >= '2013-08-30 00:00:00' AND dateline <= '2013-08-30 23:59:59';
+----+-------------+------------------------+-------+--------------------------+----------+---------+------+-------+-------------+
| id | select_type | table                  | type  | possible_keys            | key      | key_len | ref  | rows  | Extra       |
+----+-------------+------------------------+-------+--------------------------+----------+---------+------+-------+-------------+
|  1 | SIMPLE      | c2c_cpm_earn_total_log | range | dateline,super,user_type | dateline | 4       | NULL | 72778 | Using where |
+----+-------------+------------------------+-------+--------------------------+----------+---------+------+-------+-------------+
1 row in set (0.00 sec)

c2c2012>
 
 
   开发反馈从 phpmyadmin explain 执行的结果是一样的,事实肯定是以客户端为准,不知道 phpmyadmin 是通过程序直接判断sql 使用的索引呢?

升级 lograted, 让你的服务灵活的支持日期格式


/diska/htdocs/log/*.log {
   daily
   rotate 10
   notifempty
   postrotate
       day=$(date -d "yesterday" +"%Y%m%d")
       mv /diska/htdocs/log/js_error.log.1 /diska/htdocs/log/js_error.log.$day
       /home/nginx/sbin/nginx -s reopen
   endscript
}
 
 
error: /etc/logrotate.d/jserror:3 unknown option 'dateformat' -- ignoring line
 
 
 
/diska/htdocs/log/*.log {
   dateext
   dateformat .%Y%m%d
   daily
   rotate 10
   notifempty
   missingok
   postrotate
#   lastaction
   /home/nginx/sbin/nginx -s reopen
   endscript
#       day=$(date -d "yesterday" +"%Y%m%d")
#       mv /diska/htdocs/log/js_error.log.1 /diska/htdocs/log/js_error.log.$day
#   /home/nginx/sbin/nginx -s reopen
#   endscript
}
 
 
[root@app log]# logrotate -v                         
logrotate 3.7.4 - Copyright (C) 1995-2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License
 
Usage: logrotate [-dfv?] [-d|--debug] [-f|--force] [-m|--mail command]
        [-s|--state statefile] [-v|--verbose] [-?|--help] [--usage]
        [OPTION...] <configfile>
[root@app log]#
 
到 fedora 上升级 https://fedorahosted.org/logrotate/  最新的好像 3.8.5
只需要 make 和 make install