网站数据存储需要做好前期的规划,不然数据量上来以后无论是管理还是性能上都带来很多问题,对于需要存储大量文件、图片的网站来说是个重点的话题,通常网页文字内容和网页图片内容 所占用的存储空间相比较的话,显然是图片存储占用的空间要远远超过网站文字
网站数据存储需要做好前期的规划,不然数据量上来以后无论是管理还是性能上都带来很多问题,对于需要存储大量文件、图片的网站来说是个重点的话题,通常网页文字内容和网页图片内容 所占用的存储空间相比较的话,显然是图片存储占用的空间要远远超过网站文字内容所需要存储的空间,从另外一个角度上来看访问图片所占用的网络带宽要远远超过文字内容所占用的带宽。
在系统运行上的瓶颈对于互联网用户来说往往不是落在系统内部计算的I/O瓶颈上,而是落在网络带宽的瓶颈上。把存储图片的服务器和访问图片服务器的网络入口独立出来,在条件允许的情况下给予更的高网络带宽和独立的域名,有利于扩展性和整体性能的发挥,将计算、存储的扩展性和带宽的资源做到合理分配,互不影响,是我们当前的目标。
除此之外,还需要能做到:
1.使用廉价机器(老机器)构建分布式网络存储环境,支持150TB以上的存储容量,
2.数据在线同步,支持文件副本复制,无明显的单点问题,可快速恢复故障节点,
3.通用文件系统,不需要修改上层应用就可以使用(支持fuse),web服务器可以直接读取分布式存储空间,无中间转取。
4.支持在线不停机的情况下扩展存储的空间,
5.随机读写的高效,并且支持海量小文件(5kb)的高效读写,
6.可监控运行时的存储使用状态,最好是web界面。
得到了一些个解决方案,但依然不满足,对存储本身还有更高的期望:
1.需要避免图片文件重复的写入,建立图片存储的索引,根据唯一的图片文件名的查询后,再判断是否写入,
2.小图片,签名照,小头像,表情图片 放在缓存里读取,让数据更靠近cpu,设计的黄金原则,我们尽量把能放入Redis缓存中的数据就在Redis里读取。
架构介绍
1.负载均衡:HAproxy采用RoundRobin负载均衡算法,分载前端用户请求的压力到每个web图片服务器上,
2.web服务:采用Nginx-0.9.6 做图片的web服务器,对网站的大、中、小图片进行读取,加上Nginx的Redis模块对缓存中的微型(头像)图片进行读取,
3. 缓存服务器:存储网站的 微型图片,签名照,小头像,表情图片,通过Nginx的Redis模块直接读取,通过调用Redis的java API程序对数据进行写入,
4.存储单元:采用Moosefs 存储 大、中、小图片,并且提供监控管理界面,查看存储空间运行状态,
5.图片索引:将图片名和图片url路径作为键值对(Key/Value),放入HBase 中存储,并且进行数据查询,避免图片重复存储,便于将来管理,
6.应用服务器:对图片写入的操作全部由Java应用服务器完成。
我们目前图片存储的系统架构,如图所示:
查看大图请点击这里
关于HBase的话题在这里就不多说了,可以参考我之前写的几篇文件文章,主要想说说Moosefs的体系:
1 Master 管理服务器:负责各个数据存储服务器的管理,文件读写调度,文件空间回收以及恢复.多节点拷贝
2 Chunk 元数据日志服务器: 负责备份master服务器的变化日志文件,文件类型为changelog_ml.*.mfs,以便于在master server出问题的时候接替其进行工作
3 Metalogger 数据存储服务器:负责连接管理服务器,听从管理服务器调度,提供存储空间,并为客户提供数据传输.
4 Client 客户端: 通过fuse内核接口挂接远程管理服务器上所管理的数据存储服务器,看起来共享的文件系统和本地unix文件系统使用一样的效果.
最有代表性的成功案例
豆瓣网(Douban Inc),155 TB的存储空间,
Master server: Gentoo Linux / ReiserFS 3.6
24 chunk servers: Gentoo Linux / ReiserFS / XFS
3 metalogger(s): Gentoo Linux / ReiserFS 3.6
37 client machines: Gentoo Linux
其实,采用某种技术只是一种具体实现的手段,或许从外界的统计数据来看 mogileFS、ceph、FastDFS 等其他产品具有更高的读写性能,甚至可以到满足我上述的任何一项要求,但我们所关注的侧重点不一样,要需要简单,易上手,够用就行,所以在这里利用Moosefs做了一个抛砖引玉。
–end–
原文地址:山寨技术下的网站图片服务器(NGINX), 感谢原作者分享。

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools