Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:Guangdong Locality Name (eg, city) []:ZhuHai Organization Name (eg, company) [Internet Widgits Pty Ltd]:google_test.cn Team Organizational Unit Name (eg, section) []:BiNoL Project Common Name (e.g. server FQDN or YOUR name) []:google_test.cn Email Address []:postmaster@google_test.cn Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
// 标准语法 {{value}} {{data.key}} {{data['key']}} {{a ? b : c}} {{a || b}} {{a + b}} // 原始语法 <%= value %> <%= data.key %> <%= data['key'] %> <%= a ? b : c %> <%= a || b %> <%= a + b %>
3.3 原文输出
1
// 标准语法 {{@ value}} // 原始语法 <%- value %>
3.4 条件输出
1 2 3 4 5 6 7 8 9 10 11 12 13
// 标准语法
<!-- 单 if 判断 --> {{if value}} ... {{/if}}
<!-- if ... else ... 判断 --> {{if v1}} ... {{else if v2}} ... {{/if}} // 原始输出
<!-- 单 if 判断 --> <% if (value) { %> ... <% } %>
<!-- if ... else ... 判断 --> <% if (v1) { %> ... <% else if (v2) { %> ... <% } %>
[root@MyVPS ~]# fdisk -l //*查看硬盘分区情况*// Disk /dev/xvda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/xvda1 * 1 13 104391 83 Linux /dev/xvda2 14 1044 8281507+ 8e Linux LVM /dev/xvda3 1045 1305 2096482+ 8e Linux LVM Disk /dev/xvdb: 7516 MB, 7516192768 bytes 255 heads, 63 sectors/track, 913 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/xvdb doesn't contain a valid partition table [root@MyVPS ~]#df -hal //*查看已划分区空间使用情况*// Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 9.3G 1.2G 7.7G 13% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/xvda1 99M 29M 66M 31% /boot tmpfs 151M 0 151M 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs [root@MyVPS ~]#fdisk /dev/xvdb //*对硬盘/dev/xvdb进行增加分区操作*// Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m forhelp):n //*输入n新建分区*// Command action e extended p primary partition (1-4) p //*输入p,主分区*// Partition number (1-4): 1 //*由于xvdb还没有分区.我们这里输入1.第1个分区*// First cylinder (1-913, default 1)://*回车跳过*// Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-913, default 913)://*回车跳过*// Using default value 913 Command (m forhelp): t //*通过t来指定分区系统格式*// Selected partition 1 Hex code (type L to list codes):8e //*输入8e LVM系统格式*// Changed system type of partition 1 to 8e (Linux LVM) Command (m forhelp):w //*输入w保存退出*// The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@MyVPS ~]#reboot //*重启使之生效*// Broadcast message from root (pts/0) (Mon Aug 15 00:43:03 2011): The system is going down for reboot NOW! [root@MyVPS ~]# Connection closed by foreign host. Type `help' to learn how to use Xshell prompt. Xshell:\> Connecting to :22... Connection established. Escape character is '^@]'. Last login: Mon Aug 15 00:41:06 2011 from [root@MyVPS1280 ~]#fdisk -l //*查看硬盘分区情况*// Disk /dev/xvda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/xvda1 * 1 13 104391 83 Linux /dev/xvda2 14 1044 8281507+ 8e Linux LVM /dev/xvda3 1045 1305 2096482+ 8e Linux LVM Disk /dev/xvdb: 7516 MB, 7516192768 bytes 255 heads, 63 sectors/track, 913 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/xvdb1 1 913 7333641 8e Linux LVM [root@MyVPS1280 ~]#pvcreate /dev/xvdb1 //*创建物理卷*// Physical volume "/dev/xvdb1" successfully created [root@MyVPS1280 ~]#vgextend VolGroup00 /dev/xvdb1 //*将物理卷加入到组VolGroup00 *// Volume group "VolGroup00" successfully extended [root@MyVPS1280 ~]# vgdisplay //*查看物理卷组情况.可以看到我们有6.97G的容量可以扩展*// --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size 16.81 GB PE Size 32.00 MB Total PE 538 Alloc PE / Size 315 / 9.84 GB Free PE / Size 223 / 6.97 GB VG UUID ONGPxy-HBvY-xrrQ-IjEW-PIiO-2cX7-tg6tuI [root@MyVPS1280 ~]# lvresize -L +6G /dev/VolGroup00/LogVol00 //*扩容6G(我们第一次加6G)*// Extending logical volume LogVol00 to 15.59 GB Logical volume LogVol00 successfully resized [root@MyVPS1280 ~]#resize2fs /dev/VolGroup00/LogVol00 //*动态扩容分区大小*// resize2fs 1.39 (29-May-2006) Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required Performing an on-line resize of /dev/VolGroup00/LogVol00 to 4087808 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol00 is now 4087808 blocks long. [root@MyVPS1280 ~]# vgdisplay //*查看物理卷组情况.可以看到我们还有992M的容量可以扩展*// --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size 16.81 GB PE Size 32.00 MB Total PE 538 Alloc PE / Size 507 / 15.84 GB Free PE / Size 31 / 992.00 MB VG UUID ONGPxy-HBvY-xrrQ-IjEW-PIiO-2cX7-tg6tuI [root@MyVPS1280 ~]# lvresize -L +992M /dev/VolGroup00/LogVol00 //*扩容992M(我们第2次加992M)*// Extending logical volume LogVol00 to 16.56 GB Logical volume LogVol00 successfully resized [root@MyVPS1280 ~]# resize2fs /dev/VolGroup00/LogVol00 //*动态扩容分区大小*// resize2fs 1.39 (29-May-2006) Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required Performing an on-line resize of /dev/VolGroup00/LogVol00 to 4341760 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol00 is now 4341760 blocks long. [root@MyVPS1280 ~]#vgdisplay //*最后再查看扩容完没有 可以看到已经扩容完毕*// --- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size 16.81 GB PE Size 32.00 MB Total PE 538 Alloc PE / Size 538 / 16.81 GB Free PE / Size 0 / 0 VG UUID ONGPxy-HBvY-xrrQ-IjEW-PIiO-2cX7-tg6tuI [root@MyVPS1280 ~]# df -hal //*查看已划分区空间使用情况 可以看到我们挂载成功*// Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 17G 1.2G 15G 8% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/xvda1 99M 29M 66M 31% /boot tmpfs 151M 0 151M 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs //*至此硬盘挂载成功*//
三、常见问题
Q1 挂载过程中错误如何卸载
1 2 3 4 5 6
mount /dev/xvdb1 /mnt df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 40G 1.5G 36G 4% / tmpfs 498M 0 498M 0% /dev/shm /dev/xvdb1 5.0G 139M 4.6G 3% /mnt
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # this script create it by caffreyxin at 2007.10.15. # it is v.0.0.1 version. # if you find any errors on this scripts, please contact caffreyxin. # and send mail to xinyflove at sina dot com. # # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf
Making all in lib make[1]: Entering directory `/usr/local/src/keepalived-1.2.24/lib' make all-am make[2]: Entering directory `/usr/local/src/keepalived-1.2.24/lib' make[2]: Leaving directory `/usr/local/src/keepalived-1.2.24/lib' make[1]: Leaving directory `/usr/local/src/keepalived-1.2.24/lib' Making all in keepalived make[1]: Entering directory `/usr/local/src/keepalived-1.2.24/keepalived' Making all in core make[2]: Entering directory `/usr/local/src/keepalived-1.2.24/keepalived/core' CC namespaces.o namespaces.c: In function ‘setns’: namespaces.c:184: error: ‘__NR_setns’ undeclared (first use in this function) namespaces.c:184: error: (Each undeclared identifier is reported only once namespaces.c:184: error: for each function it appears in.) make[2]: *** [namespaces.o] Error1 make[2]: Leaving directory `/usr/local/src/keepalived-1.2.24/keepalived/core' make[1]: *** [all-recursive] Error1 make[1]: Leaving directory `/usr/local/src/keepalived-1.2.24/keepalived' make: *** [all-recursive] Error1
nginx version: nginx/1.14.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=/data/wwwroot/ftp/fastdfs-nginx-module/src
看到以上提示即添加成功。
3、浅入理解 FastDFS
3.1. 什么是 FastDFS
FastDFS 是用 C 语言编写的一款开源的分布式文件系统。FastDFS 为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用 FastDFS 很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。
3.2 文件上传流程
2.3 文件下载流程
2.3 文件访问流程
客户端上传文件后存储服务器将文件 ID 返回给客户端,此文件 ID 用于以后访问该文件的索引信息。文件索引信息包括:组名,虚拟磁盘路径,数据两级目录,文件名。
修改/etc/fdfs/tracker.conf 文件 vi tracker.conf 编辑代码 键盘按下“i”键入,开始修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# is this config file disabled # false for enabled # true for disabled disabled=false # bind an address of this host # empty for bind all addresses of this host bind_addr= # the tracker server port port=22122 # connect timeout in seconds # default value is 30s connect_timeout=30 # network timeout in seconds # default value is 30s network_timeout=60 # the base path to store data and log files base_path=/data/wwwroot/fastdfs/tracker
修改/etc/fdfs/storage.conf 文件 vi storage.conf 编辑代码 键盘按下“i”键入,开始修改 值得注意几个地方:
1 2
# the port of the web server on this storage server http.server_port=8888
注意,Server 的 port 端口为 8888
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# true for binding the address configed by above parameter: "bind_addr" # false for binding any address of this host client_bind=true # the storage server port port=23000 # connect timeout in seconds # default value is 30s connect_timeout=30 # network timeout in seconds # default value is 30s network_timeout=60 # heart beat interval in seconds heart_beat_interval=30 # disk usage report interval in seconds stat_report_interval=60 # the base path to store data and log files base_path=/data/wwwroot/fastdfs/storage
base_path 依旧换成你需要的存放图片路径,实际存在的
1 2 3
# store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist store_path0=/data/wwwroot/fastdfs/storage
base_path0 换成你需要的首要存放图片路径,于上面相对应,实际存在的
1 2 3
# tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=139.129.30.222:22122
修改/etc/fdfs/client.conf 文件 vi client.conf 编辑代码 键盘按下“i”键入,开始修改
1 2 3 4 5 6 7 8 9 10 11
# connect timeout in seconds # default value is 30s connect_timeout=30 # network timeout in seconds # default value is 30s network_timeout=60 # the base path to store log files base_path=/data/wwwroot/fastdfs/client # tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=139.129.30.222:22122
# specify storage ids filename, can use relative or absolute path # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # since V1.13 storage_ids_filename = storage_ids.conf # FastDFS tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true tracker_server=139.129.30.222:22122 # the port of the local storage server # the default value is 23000 storage_server_port=23000 # the group name of the local storage server group_name=group1 # if the url / uri including the group name # set to false when uri like /M00/00/00/xxx # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx # default value is false url_have_group_name = true
注意的是,Tracker 服务器 IP 地址填写外网地址,注意端口 22122,而后 url_have_group_name 需要开启不然 HTTP 访问 404
1 2
# the base path to store log files base_path=/tmp
base_path 换成你需要的存放日志路径,实际存在的
1 2 3 4 5
# store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist # must same as storage.conf store_path0=/data/wwwroot/fastdfs/storage #store_path1=/home/yuqing/fastdfs1
base_path 还是换成你需要的首要存放图片路径,于上面相对应,实际存在的
以上结束修改。
5.10 配置 Nginx
进入存放 Nginx 配置根目录 cd /usr/local/nginx/conf 编辑配置文件 vi nginx.conf 值得注意几个地方
This is FastDFS client test program v5.08 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.csource.org/ for more detail. [2018-06-04 14:47:01] DEBUG - base_path=/data/wwwroot/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=139.129.109.222, port=23000 group_name=group1, ip_addr=139.129.109.222, port=23000 storage_upload_by_filename group_name=group1, remote_filename=M00/00/00/i4Ee3lsU4GWAbt8wABBiM_6UMxA671.jpg source ip address: 139.129.109.222 file timestamp=2018-06-04 14:47:01 file size=1073715 file crc32=4271125264 example file url: http://139.129.109.222/group1/M00/00/00/i4Ee3lsU4GWAbt8wABBiM_6UMxA671.jpg storage_upload_slave_by_filename group_name=group1, remote_filename=M00/00/00/i4Ee3lsU4GWAbt8wABBiM_6UMxA671_big.jpg source ip address: 139.129.109.222 file timestamp=2018-06-04 14:47:01 file size=1073715 file crc32=4271125264 example file url: http://139.129.109.222/group1/M00/00/00/i4Ee3lsU4GWAbt8wABBiM_6UMxA671_big.jpg