In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces "how to configure nginx read-write separation" in detail, with detailed content, clear steps and proper handling of details. I hope this article "how to configure nginx read-write separation" can help you solve your doubts.
Separation of Reading and Writing in nginx
1. Experimental topology
Demand analysis, the front end of a nginx to do load balancing reverse proxy, the next two httpd servers. The whole architecture is to provide bbs (Forum) services, there is a need to achieve read-write separation, that is, the function of uploading attachments, we can only upload attachments to web1, and then use rsync+inotify to achieve attachment synchronization on web1. We all know that rsync+inotify can only be master-slave synchronization, not two-way synchronization. So web1 can write, while web2 can only read, which brings the need for read-write separation. Let's talk about how to achieve read-write separation.
2.webdav feature description
Webdav (web-based distributed authoring and versioning) is a communication protocol based on http 1.1 protocol. It extends http 1.1.It adds some new methods in addition to several http standard methods such as get, post, head, etc., so that the application can read and write directly to web server, and supports write file locking (locking) and unlocking (unlock), as well as file version control. In this way, we can configure the read-write separation function, let's configure it in detail.
3. Modify the configuration file
[root@nginx nginx] # vim / etc/nginx/nginx.confserver {listen 80; server_name localhost; # charset koi8-r; # access_log logs/host.access.log main; location / {proxy_pass http://192.168.18.202; if ($request_method = "put") {proxy_pass http://192.168.18.201;}
4. Reload the configuration file
[root@nginx ~] # service nginx reloadnginx: the configuration file / etc/nginx/nginx.conf syntax is oknginx: configuration file / etc/nginx/nginx.conf test is successful reload nginx: [OK]
5. Configure the webdav feature of httpd
[root@web1 ~] # vim / etc/httpd/conf/httpd.conf
Note, just enable it below.
6. Restart httpd
[root@web1 ~] # service httpd restart stop httpd: [OK] starting httpd: [OK]
7. Test it
[root@nginx ~] # curl http://192.168.18.201web1.test.com[root@nginx ~] # curl http://192.168.18.202web2.test.com
Note, both web1 and web2 access are fine.
[root@nginx] # curl-t / etc/issue http://192.168.18.202405 method not allowedmethod not allowedthe requested method put is not allowed for the url / issue.apache/2.2.15 (centos) server at 192.168.18.202 port 80
Note: when we upload files to web2, because web2 is human-readable, there is no webdav function for opening an account, so it shows 405 method not allowed.
[root@nginx] # curl-t / etc/issue http://192.168.18.201403 forbiddenforbiddenyou don't have permission to access / issueon this server.apache/2.2.15 (centos) server at 192.168.18.201 port 80
Note, we have enabled the webdav function in web1, but our directory is the root directory, which does not allow apache users to upload, so it shows 403 forbidden. Next we give apache authorization to upload.
[root@web1] # setfacl-m u:apache:rwx / var/www/html/
Let's test it again.
[root@nginx] # curl-t / etc/issue http://192.168.18.201201 createdcreatedresource / issue has been created.apache/2.2.15 (centos) server at 192.168.18.201 port 80
Note, you can see that we have successfully uploaded the file, indicating that the nginx read-write separation function has been configured. Finally, let's take a look at the uploaded file.
[root@web1 ~] # cd / var/www/html/ [root@web1 html] # ll
Total dosage 12
Drwxr-xr-x 2 root root 4096 September 4 13:16 forum-rw-r--r-- 1 root root 23 September 3 23:37 index.html-rw-r--r-- 1 apache apache 47 September 4 14:06 issue read here, this article "how to configure nginx read-write separation" has been introduced, in order to master the knowledge of this article, you still need to do your own practice to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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: 247
*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.