标签:
对于绝大多数网站,图片资源是一个非常重要的元素。社区论坛里面图片相册,电子商务线上产品展示图,移动端应用图片分享功能等。都在说互联网正在处于读图时代,各大中小型网站都需要保持良好的图片处理能力。需要支持海量图片资源存储时,更加要搭建高可用负载图片服务集群支撑网站系统,保证网站上图片相关功能准确无误运行,用户对象访问页面体验流畅。
环境:四台Linux主机,一台LVS负载均衡,一台FastDFS_tracker,两台FastDFS_storage,FastDFS_client在FastDFS_tracker上面。
负载:192.168.10.141,安装LVS
图片:192.168.10.173,安装Nginx+FastDFS
图片:192.168.10.74,安装Nginx+FastDFS
调度:192.168.10.252,安装FastDFS
负载均衡:使用LVS实现负载均衡,工作于网络层的代理转发,支持三个转发工作方式,提供十种代理调度算法。
读写分离:访问图片时通过负载均衡的代理,上传图片时通过分布式文件系统的调度器,访问与上传不再经过单一服务器。
高可用性:使用LVS+Keepalived实现负载均衡高可用性图片服务器集群,搭建两台LVS负载服务器,安装Keepalived检测当前LVS健康状态,随时准备主从切换。
备份功能:启用图片服务的实时备份功能,该备份服务器只进行图片的写操作,不支持文件系统与客户端进行图片删除、修改、访问。
分布式文件系统:使用FastDFS分布式文件系统,图片通过调度器写到优先级高的存储器,然后同步到其他存储器。
[root@localhost Desktop]# yum -y install ipvsadm*
[root@localhost Desktop]# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@localhost Desktop]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm Retrieving http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm warning: /var/tmp/rpm-tmp.4MHe6h: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY Preparing... ########################################### [100%] 1:nginx-release-centos ########################################### [100%]
[root@localhost Desktop]# yum info nginx Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.sina.cn nginx | 2.9 kB 00:00 nginx/primary_db | 8.3 kB 00:00 Available Packages Name : nginx Arch : x86_64 Version : 1.8.1 Release : 1.el6.ngx Size : 352 k Repo : nginx Summary : High performance web server URL : http://nginx.org/ License : 2-clause BSD-like license Description : nginx [engine x] is an HTTP and reverse proxy server, as well as : a mail proxy server.
[root@localhost Desktop]# yum install nginx
[root@localhost Desktop]# nginx
[root@localhost Desktop]# mkdir FastNFS [root@localhost Desktop]# cd FastNFS/ [root@localhost FastNFS]# git clone https://github.com/libevent/libevent.git [root@localhost libevent]# rpm -qa libevent [root@localhost libevent]# rpm -qa|grep libevent rpm -e libevent* [root@localhost FastNFS]# cd libevent [root@localhost libevent]# cd cmake [root@localhost cmake]# yum install cmake [root@localhost cmake]# cmake .. [root@localhost cmake]# make [root@localhost cmake]# make install
[root@localhost FastNFS]# git clone https://github.com/happyfish100/libfastcommon.git [root@localhost FastNFS]# cd libfastcommon [root@localhost libfastcommon]# ./make.sh [root@localhost libfastcommon]# ./make.sh install mkdir -p /usr/lib64 mkdir -p /usr/lib install -m 755 libfastcommon.so /usr/lib64 install -m 755 libfastcommon.so /usr/lib mkdir -p /usr/include/fastcommon install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h /usr/include/fastcommon
[root@localhost FastNFS]# wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz [root@localhost FastNFS]# tar -zxvf V5.05.tar.gz [root@localhost FastNFS]# cd fastdfs-5.05 [root@localhost fastdfs-5.05]# ./make.sh [root@localhost fastdfs-5.05]# ./make.sh install mkdir -p /usr/bin mkdir -p /etc/fdfs cp -f fdfs_trackerd /usr/bin if [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fi mkdir -p /usr/bin mkdir -p /etc/fdfs cp -f fdfs_storaged /usr/bin if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi mkdir -p /usr/bin mkdir -p /etc/fdfs mkdir -p /usr/lib64 cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender /usr/bin if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; fi if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; fi mkdir -p /usr/include/fastdfs cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi
[root@localhost fastdfs-5.05]# ll /etc/fdfs/ total 20 -rw-r--r--. 1 root root 1461 Mar 21 03:01 client.conf.sample -rw-r--r--. 1 root root 7829 Mar 21 03:01 storage.conf.sample -rw-r--r--. 1 root root 7102 Mar 21 03:01 tracker.conf.sample
[root@localhost nginx]# ipvsadm --help ipvsadm v1.26 2008/5/15 (compiled with popt and IPVS v1.2.1) Usage: ipvsadm -A|E -t|u|f service-address [-s scheduler] [-p [timeout]] [-M netmask] [--pe persistence_engine] ipvsadm -D -t|u|f service-address ipvsadm -C ipvsadm -R ipvsadm -S [-n] ipvsadm -a|e -t|u|f service-address -r server-address [options] ipvsadm -d -t|u|f service-address -r server-address ipvsadm -L|l [options] ipvsadm -Z [-t|u|f service-address] ipvsadm --set tcp tcpfin udp ipvsadm --start-daemon state [--mcast-interface interface] [--syncid sid] ipvsadm --stop-daemon state ipvsadm -h Commands: Either long or short options are allowed. --add-service -A add virtual service with options --edit-service -E edit virtual service with options --delete-service -D delete virtual service --clear -C clear the whole table --restore -R restore rules from stdin --save -S save rules to stdout --add-server -a add real server with options --edit-server -e edit real server with options --delete-server -d delete real server --list -L|-l list the table --zero -Z zero counters in a service or all services --set tcp tcpfin udp set connection timeout values --start-daemon start connection sync daemon --stop-daemon stop connection sync daemon --help -h display this help message Options: --tcp-service -t service-address service-address is host[:port] --udp-service -u service-address service-address is host[:port] --fwmark-service -f fwmark fwmark is an integer greater than zero --ipv6 -6 fwmark entry uses IPv6 --scheduler -s scheduler one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq, the default scheduler is wlc. --pe engine alternate persistence engine may be sip, not set by default. --persistent -p [timeout] persistent service --netmask -M netmask persistent granularity mask --real-server -r server-address server-address is host (and port) --gatewaying -g gatewaying (direct routing) (default) --ipip -i ipip encapsulation (tunneling) --masquerading -m masquerading (NAT) --weight -w weight capacity of real server --u-threshold -x uthreshold upper threshold of connections --l-threshold -y lthreshold lower threshold of connections --mcast-interface interface multicast interface for connection sync --syncid sid syncid for connection sync (default=255) --connection -c output of current IPVS connections --timeout output of timeout (tcp tcpfin udp) --daemon output of daemon information --stats output of statistics information --rate output of rate information --exact expand numbers (display exact values) --thresholds output of thresholds information --persistent-conn output of persistent connection info --nosort disable sorting output of service/server entries --sort does nothing, for backwards compatibility --ops -o one-packet scheduling --numeric -n numeric output of addresses and ports
VIP=192.168.10.251 /sbin/ifconfig eth2:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev eth2:0 echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/all/send_redirects echo 1 > /proc/sys/net/ipv4/conf/default/send_redirects echo 1 > /proc/sys/net/ipv4/conf/eth2/send_redirects /sbin/ipvsadm -C ipvsadm -A -f 1 -s rr ipvsadm -a -f 1 -r $RIP1:80 -g ipvsadm -a -f 1 -r $RIP2:80 -g
[root@localhost ipvsadm]# ipvsadm -ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn FWM 1 rr -> 192.168.10.98:80 Route 1 0 0 -> 192.168.10.128:80 Route 1 0 0
VIP=192.168.10.251 ifconfig lo down ifconfig lo up echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev lo:0
[root@localhost html]# vi /etc/nginx/conf.d/default.conf
location / { root /usr/share/nginx/html; index index.html index.htm; }
location / { #root /usr/share/nginx/html; root /home/yuqing/fastdfs/data/00/00; index index.html index.htm; }
[liang@localhost Desktop]$ fdfs_upload_file /etc/fdfs/client.conf ./linux.jpg group1/M00/00/00/wKgKYlcgVEGAfRLhAAAX6oV41fw051.jpg
[root@localhost html]# ll /home/yuqing/fastdfs/data/00/00/ total 32 -rw-r--r--. 1 root root 6122 Apr 26 22:55 wKgKYlcgVEGAfRLhAAAX6oV41fw051.jpg -rw-r--r--. 1 root root 11336 Mar 22 00:59 wKjVh1bw-1KADEceAAAsSKZJhlk53.html -rw-r--r--. 1 root root 11336 Mar 22 01:05 wKjViFbw_LyAIv-oAAAsSKZJhlk82.html
标签:
原文地址:http://blog.csdn.net/a821478424/article/details/51261054