In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Compared with other CDN service providers, the main advantages of CDN include stable and fast, cost-effective, easy to use, efficient and intelligent. More users will ask about the advantage of stability and speed. Generally speaking, CDN is characterized by sharing the pressure on the origin server, avoiding network congestion, accelerating the distribution of website content in different regions and different scenarios, and improving the speed of resource access. The following is to introduce the mysql database push platform and CDN.
Sendfile (data is sent directly from the buffer of kernal) is suitable for small files
Aio (nginx) fully asynchronous (unlike event-driven io: data will not be notified until it arrives at mem, in fact, it can be returned directly to the client without notification) support: mmap event drive (handling large files)
As mentioned last time, after the database is modified, the data in redis cannot be updated automatically, and the changed data must be deleted manually. According to the above problems, we make the following improvements:
So the next step is to synchronize the changed data to the redis through the mysql trigger
Configure gearman to realize data synchronization
Gearman is a distributed task distribution framework:
Gearman Job Server: Gearman core program that needs to be compiled and installed and run in the background as a daemon.
Gearman Client: can be understood as the requestor of the task.
Gearman Worker: the real executor of the task, generally need to write the specific logic and daemon way
Running, when Gearman Worker receives the task content passed by GearmanClient, it will process it sequentially.
General process: the mysql trigger to be written below is equivalent to the client of Gearman. Modifying the table and inserting the table is equivalent to directly
Send out the mission. Then map the relational data to JSON format through the lib_mysqludf_json UDF library function, and then
After adding the task to the Gearman task queue through the gearman-mysql-udf plug-in, finally through the
Redis_worker.php, which is the worker side of Gearman, completes the update of the redis database.
Dd1:
Cd / root/redis
Install the gearman package:
Yum install gearmand-1.1.8-2.el6.x86_64.rpm libgearman-1.1.8-2.el6.x86_64.rpm
/ etc/init.d/php-fpm start
Netstat-antlpe
Dd1: install the gearman extension for php
Tar zxf gearman-1.1.2.tgz
Cd gearman-1.1.2
Phpize
Rpm-ivh libgearman-devel-1.1.8-2.el6.x86_64.rpmlibevent-devel-1.4.13-4.el6.x86_64.rpm libevent-doc-1.4.13-4.el6.noarch.rpmlibevent-headers-1.4.13-4.el6.noarch.rpm
. / configure
Make & & make install
Cd / etc/php.d/
Cp mysql.ini gearman.ini
Vim gearman.ini
/ etc/init.d/php-fpm restart
Check out the extensions that php has installed:
Php-m | grep gearman
Php-m | grep mysql
Php-m | grep redis
Cd redis/
Scp gearman-mysql-udf-0.6.tar.gz 172.25.42.12
Scp lib_mysqludf_json-master.zip 172.25.42.12:
Scp libevent-* libgearman-* 172.25.42.12:
Dd3:
/ etc/init.d/mysqld start
Tar zxf gearman-mysql-udf-0.6.tar.gz
Yum install mysql-devel-y
Rpm-ivh libgearman-devel-1.1.8-2.el6.x86_64.rpmlibevent-devel-1.4.13-4.el6.x86_64.rpm libevent-doc-1.4.13-4.el6.noarch.rpmlibevent-headers-1.4.13-4.el6.noarch.rpm
Cd gearman-mysql-udf-0.6
. / configure-- libdir=/usr/lib64/mysql/plugin/
Make & & make install
Cd / usr/lib64/mysql/plugin/
Enter the mysql environment:
Register the UDF function
Mysql > CREATE FUNCTION gman_do_background RETURNS STRING SONAME
'libgearman_mysql_udf.so'
Mysql > CREATE FUNCTION gman_servers_set RETURNS STRINGSONAME
'libgearman_mysql_udf.so'
View function
Mysql > select * from mysql.func
Install lib_mysqludf_json
The lib_mysqludf_jsonUDF library function maps relational data to JSON format. Usually, the data in the database is mapped to JSON format and is transformed by program.
Unzip lib_mysqludf_json-master.zip
Cd lib_mysqludf_json-maste
Gcc $(mysql_config-- cflags)-shared-fPIC-olib_mysqludf_json.so
Lib_mysqludf_json.c
View the module directory of mysql:
Mysql > show global variables like 'plugin_dir'
Copy the lib_mysqludf_json.so module:
Cp lib_mysqludf_json.so / usr/lib64/mysql/plugin/
Register the UDF function
Mysql > CREATE FUNCTION json_object RETURNS STRING SONAME
'lib_mysqludf_json.so'
View function
Mysql > select * from mysql.func
Specify the service information for gearman
Mysql > SELECT gman_servers_set ('172.25.42.10 4730')
Write mysql trigger test.sql
Mysql
< test.sql 查看触发器 mysql>SHOW TRIGGERS FROM test
Dd1: the worker side of writing gearman
Nohup php worker.php & > / dev/null & (running in the background)
Test:
Update data in mysql
Mysql > update test set name='test1' where id=1
Mysql > update test set name='dangdang' where id=1
Varnish: http cache:
Dd1:
Varnish-3.0.5-1.el6.x86_64.rpm varnish-libs-3.0.5-1.el6.x86_64.rpm
Rpm-ivh
Vim / etc/sysconfig/varnish
Cd / etc/varnish/
Vim default.vcl
/ etc/init.d/varnish start
Dd3:/etc/init.d/httpd start
# manually clear the cache through varnishadm
# varnishadm ban.url. * $
# clear all
# varnishadm ban.url / index.html
# clear the index.html page cache
# varnishadm ban.url / admin/$
# clear the admin directory cache
Vim default.vcl
# View cache hits
Sub vcl_deliver {
If (obj.hits > 0) {
Set resp.http.X-Cache = "HIT from westos cache"
}
Else {
Set resp.http.X-Cache = "MISS from westos cache"
}
Return (deliver)
}
Test cache hit:
Define back-end servers for multiple different domain name sites:
Backend default {
.host = "172.25.42.12"
.port = "80"
}
Backend web {
.host = "172.25.42.11"
.port = "80"
}
Sub vcl_recv {
If (req.http.host ~ "^ (www.)? dd.org") {
Set req.http.host = "www.dd.org"
Set req.backend = default
} elsif (req.http.host ~ "^ bbs.dd.org") {
Set req.backend = web
} else {error 404 "westos cache"
}
Test: www.dd.org and dd.org are the same cache
And bbs.dd.org is a cache.
# get data from default when accessing www.dd.org domain name, get data from web when accessing bbs.dd.org domain name, and report an error when visiting other pages / / Note: test host plus resolution
Load balancer: (domain name load balancer)
Two hosts respond to www.dd.org when it is accessed
Avoid opening another virtual machine to dd2 as a virtual host (one ip with multiple domain names)
Dd1:
Vim default.vcl
Director lb round-robin {
{.backend = default;}
{.backend = web;}
}
Sub vcl_recv {
If (req.http.host ~ "^ (www.)? dd.org") {
Set req.http.host = "www.dd.org"
Set req.backend = lb
Return (pass); (testing)
} elsif (req.http.host ~ "^ bbs.dd.org") {
Set req.backend = web
} else {error 404 "westos cache"
}
}
Varnish cdn push platform (clear cache)
# need to install php support
# unzip bansys.zip-d / var/www/html
# vi / var/www/html/bansys/config.php
# keep only the following settings and leave the rest out
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.