Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to split a database and set up NFS shared storage

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to split the database and set up NFS shared storage. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

1. Why split the database?

In LNMP architecture, dynamic data is read through PHP to retrieve database data. If such a process is difficult for a database to undertake in the case of a large number of visits, it will inevitably lead to memory overflowing, unable to read and lead to web downtime. Therefore, in general architecture, Nginx and PHP are deployed together. Database as the back end, its data processing speed represents the efficiency of the entire web architecture, so the database is deployed separately and there is more than one database server.

2. What problems have been solved after the database is split?

1) improve the data processing speed of the database

2) relieve the pressure of Web

3) improve user access speed

3. The schema changes after the database is split

4, take chapter 22 LNMP architecture as an example

1) web:10.0.0.8 Nging+PHP

2) db: 10.0.0.51 mysql

5, split

1) install the database server

Yum install mariadb mariadb-server-y

Systemctl start mariadb

Systemctl enable mariadb

Mysqladmin password 'oldboy123'

2) back up the database data on Web

Mysqldump-uroot-paired oldboy 123'-A-- single-transaction > mysql-all.sql (back up all the data in the database)

3) SCP the data to the new database server

Scp mysql-all.sql 10.0.1.51:/tmp

4) restore the data on the new database server

Mysql-uroot-paired oldboy 123'

< /tmp/mysql-all.sql mysql -uroot -p'oldboy123' -e "show databases;" 5)创建用户并授权 mysql -uroot -p'oldboy123' grant all privileges on *.* to 'yangjiwan'@'%' identified by 'oldboy123';(这里创建一个普通用户不用root用户了权限太大,密码是oldboy123,%表示允许所有ip连接也可以指定就Nginx+PHP服务器连接) flush privileges; exit 6)修改PHP与数据库的配置文件将指定新的(用户,密码,ip)用来连通新的数据库 vim /code/wordpress/wp-config.php /** MySQL数据库用户名 */define('DB_USER', 'yangjiwan');/** MySQL数据库密码 */define('DB_PASSWORD', 'oldboy123');/** MySQL主机 */define('DB_HOST', '10.0.0.51'); 7)测试,将原来PHP与数据库的通讯断开,连接新的数据库 systemctl stop mariadb.service

Then you can visit to indicate that the migration is successful!

1. Mount Web data directory resources to NFS shared storage

1) Why should the web data directory be mounted to the NFS shared unified storage? in the production environment, users will visit different web servers after they are distributed through Nginx. After the user uploads the data, if you do not have a unified storage location and store it separately on a web, then the next time the user visits, Nginx distributes his request to another web. Can you still see the data you uploaded?

2) the role of adding a NFS server?

1. Consistency of web data directory resources

2, saving the storage resources on the web server

3. Facilitate the acceleration of resources by the back-end CDN

4. Realize the unified backup of web data by back-end Lsyncd

2. Web architecture after adding NFS server

3. Environment:

Web7:nginx+php

Web8:nginx+php

Db51:mariadb

Nfs31:nfs

4. Build NFS server (completed)

[root@nfs01 ~] # yum install nfs-utils-y [root@nfs01 ~] # cat / etc/exports/data/blog 172.16.1.0 rw,sync,all_squash,anonuid=666,anongid=666 / data/zh 172.16.1.0 rw,sync,all_squash,anonuid=666,anongid=666 24 (rw,sync,all_squash,anonuid=666,anongid=666) [root@nfs01 ~] # mkdir / data/ {blog,zh}-p [root@nfs01 ~] # chown-R www.www / data

5Jing web7 server as nfs client

Yum-y install nfs-utils

Systemctl start rpcbind (client only needs to start rpc)

6. Mount the data directory to the NFS server on the web server

Mount-t nfs 172.16.1.31:/data/blog / code/wordpress/wp-content/uploads/ (web data directory)

Mount-t nfs 172.16.1.31:/data/zh / code/zh/wp-content/uploads/

7, power on and mount automatically

[root@web01 ~] # tail-1 / etc/fstab 172.16.1.31:/data/blog / code/wordpress/wp-content/uploads nfs defaults 0 0

8Bing web8 server as nfs client

Operate as above, web7:

The above is how to split the database and set up NFS shared storage. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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: 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report