部署数据库1

网友投稿 621 2022-05-29

在ChinaSkill-node1实例节点上增加一个MariaDB-10数据库软件的yum源配置文件。配置完成后清楚yum缓存。命令如下:

[root@chinaskill-node1 ~]# vi /etc/yum.repos.d/MariaDB.repo

[MariaDB]

name=MariaDB-10

baseurl=https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64/

gpgcheck=0

enabled=1

[root@chinaskill-node1 ~]# yum clean all && yum repolist

在ChinaSkill-node1实例节点上安装MariaDB-10数据库。命令如下:

[root@chinaskill-node1 ~]# yum install  mariadb mariadb-server -y

在chinaskill-node1实例节点启动mariadb数据库。命令如下:

[root@chinaskill-node2 ~]# systemctl start mariadb

[root@chinaskill-node2 ~]# systemctl enable mariadb

Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.

Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

在chinaskill-node1实例节点初始化mariadb数据库,并设置mariadb数据库的root用户密码为Abc@1234。命令如下:

[root@chinaskill-node1 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n

... skipping.

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y

... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

在chinaskill-node1的实例节点上登录数据库,并创建wordpress数据库,将提供的yunmeng-wordpress.sql数据库导入wordpress数据库中,赋予root用户访问wordpress数据库权限。命令如下:

[root@chinaskill-node1 ~]# mysql -uroot -pAbc@1234

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 25

Server version: 10.1.47-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to root@localhost identified by 'Abc@1234';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to root@'%' identified by 'Abc@1234';

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

在ChinaSkill-node1实例节点上使用yum命令安装nginx服务并启动。命令如下:

[root@chinaskill-node1 ~]# yum install nginx –y

[root@chinaskill-node1 ~]# systemctl start nginx && systemctl enable nginx

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

在ChinaSkill-node2实例节点上安装nginx服务,步骤同上。

在ChinaSkill-node1实例节点上修改nginx的配置文件,使nginx支持php服务,修改完检查配置并重启服务。命令如下:

[root@chinaskill-node1 ~]# vi /etc/nginx/nginx.conf

……

location / {

root   /usr/share/nginx/html;

index  index.php index.html index.htm;

}

location ~ \.php$ {

root           /usr/share/nginx/html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

……

[root@chinaskill-node1 ~]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@chinaskill-node1 ~]# systemctl restart nginx

在ChinaSkill-node2实例节点上修改nginx服务配置文件,步骤同上。

在ChinaSkill-node1实例节点上使用yum命令安装php服务,修改php服务的配置文件中运行用户和组为nginx,并启动。命令如下:

[root@chinaskill-node1 ~]# yum install php-fpm php-mysql –y

[root@chinaskill-node1 ~]# vi /etc/php-fpm.d/www.conf

; RPM: apache Choosed to be able to access some dir as httpd

user = nginx

; RPM: Keep a group allowed to write in log dir.

group = nginx

[root@chinaskill-node1 ~]# systemctl start php-fpm && systemctl enable php-fpm

Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

在ChinaSkill-node2实例节点上安装php服务,步骤同上。

将提供的wordpress-5.0.2-zh_CN.tar.gz压缩包上传至ChinaSkill-node1实例节点的/root目录并解压,命令如下:

[root@chinaskill-node1 ~]# tar -zxvf wordpress-5.0.2-zh_CN.tar.gz

删除nginx服务的项目目录/usr/share/nginx/html中默认页面文件,将解压的wordpress目录中文件上传到目录/usr/share/nginx/html中,并赋予777权限。命令如下:

[root@chinaskill-node1 ~]# rm -rfv  /usr/share/nginx/html/*

[root@chinaskill-node1 ~]# cp -r /root/wordpress/* /usr/share/nginx/html/.

[root@chinaskill-node1 ~]# chmod 777 /usr/share/nginx/html/*

在/usr/share/nginx/html目录下,可以看见一个wp-config-sample.php配置文件,该文件是WordPress应用提供了一个模板配置文件,将该模板复制一份并改名为wp-config.php,然后编辑该文件,配置wordpress应用访问数据库。命令如下:

[root@chinaskill-node1 ~]# cp -r /usr/share/nginx/html/wp-config-sample.php /usr/share/nginx/html/wp-config.php

[root@chinaskill-node1 ~]# vi /usr/share/nginx/html/wp-config.php

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //

/** WordPress数据库的名称 */

define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */

define('DB_USER', 'root');

/** MySQL数据库密码 */

define('DB_PASSWORD', 'Abc@1234');

/** MySQL主机 */

define('DB_HOST', '192.168.1.13');

/** 创建数据表时默认的文字编码 */

define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */

define('DB_COLLATE', '');

访问chinaskill-node1实例节点的wordpress应用,wordpress首页如图17所示。

wordpress应用

在ChinaSkill-node2实例节点上部署wordpress应用,步骤同上,wp-config.php文件配置相同。

点击云产品登录负载均衡控制台,负载均衡选项位置如图18所示。

负载均衡

在负载均衡控制台点击新建,进入负载均衡服务购买页面,地域选择上海(与云服务器在相同的地域即可),网络选择intnet1,实例名设置为chinaskill-clb。如图19所示。

部署数据库1

购买负载均衡

配置完成后点击立即购买完成负载均衡服务新建。生成负载均衡服务,负载均衡服务的VIP地址为81.69.165.236,如图20所示。

负载均衡服务

点击进入负载均衡实例chinaskill-clb,选择安全组。如图21所示。

负载均衡安全组

点击绑定,在弹出的对话框中选中Chinaskll-security-group安全组,点击确定。如图22所示。

绑定安全组

进入负载均衡实例chinaskill-clb,选择-管理。如图23所示。

-

点击新建,在弹出的对话框中,设置名称为wordpress,端口协议HTTP,端口为80的-,点击提交完成创建。如图24所示。

新建-wordpress

选择wordpress-的‘+’添加规则按键,在弹出来的对话框中,设置域名为负载均衡实例的vip地址,URL路径设置为‘/’,点击下一步,默认设置不修改,点击下一步,默认设置不修改,点击提交完成新建。如图25所示。

新建规则

点击打开wordpress-和81.69.165.236域名的‘+’按键,选中‘/’,在右侧出现的“已绑定后端服务”中选中绑定选项,在弹出的对话框中,选中云服务器下的ChinaSkill-node1实例节点和ChinaSkill-node2实例节点,端口设置为80,点击确认完成绑定。如图26所示。

绑定后端服务

稍作等等,确认端口健康状态为健康。我们就可以通过负载均衡实例节点的VIP地址http://81.69.165.236/访问wordpress应用。如图27所示。

vip访问wordpress

在ChinaSkill-node1实例节点wordpress应用部署目录中创建wordpress应用图片存放目录uploads。

[root@chinaskill-node1 ~]# cd /usr/share/nginx/html/

[root@chinaskill-node1 html]# mkdir wp-content/uploads

在Chinaskill-node1实例节点中,将nfs共享目录挂载到wordpress应用图片存放目录uploads中。

[root@chinaskill-node1 html]# mount -t nfs 192.168.1.4://nfs/code wp-content/uploads/

在ChinaSkill-node2实例节点共享存储,步骤如上所述。

登录ChinaSkill-node2实例节点,进入nfs服务的共享目录,创建/nfs/code/2020/10目录,并将提供的wordpress.png图片文件上传到/nfs/code/2020/10目录。

[root@chinaskill-node2 ~]# cd /nfs/code/

[root@chinaskill-node2 code]# mkdir -p 2020/10

[root@chinaskill-node2 code]# ll 2020/10/

total 68

-rw-r--r-- 1 root root 69571 Oct 26 18:28 wordpress.png

这样ChinaSkill-node1实例节点和ChinaSkill-node2实例节点的wordpress应用的图片存储目录中就有了nfs共享的图片。

[root@chinaskill-node1 ~]# ll /usr/share/nginx/html/wp-content/uploads/2020/10/

total 68

-rw-r--r-- 1 root root 69571 Oct 26 18:28 wordpress.png

[root@chinaskill-node2 ~]# ll /usr/share/nginx/html/wp-content/uploads/2020/10/

total 68

-rw-r--r-- 1 root root 69571 Oct 26 18:28 wordpress.png

访问http://81.69.165.236/地址,可以看到我们上传的wordpress.png图片。这是云梦科技wordpress博客网站文章中原来就存在的图片,现在提供了图片文件后就可以在网页中看见了。如图28所示。

WordPress 数据库

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:NIO之缓冲区【复制缓冲区】
下一篇:Velero 二次开发-02
相关文章