Wishlist 0 ¥0.00

What is a CDN and how to Implement a CDN in Joomla 什么是CDN以及如何在Joomla中实现CDN

Were you ever curious about why large websites load their pages quicker. Sure, they have high performance dedicated servers, but they also use a globally distributed network called Content Delivery Network (CDN). This article will introduce you to the concept of CDN, how it works and how it can be configured on a Joomla website or in other words how to perform a Joomla CDN integration to help improve website content delivery speeds and reduce latency.

你是否曾经好奇为什么大型网站加载页面更快。当然,他们有高性能的专用服务器,但他们也使用一个全球分布式网络称为内容交付网络(CDN)。本文将向您介绍CDN的概念,它是如何工作的,以及如何在Joomla网站上进行配置,或者换句话说,如何执行Joomla CDN集成,以帮助提高网站内容交付速度和减少延迟。

What is a Content Delivery Network (CDN)?

什么是内容交付网络(CDN)?

A Content Delivery Network (CDN) is a globally distributed network of web servers or Points of Presence (PoP) whose purpose is to provide faster content delivery by replicating the content and storing it on multiple CDN Servers. That way, the user can access the data from a server that is in the nearest geographical location. This has proved more efficient than storing content on just one central server. Clients accessing copies of their data on the multiple CDN servers will help avoid bottlenecks near that central server.

内容交付网络(CDN)是Web服务器或存在点(PoP)的全球分布式网络,其目的是通过复制内容并将其存储在多个CDN服务器上来提供更快的内容交付。这样,用户就可以从地理位置最近的服务器访问数据。事实证明,这比仅在一台中央服务器上存储内容更高效。访问多个CDN服务器上的数据副本的客户端将有助于避免中央服务器附近的瓶颈。

Without a CDN, central servers must respond to every single end user request. This results a subsequent load, thereby increasing the chances for central server failure if the traffic spikes are exceedingly high or if the load is persistent.

如果没有CDN,中央服务器必须响应每个最终用户的请求。这会导致后续负载,从而在流量峰值过高或负载持续的情况下增加中央服务器发生故障的机会。

How does a Content Delivery Network (CDN) work?

内容交付网络(CDN)如何工作?

Nowadays, web pages are quite complicated and complex; one feature being that the entire content is too big to be downloaded at once. The browser on the user's personal computer or smartphone makes multiple requests to the central web server where each of these requests takes a few milliseconds only to get a response.

如今,网页相当繁杂复杂;一个特征是整个内容太大而不能一次下载。用户的个人计算机或智能手机上的浏览器向中央Web服务器发出多个请求,其中每个请求只需要几毫秒就能得到响应。

Moreover, the further away the central server is located, more intermediate nodes or networking devices that multiply requests time will be inevitable. Subsequently, hundreds of requests are placed to the central server for a single webpage to load up completely. This not only increases the server load but also increases the latency.

此外,中央服务器位置越远,将不可避免地会有更多的中间节点或网络设备,从而使请求时间倍增。随后,数百个请求被放置到中央服务器以完全加载单个网页。这不仅增加了服务器负载,而且增加了延迟。

Therefore, a website that applies Content Delivery Network (CDN) technology bridges the physical distance between the central server and the users’ personal computers. For example, a user is requesting a webpage from Saudi Arabia. The requested web page’s central server is located in the United States and there is a CDN server located in Switzerland.

因此,应用内容交付网络(CDN)技术的网站在中央服务器和用户的个人计算机之间架起了物理距离的桥梁。例如,用户正在请求来自沙特阿拉伯的网页。所请求网页的中央服务器位于美国,而CDN服务器位于瑞士。

If the webpage requested is a typical non-CDN website: The browser straight off connects to the server in the United States and asks for the HTML. The server sends it back from the United States to the browser in Saudi Arabia. Then the browser asks the United States web server again for images, Javascript and CSS. The server sends the images, Javascript and CSS to the browser in Saudi Arabia. But if the webpage requested is a CDN Website: The browser requests the HTML from the server in the United States. The browser receives the HTML from the United States and informs that the images, Javascript and CSS are in Switzerland CDN server. The images, Javascript and CSS are being sent by the Switzerland CDN server to the user browser in Saudi Arabia. 

如果请求的网页是典型的非CDN网站:浏览器直接连接到美国的服务器并要求HTML。服务器将其从美国发送回沙特阿拉伯的浏览器。然后,浏览器再次向美国网络服务器请求图像、Javascript和CSS。服务器将图像、Javascript和CSS发送到沙特阿拉伯的浏览器。但是,如果请求的网页是CDN网站:浏览器向美国的服务器请求HTML。浏览器从美国接收HTML,并通知图像、Javascript和CSS位于瑞士CDN服务器中。图片、Javascript和CSS由瑞士CDN服务器发送到沙特阿拉伯的用户浏览器。

 

What are the Content Delivery Network (CDN) Pros and Cons?

内容交付网络(CDN)的优缺点是什么?

The Pros of using CDN are:

使用CDN的优点是:

  • Web pages load quicker. 网页加载速度更快。
  • Better user experience. 更好的用户体验。
  • Reduce server bandwidth. 减少服务器带宽。
  • Lower server load. 降低服务器负载。
  • Increase in concurrent users on the central server. 中央服务器上并发用户的增加。
  • Geo-location of the content. 内容的地理位置。
  • Faster content delivery to the users’ browsers. 更快地将内容交付到用户的浏览器。

While the Cons of using CDN are:

使用CDN的缺点是:

  • Incorrect configuration of the CDN might cause viewing errors. CDN配置不正确可能会导致查看错误。
  • Cost additional expenses. 成本附加费用。
  • Adds complexity to your website and deployment procedures. 增加网站和部署程序的复杂性。
  • Network filters might block some Content Delivery Networks and prevent your website content from being loaded. 网络筛选器可能会阻止某些内容交付网络,并阻止加载您的网站内容。
  • Geo-location might actually be further away from your targeted audience. 地理位置可能实际上更远离您的目标受众。

What are the two types of Content Delivery Network (CDN)?

有哪些两种类型内容分发网络(CDN)的性能?

There are two different types of CDNs: push and original pull (or simply 'pull'). Each has its own advantages and disadvantages. Some sites work best with push CDNs, and some work better with pull CDNs.

有两种不同类型的CDN:推送和原始拉取(或简称为“拉取”)。每一种都有其优缺点。有些网站最适合使用推送CDN,有些则更适合使用拉取CDN。

Using a push CDN server, the site owner is required to upload website content (automatically or manually) directly to the CDN server and link that content to the website. The site owner, or the primary server, takes responsibility for providing the content to the CDN server, which in turn pushes it to the network. This is flexible as site owners can specify the content that is uploaded, when it expires and when it should be updated. This method is also the most efficient in terms of how the traffic is used. Content is uploaded only when it is new or changed, thus keeping traffic to a minimum.

使用推送CDN服务器时,网站所有者需要将网站内容(自动或手动)直接上传到CDN服务器,并将该内容链接到网站。站点所有者或主服务器负责向CDN服务器提供内容,CDN服务器进而将内容推送到网络。这是灵活的,因为网站所有者可以指定上传的内容、过期时间以及更新时间。就如何使用流量而言,此方法也是最有效的。只有当内容是新的或更改时才上传,从而将流量保持在最低水平。

On the contrary, an origin pull CDN works very differently. The site owner is not required to upload files onto the CDN, the CDN does it autonomously. The site owner leaves the content on the central server and rewrites the content URLs to point to the CDN server. When the visitors ask for a specific file, the CDN server will first go to the central server, pull the file and serve it. The CDN server will then cache that file until it expires. People who are trying to access a file for the first time, or accessing it after it has expired, may notice a small difference in speed. Setting the expiration correctly can help to minimise this problem, but it can involve trial and error.

相反,源拉CDN的工作方式非常不同。网站所有者不需要将文件上传到CDN,CDN会自动完成。站点所有者将内容保留在中央服务器上,并重写内容URL以指向CDN服务器。当访问者请求一个特定的文件时,CDN服务器会首先访问中央服务器,提取该文件并提供服务,然后CDN服务器会缓存该文件,直到它过期。首次尝试访问文件或在文件过期后访问文件的用户可能会注意到速度上的细微差异。正确设置过期时间有助于最大限度地减少此问题,但这可能需要反复试验。

How to Implement a Content Delivery Network (CDN) in Joomla?

如何在Joomla中实现内容交付网络(CDN)?

We already mentioned the two main CDN types, which were Push and Pull CDNs. Both of them have their advantages depending on the setup of your website. The Pull CDN is the one which is great for most of the Joomla sites and there is not much initial setup and maintenance needed. 

我们已经提到了两种主要的CDN类型,即Push CDN和Pull CDN。他们都有自己的优势取决于您的网站的设置拉CDN是一个伟大的大多数Joomla网站,并没有太多的初始设置和维护需要.& nbsp;

We will now introduce to you some tips on how to implement the Pull CDN. You can start with choosing a CDN provider from the list shown in the below sections, and creating an account with them. Now establish the DNS redirects while reading the instructions given by the provider. Once the cdn.yourdomain.com points at your CDN account, it’s all good.

现在我们将向您介绍一些关于如何实施Pull CDN的技巧。您可以从以下部分所示的列表中选择CDN提供商,并创建一个帐户。现在,在阅读提供商提供的说明的同时建立DNS重定向。一旦cdn.yourdomain.com指向您的CDN帐户,一切都很好。

The next step after the DNS and the CDN account configuration is to change your website files URLs from www.mydomain.com to cdn.mydomain.com. Instead of changing all website files URLs manually as it's very inefficient and will take a lot of time to do that, you can save your time and do it automatically using a Joomla CDN extension from the list shown in the below section. Joomla CDN extension gives you advanced options, easy accessibility, less maintenance, and can automatically change the links of your websites images, Javascript and CSS. Some of these extensions also include the option to specify the file types which should be rewritten while allowing the use of multiple CDNs at once. You can also easily turn the CDN on and off by using such an extension.

DNS和CDN帐户配置后的下一步是将网站文件URL从www.example.com更改www.mydomain.com为cdn.mydomain.com。而不是手动更改所有网站文件的URL,因为它是非常低效的,并将花费大量的时间来做,你可以保存你的时间,并自动使用Joomla CDN扩展从下面的部分显示的列表。Joomla CDN扩展为您提供了高级选项,易于访问,维护更少,并可以自动更改您的网站图像,Javascript和CSS的链接。其中一些扩展还包括指定应重写的文件类型的选项,同时允许一次使用多个CDN。您还可以使用这样的扩展轻松地打开和关闭CDN。

Choosing a CDN Extension:

选择CDN扩展:

The Joomla CDN extensions can be found in the Joomla Extensions Directory, just go to Core Enhancements > Performance category or you may choose one from the below list according to your needs in order to set up the CDN integration:

Joomla CDN扩展可以在Joomla扩展目录中找到,只需转到核心增强>性能类别,或者您可以根据您的需要从下面的列表中选择一个,以便设置CDN集成:

Setting up these extensions is usually pretty easy to do, depending on which one you choose. You may find other extensions which might fit your needs. Make sure to check extension documentation for further information.

设置这些扩展通常很容易,这取决于您选择的扩展。您可能会找到其他扩展可能适合您的需要。请确保查看扩展文档以了解更多信息。

Choosing a CDN Provider:

选择CDN提供商:

You may choose one of the popular CDN providers listed below. Be noted that some of them are free with limited features while others should be purchased as subscriptions in order to benefit all CDN features.

您可以选择下面列出的其中一个常用CDN提供商。请注意,其中一些是免费的,功能有限,而其他人应该购买订阅,以受益于所有CDN功能。

Conclusion

结语

CDNs serve a great purpose, they reduce significant traffic to the central server and improve the web experience which benefits both the content provider and the end users.

CDN的用途非常广泛,它们可以显著减少中央服务器的流量,改善Web体验,从而使内容提供商和最终用户都受益。

I hope you find this explanation of Content Delivery Networks helpful. A CDN requires extra configuration and extra expenses but the benefits are well worth it especially if you have users located all around the world.

我希望您会发现这对内容交付网络的解释有帮助。CDN需要额外的配置和额外的费用,但好处是非常值得的,特别是如果你有用户位于世界各地。

 
 

 

 

KangleWeb – How to Start a Web Server Business from Scratch in 2022

The Internet has changed our lives forever. Nowadays, almost everyone uses the World Wide Web every day. If you want to get ahead in life, you need to master the basics of computer science. This is especially true if you plan to launch your own web hosting business.

Web servers are computers that store websites and other data online. They allow us to access these files whenever we wish. To run a successful web server business, you’ll need to have some basic technical skills. These include knowing how to install software, troubleshoot problems, and configure settings. You can learn all this by reading through this article.

In this article, I have shared how to start a web server business from scratch. If you are a beginner, then this article is for you. Read this article to know more about the web server business in 2022.

On this page, you’ll learn about the following:

What is a Web Server

A web server is a computer program that allows people to view or download information stored on it. It’s like an online storage space where you can upload and share any type of file. For example, you could use a web server to host your website. Or you could use one to host your company’s website. You can also use a web server to create blogs, forums, wikis, photo galleries, video-sharing sites, etc. Anything that requires storing content online. 

For example, KangleWeb is one such web server that we can think of today. It is light, easy to use, and has a lot of users’ friendly features. 

Why Use a Web Server

The main reason why you would use a web server is that it’s easy to set up. Once you’ve installed it, you don’t need to worry about maintaining it. All you need to do is visit the site once in a while to make sure everything is working fine. Another good thing about using a web server is that it’s cheap. Most web hosts offer free plans with limited features. So, even if you’re just starting, you won’t be spending much money.

If you want to build a profitable web server business, you should consider selling premium services. Premium packages usually cost around $10 per month. However, they come with many advanced features such as unlimited bandwidth, multiple domains, email accounts, etc.

How to Start a Web Server Business in 2022

In the early 2000s, web hosting was a popular service among small businesses looking to make money online. Today, however, web hosting is much different. There are now several options for small businesses looking to host websites, including cloud computing platforms like Amazon Web Services and Microsoft Azure.

Starting a web server business from scratch may seem like a daunting task, but it doesn’t have to be! There are plenty of resources out there that can help you get started. Here are some important steps to make sure you’re ready to launch your web hosting company.

Step 1: Choose a Niche Market

Choosing a niche market is key when starting a web hosting company. Choosing an underserved market is a smart move since it gives you a competitive advantage over competitors. For example, choosing a market that is underserviced by existing providers allows you to charge higher prices and provide superior customer service.

Step 2: Get a Business Name

Once you’ve chosen a niche market, you’ll need to choose a name for your web hosting company. It is suggested to get a short yet unique name for your company. Also, it is important to create your website as soon as you get the name registered. Try to find a domain name that is short, memorable, and conveys a sense of professionalism. 

Step 3: Get Your Company Registered

As soon as you get the name of your company and get the website, it is time to register your company. For a startup, it is better to start a limited liability company. They have a less-complicated formation process and have more tax benefits. Check out the guide on how to start an LLC and some more LLC-related articles on StartMyLLC. 

Step 4: Build a Branding Strategy

Your branding strategy should include everything from logo design to advertising materials. Once you have a brand identity, you’ll need to build a strong reputation within your target market. This will allow you to attract customers who trust your brand. If you take any web hosting company like KangleWeb, they have a unique brand name and design. More such companies started recently and expanding at high speed. 

Step 5: Develop a Customer Relationship Management System

Developing a CRM system is essential for running a successful web hosting company. Keeping track of customers’ needs and preferences ensures that you’re providing the best possible service. Also, for web server business, you must be available to serve your customers/clients 24/7. It is important to get a CRM to keep all your clients on track. 

Step 6: Hire Staff

Hiring staff members is another critical step in launching a web hosting company. As your business grows, you’ll need employees to manage operations, handle billing, and answer support requests. While hiring employees, make sure to follow state-wise employment rules. For example, if you are starting an LLC in Florida, you might have to file an employment tax return. 

Step 7: Promote Yourself

Promoting yourself is crucial for getting clients. Whether you advertise on social media sites, place ads in local newspapers, or hold seminars, you’ll need to promote yourself so that clients know who you are and what you can do for them.

Step 8: Grow Your Client Base

Grow your client base by offering discounts, referrals, and other incentives to current clients. You can also offer free trials to potential clients to see if they would be interested in signing up. Keep an eye on the competitors in the market. Their offers, discounts, and what they are offering to their clients are needed to be checked. 

Step 9: Offer More Than Just Hosting

As your business grows, you might decide to expand into additional services. For example, you could start an e-commerce store where you sell products directly to consumers. You can also offer website designing, web content, logo designing, or something else to grab more clients. 

Step 10: Keep Up With Technology

Keeping up with technology is important for any business, but it’s especially true for a web hosting company. If you don’t stay ahead of trends, you risk losing clients to competitors who are using new technologies. 

Types of Web Server Solutions

Here’s a look at some of the best web server solutions available today:

1. Hosting Providers

Web hosting providers sell space on servers located in remote locations around the world. They provide customers access to software tools, databases, email addresses, and other resources needed to build and maintain websites. Hosting providers typically charge monthly fees based on the number of domains hosted on the server. Many also offer discounts for multiple domain names.

Some providers offer unlimited bandwidth, meaning customers can upload large files without worrying about running out of space. Others restrict bandwidth so that only certain kinds of content can be uploaded.

2. Cloud Computing Platforms

Cloud computing platforms allow users to store and process information in the cloud rather than on local computers. These platforms usually provide storage space and processing power on demand. Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure are examples of cloud computing platforms. Each platform provides its own set of features and benefits, but all three offer similar capabilities.

3. Dedicated Servers

Dedicated servers are physical machines dedicated to serving websites. Customers purchase these systems directly from manufacturers and install operating systems, applications, and databases themselves. For Example, KangleWeb, as I mentioned before. 

Dedicated servers come in various sizes, ranging from single-processor models to multi-core configurations. Some vendors offer virtualized versions of dedicated servers, allowing customers to run multiple instances of the same application on the same system. 

4. VPS Hosting

Virtual private servers (VPS) are virtual servers that reside within larger shared environments. Unlike dedicated servers, VPSes share hardware and network infrastructure with other customers. Customers buy VPSes from third parties and install operating systems, database programs, and applications themselves. 

5. Managed Service Providers

Managed service providers (MSPs) manage IT operations for their clients. MSPs often specialize in one or more areas, such as security, networking, or data backup. An MSP may handle everything related to an organization’s technology needs, including installing new equipment, maintaining existing systems, and providing ongoing support.

6. Software As A Service (SAAS)

Software as a service (SAAS) refers to services offered by companies that don’t own any physical assets. Instead, they rent them to customers. The most common SAAS offering is SaaS, which stands for “software as a service.” This type of service allows organizations to use software over the internet instead of having to download it onto their computer.

7. Application Programming Interface (API)

An API (application programming interface) is a way for two different pieces of software to communicate with each other. APIs are used when developers want to create custom solutions for specific problems. For example, if you wanted to develop a website builder, you could write your API that would let you connect your site builder to a database program.

8. Content Delivery Network (CDN)

A content delivery network (CDN) delivers digital media faster because it stores copies of popular content closer to where people are accessing it. Content delivery networks were originally designed to improve the performance of online video streaming sites like Netflix. However, CDNs also work well for static web pages and other types of content.

9. Digital Marketing Agency

Digital marketing agencies help businesses market their products and services using a variety of tools and techniques. They can provide everything needed to launch a successful campaign, from creating ads to managing social media accounts. Digital marketing agencies typically charge hourly rates based on the number of hours worked.

10. Online Advertising Agency

Online advertising agencies help businesses advertise their products and services through paid advertisements. These ads appear across the Internet, including search engines, social media platforms, and email newsletters.

Cost to Start a Web Server Business 

The average cost to start a web hosting company is $10,000-$20,000. This includes buying servers, hiring staff, purchasing software, etc. If you want to be successful, you need to spend at least $50,000 on equipment, staff, and other costs.

You will likely have to pay sales commissions to employees who sell web hosting plans. You should expect to make about 10% commission on every sale. If you plan to offer managed services, you’ll need to invest even more money. The average cost to hire a team of technicians is around $100 per hour.

Apart from the cost of setting up your web server business, there are filing fee charges, annual fees, and taxes that you must pay. These fees and taxes differ with states. For example, if you have an LLC in Texas or an LLC in California, you must have paid an annual Franchise Tax, along with a Sales Tax. On the other hand, for a Wyoming LLC and Montana LLC, you neither have to pay a Franchise Tax nor a Sales Tax.  Hence, to start and maintain a web server business, the above-mentioned costs should be considered. 

Hosting yourself is always better than hiring someone else. If you want to save money, hosting yourself is the best option. However, if you want to have full control over your website, then hiring someone else is the way to go. The main advantage of having someone else do the work for you is that they know how to create websites and optimize them for search engines like Google.

In Conclusion

Starting a Web Server business is not as difficult as many think. It’s quite easy to set up a web server business. All you need is a computer, some basic knowledge of computers, and a good idea. If you’re looking to start a web hosting business, this guide has all the information you need. We’ve provided a detailed description above of how to start a web server business from scratch. 

提高mysql的性能_MySQL 性能调优的10个方法

MYSQL 应该是最流行了 WEB 后端数据库。WEB 开发语言最近发展很快,PHP, Ruby, Python, Java 各有特点,虽然 NOSQL 最近越來越多的被提到,但是相信大部分架构师还是会选择 MYSQL 来做数据存储。

MYSQL 如此方便和稳定,以至于我们在开发 WEB 程序的时候很少想到它。即使想到优化也是程序级别的,比如,不要写过于消耗资源的 SQL 语句。但是除此之外,在整个系统上仍然有很多可以优化的地方。

1. 选择合适的存储引擎: InnoDB

除非你的数据表使用来做只读或者全文检索 (相信现在提到全文检索,没人会用 MYSQL 了),你应该默认选择 InnoDB 。

你自己在测试的时候可能会发现 MyISAM 比 InnoDB 速度快,这是因为: MyISAM 只缓存索引,而 InnoDB 缓存数据和索引,MyISAM 不支持事务。但是 如果你使用 innodb_flush_log_at_trx_commit = 2可以获得接近的读取性能 (相差百倍) 。

1.1 如何将现有的 MyISAM 数据库转换为 InnoDB:mysql -u [USER_NAME] -p -e "SHOW TABLES IN [DATABASE_NAME];" | tail -n +2 | xargs -I '{}' echo "ALTER TABLE {} ENGINE=InnoDB;" > alter_table.sql

perl -p -i -e 's/(search_[a-z_]+ ENGINE=)InnoDB//1MyISAM/g' alter_table.sql

mysql -u [USER_NAME] -p [DATABASE_NAME]

1.2 为每个表分别创建 InnoDB FILE:innodb_file_per_table=1

这样可以保证 ibdata1 文件不会过大,失去控制。尤其是在执行 mysqlcheck -o –all-databases 的时候。

2. 保证从内存中读取数据,讲数据保存在内存中

2.1 足够大的 innodb_buffer_pool_size

推荐将数据完全保存在 innodb_buffer_pool_size ,即按存储量规划 innodb_buffer_pool_size 的容量。这样你可以完全从内存中读取数据,最大限度减少磁盘操作。

2.1.1 如何确定 innodb_buffer_pool_size 足够大,数据是从内存读取而不是硬盘?

方法 1mysql> SHOW GLOBAL STATUS LIKE 'innodb_buffer_pool_pages_%';

+----------------------------------+--------+| Variable_name                    | Value  |

+----------------------------------+--------+

| Innodb_buffer_pool_pages_data    | 129037 || Innodb_buffer_pool_pages_dirty   | 362    |

| Innodb_buffer_pool_pages_flushed | 9998   || Innodb_buffer_pool_pages_free    | 0      |  !!!!!!!!

| Innodb_buffer_pool_pages_misc    | 2035   || Innodb_buffer_pool_pages_total   | 131072 |

+----------------------------------+--------+

6 rows in set (0.00 sec)

发现 Innodb_buffer_pool_pages_free 为 0,则说明 buffer pool 已经被用光,需要增大 innodb_buffer_pool_size

InnoDB 的其他几个参数:innodb_additional_mem_pool_size = 1/200 of buffer_pool

innodb_max_dirty_pages_pct 80%

方法 2

或者用iostat -d -x -k 1 命令,查看硬盘的操作。

2.1.2 服务器上是否有足够内存用来规划

执行 echo 1 > /proc/sys/vm/drop_caches 清除操作系统的文件缓存,可以看到真正的内存使用量。

2.2 数据预热

默认情况,只有某条数据被读取一次,才会缓存在 innodb_buffer_pool。所以,数据库刚刚启动,需要进行数据预热,将磁盘上的所有数据缓存到内存中。数据预热可以提高读取速度。

对于 InnoDB 数据库,可以用以下方法,进行数据预热:

1. 将以下脚本保存为 MakeSelectQueriesToLoad.sqlSELECT DISTINCT

CONCAT('SELECT ',ndxcollist,' FROM ',db,'.',tb,    ' ORDER BY ',ndxcollist,';') SelectQueryToLoadCache    FROM

(        SELECT

engine,table_schema db,table_name tb,

index_name,GROUP_CONCAT(column_name ORDER BY seq_in_index) ndxcollist        FROM

(            SELECT

B.engine,A.table_schema,A.table_name,

A.index_name,A.column_name,A.seq_in_index            FROM

information_schema.statistics A INNER JOIN

(                    SELECT engine,table_schema,table_name                    FROM information_schema.tables WHERE

engine='InnoDB'

) B USING (table_schema,table_name)            WHERE B.table_schema NOT IN ('information_schema','mysql')            ORDER BY table_schema,table_name,index_name,seq_in_index

) A        GROUP BY table_schema,table_name,index_name

) AAORDER BY db,tb

;

2. 执行mysql -uroot -AN  /root/SelectQueriesToLoad.sql

3. 每次重启数据库,或者整库备份前需要预热的时候执行:mysql -uroot  /dev/null 2>&1

2.3 不要让数据存到 SWAP 中

如果是专用 MYSQL 服务器,可以禁用 SWAP,如果是共享服务器,确定 innodb_buffer_pool_size 足够大。或者使用固定的内存空间做缓存,使用 memlock 指令。

3. 定期优化重建数据库

mysqlcheck -o –all-databases 会让 ibdata1 不断增大,真正的优化只有重建数据表结构:CREATE TABLE IF NOT EXISTS mydb.mytablenew LIKE mydb.mytable;INSERT INTO mydb.mytablenew SELECT * FROM mydb.mytable;ALTER TABLE mydb.mytable RENAME mydb.mytablezap;ALTER TABLE mydb.mytablenew RENAME mydb.mytable;DROP TABLE mydb.mytablezap;

4. 减少磁盘写入操作

4.1 使用足够大的写入缓存 innodb_log_file_size

但是需要注意如果用 1G 的 innodb_log_file_size ,假如服务器当机,需要 10 分钟来恢复。

推荐 innodb_log_file_size 设置为 0.25 * innodb_buffer_pool_size

4.2 innodb_flush_log_at_trx_commit

这个选项和写磁盘操作密切相关:

innodb_flush_log_at_trx_commit = 1 则每次修改写入磁盘

innodb_flush_log_at_trx_commit = 0/2 每秒写入磁盘

如果你的应用不涉及很高的安全性 (金融系统),或者基础架构足够安全,或者 事务都很小,都可以用 0 或者 2 来降低磁盘操作。

4.3 避免双写入缓冲innodb_flush_method=O_DIRECT

5. 提高磁盘读写速度

RAID0 尤其是在使用 EC2 这种虚拟磁盘 (EBS) 的时候,使用软 RAID0 非常重要。

6. 充分使用索引

6.1 查看现有表结构和索引SHOW CREATE TABLE IF NOT EXISTS db1.tb1/G

6.2 添加必要的索引

索引是提高查询速度的唯一方法,比如搜索引擎用的倒排索引是一样的原理。

索引的添加需要根据查询来确定,比如通过慢查询日志或者查询日志,或者通过 EXPLAIN 命令分析查询。ADD UNIQUE INDEX

ADD INDEX

6.2.1 比如,优化用户验证表:

添加索引ALTER TABLE users ADD UNIQUE INDEX username_ndx (username);ALTER TABLE users ADD UNIQUE INDEX username_password_ndx (username,password);

每次重启服务器进行数据预热echo “select username,password from users;” > /var/lib/mysql/upcache.sql

添加启动脚本到 my.cnf[mysqld]init-file=/var/lib/mysql/upcache.sql

6.2.2 使用自动加索引的框架或者自动拆分表结构的框架

比如,Rails 这样的框架,会自动添加索引,Drupal 这样的框架会自动拆分表结构。会在你开发的初期指明正确的方向。所以,经验不太丰富的人一开始就追求从 0 开始构建,实际是不好的做法。

7. 分析查询日志和慢查询日志

记录所有查询,这在用 ORM 系统或者生成查询语句的系统很有用。log=/var/log/mysql.log

注意不要在生产环境用,否则会占满你的磁盘空间。

记录执行时间超过 1 秒的查询:long_query_time=1log-slow-queries=/var/log/mysql/log-slow-queries.log

8. 激进的方法,使用内存磁盘

现在基础设施的可靠性已经非常高了,比如 EC2 几乎不用担心服务器硬件当机。而且内存实在是便宜,很容易买到几十G内存的服务器,可以用内存磁盘,定期备份到磁盘。

将 MYSQL 目录迁移到 4G 的内存磁盘mkdir -p /mnt/ramdisk

sudo mount -t tmpfs -o size=4000M tmpfs /mnt/ramdisk/

mv /var/lib/mysql /mnt/ramdisk/mysql

ln -s /tmp/ramdisk/mysql /var/lib/mysql

chown mysql:mysql mysql

9. 用 NOSQL 的方式使用 MYSQL

B-TREE 仍然是最高效的索引之一,所有 MYSQL 仍然不会过时。

用 HandlerSocket 跳过 MYSQL 的 SQL 解析层,MYSQL 就真正变成了 NOSQL。

10. 其他单条查询最后增加 LIMIT 1,停止全表扫描。

将非”索引”数据分离,比如将大篇文章分离存储,不影响其他自动查询。

不用 MYSQL 内置的函数,因为内置函数不会建立查询缓存。

PHP 的建立连接速度非常快,所有可以不用连接池,否则可能会造成超过连接数。当然不用连接池 PHP 程序也可能将

连接数占满比如用了 @ignore_user_abort(TRUE);

使用 IP 而不是域名做数据库路径,避免 DNS 解析问题

11. 结束

你会发现优化后,数据库的性能提高几倍到几百倍。所以 MYSQL 基本还是可以适用大部分场景的应用的。优化现有系统的成本比系统重构或者迁移到 NOSQL 低很多。9

 
 

 

 

MySQL服务自动停止的解决方法

问题描述

服务器上安装的 MySQL,会出现自动停止的情况。出现这种现象,通常是服务器的内存不足导致的。

具体可以通过服务器日志来进行分析排查:

查看服务器的系统日志 /var/log/messages

看下在 MySQL 自动停止的时间段内,有什么异常的日志信息,如果日志有提示 Out of memory 就可以判定,是服务器的内存使用不足,导致系统自动杀死的 MySQL 的进程

解决办法

通过升级服务器的内存可以解决.

About Us

Since 1996, our company has been focusing on domain name registration, web hosting, server hosting, website construction, e-commerce and other Internet services, and constantly practicing the concept of "providing enterprise-level solutions and providing personalized service support". As a Dell Authorized Solution Provider, we also provide hardware product solutions associated with the company's services.
 

Contact Us

Address: No. 2, Jingwu Road, Zhengzhou City, Henan Province

Phone: 0086-371-63520088 

QQ:76257322

Website: 800188.com

E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.