linux运维、架构之路-数据库迁移
一、wordpress搭建
1、wordpress下载部署
cd /server/tools/ wget https://cn.wordpress.org/wordpress-4.8.1-zh_CN.tar.gz tar xf wordpress-4.8.1-zh_CN.tar.gz mv wordpress/* /application/nginx/html/blog/ chown -R www.www /application/nginx/html/blog/ 注意:确认hosts文件进行了解析 浏览器页面输入blog.etiantian.org/进行wordpress部署 vim wp-config.php可以修改wordpress上的数据库连接参数信息
2、数据库创建管理wordpress用户及授权
create database wordpress; grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456'; select user,host from mysql.user; grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456'; flush privileges;
3、 搭建网站基本流程
①要有网站代码(向开发人员要)
wordpress Discuz DedeCMS……等开源软件
②进入到代码程序目录中,将代码信息移动到站点目录下
mv ./* /application/nginx/html/blog/
③修改站点目录权限
chown -R www.www /application/nginx/html/blog/
④进行网站初始化
create database wordpress; grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456'; grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456'; flush privileges;
4、站点目录严格授权
cd /application/nginx/html chown -R root.root blog/ find blog/ -type f|xargs chmod 644 find blog/ -type d|xargs chmod 755 chown -R www.www blog/wp-content/uploads/
二、数据库迁移
1、备份web01数据库数据
mysqldump -uroot -p123456 --all-databases >/tmp/bak_$(date +%F).sql
2、把备份到的数据远程拷贝到独立数据库db01(172.16.1.51)上面
scp -rp /tmp/bak_2017-09-25.sql 172.16.1.51:/tmp/
3、db01导入数备份的据库信息
mysql -uroot -p123456 </tmp/bak_2017-09-25.sql flush privileges;
4、数据库迁移完毕,修改网站连接数据库的配置文件
vi wp-config.php
注:修改localhost为远程db01的数据库IP地址
此时web服务器的数据库就可以停止服务了,至此数据库迁移完毕
三、站点数据迁移到NFS共享目录
1、将原有目录中的数据移出
/application/nginx/html/blog/wp-content mkdir /tmp/wordpress_backup -p mv uploads/* /tmp/wordpress_backup/
2、NFS服务器上面配置创建共享目录
echo "/data 172.16.1.0/24(rw,sync,all_squash)" >>/etc/exports /etc/init.d/nfs restart showmount -e 172.16.1.31 mount -t nfs 172.16.1.31:/data /application/nginx/html/blog/wp-content/uploads/ mv /tmp/wordpress_backup/* .
3、wordpress博客站点配置文件
[root@web01 extra]# cat blog.conf server { listen 80; server_name blog.etiantian.org; location / { root html/blog; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
4、其它bbs、cms网站搭建类似
dedecms搭建
#软件下载安装
cd /application/nginx/html/www wget http://updatenew.dedecms.com/base-v57/package/DedeCMS-V5.7-UTF8-SP2-Full.tar.gz tar xf DedeCMS-V5.7-UTF8-SP2-Full.tar.gz mv DedeCMS-V5.7-UTF8-SP2-Full/uploads/* . rm -fr DedeCMS-V5.7-UTF8-SP2-Full rm -fr DedeCMS-V5.7-UTF8-SP2-Full.tar.gz cd .. chown -R www.www www/ #数据库授权 create database www; grant all on www.* to 'www'@'172.16.1.%' identified by '123456'; select user,host from mysql.user; grant all on www.* to 'www'@'localhost' identified by '123456'; flush privileges;
BBS搭建
#软件下载安装 cd /application/nginx/html/bbs wget http://download.comsenz.com/DiscuzX/3.4/Discuz_X3.4_SC_UTF8.zip unzip Discuz_X3.4_SC_UTF8.zip rm -fr readme/ utility/ Discuz_X3.4_SC_UTF8.zip mv upload/* . cd .. chown -R www.www bbs/ #数据库授权 create database bbs; grant all on bss.* to 'bbs'@'172.16.1.%' identified by '123456'; select user,host from mysql.user; grant all on bbs.* to 'bbs'@'localhost' identified by '123456'; flush privileges;
成功最有效的方法就是向有经验的人学习!