首页 > 技术文章 > 单节点部署应用商城(上)

tcq123 2021-04-02 16:16 原文

单节点部署应用商城(上)

 

我自己把单节点部署分为以下5个步骤,所以做的时候就会简单好记些。

【案例分析】

(1)规划节点

IP地址

主机名

节点

192.168.200.30

Mall

单节点服务器

(2)需要准备gpmall-repo安装包,kafka、zookeeper压缩包,gpmall.sql

(3)部署前端需要的dist文件,部署后端的4个jar包

【案例实施】

1. 修改主机名

修改主机名命令如下所示:

[root@localhost ~]# hostnamectl set-hostname mall

[root@localhost ~]# bash //重新加载

[root@mall ~]# echo “192.168.200.30 mall” >> /etc/hosts

2. 配置本地YUM

将提供的gpmall-repo包上传到服务器的/root目录下,并配置本地local.repo文件,具体代码如下所示:

[root@mall ~]# cat /etc/yum.repos.d/local.repo

[mall]

name=mall

baseurl=file:///root/gpmall-repo

gpgcheck=0

enabled=1

3. 安装基础服务

安装基础服务,包括Java JDK环境、数据库、Redis、Nginx等,安装基础服务的命令具体如下:

1)安装Java环境
[root@mall ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel

[root@mall ~]# java -version

openjdk version "1.8.0_222"

OpenJDK Runtime Environment (build 1.8.0_222-b10)

OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
2)安装Redis缓存服务
[root@mall ~]# yum install redis -y
(3)安装Elasticsearch服务
[root@mall ~]# yum install elasticsearch -y
4)安装Nginx服务
[root@mall ~]# yum install nginx -y
(5)安装MariaDB数据库
[root@mall ~]# yum install mariadb mariadb-server -y
(6)安装ZooKeeper服务

将提供的zookeeper-3.4.14.tar.gz上传至虚拟机的/root,解压压缩包命令如下:

[root@mall ~]# tar -zxvf zookeeper-3.4.14.tar.gz

进入到zookeeper-3.4.14/conf目录下,将zoo_sample.cfg文件重命名为zoo.cfg,命令如下:

[root@mall conf]# cd zookeeper-3.4.14/conf

[root@mall conf]# mv zoo_sample.cfg zoo.cfg

进入到zookeeper-3.4.14/bin目录下,启动ZooKeeper服务,命令如下:

[root@mall conf]# cd zookeeper-3.4.14/bin

[root@mall bin]# ./zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

查看ZooKeeper状态,命令如下:

[root@mall bin]# ./zkServer.sh status

ZooKeeper JMX enabled by default

Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg

Mode: standalone
7)安装Kafka服务

将提供的kafka_2.11-1.1.1.tgz包上传到云主机的/root目录下,解压该压缩包,命令如下:

[root@mall]# tar -zxvf kafka_2.11-1.1.1.tgz

进入到kafka_2.11-1.1.1/bin目录下,启动Kafka服务,命令如下:

[root@mall]# cd kafka_2.11-1.1.1/bin

[root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties

使用netstat –ntpl命令查看Kafka是否成功启动,运行结果查看到Kafka服务和9092端口,说明Kafka服务已启动,如下图所示:

[root@mall bin]# netstat -ntpl  

4. 启动服务

1)启动数据库并配置

修改数据库配置文件并启动MariaDB数据库,设置root用户密码为123456,并创建gpmall数据库,将提供的gpmall.sql导入。

修改/etc/my.cnf文件,添加字段如下所示:

[root@mall ~]# vi /etc/my.cnf

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

 

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

 

[mysqld]

init_connect='SET collation_connection = utf8_unicode_ci'

init_connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_unicode_ci

skip-character-set-client-handshake
2)启动并配置数据库
[root@mall ~]# systemctl start mariadb

[root@mall ~]# 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: //输入密码000000

Re-enter new password: //再次输入000000

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] //默认回车

 ... Success!

 

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] //默认回车

 - 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] //默认回车

 ... 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! //数据库配置完毕

3)创建数据库gpmall,并将gpmall.sql导入

[root@mall ~]# mysql -uroot -p000000

MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option;

Query OK, 0 rows affected (0.001 sec)

 

MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456' with grant option;

Query OK, 0 rows affected (0.001 sec)

 

MariaDB [(none)]> create database gpmall; //创建数据库gpmall

Query OK, 1 row affected (0.001 sec)

 

MariaDB [(none)]> Ctrl-C -- exit!

Aborted

 

[root@mall ~]# mysql -uroot -p -D gpmall < gpmall.sql

Enter password:000000 //导入数据库
(3)启动Redis服务

修改Redis配置文件,编辑/etc/redis.conf文件。

[root@mall ~]# vi /etc/redis.conf

bind 127.0.0.1这一行注释掉;将protected-mode yes 改为 protected-mode no。

启动Redis服务命令如下。

[root@mall ~]# systemctl start redis

[root@mall ~]# systemctl enable redis

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

(3)配置Elasticsearch服务并启动

配置Elasticsearch服务命令如下:

[root@mall ~]# vi /etc/elasticsearch/elasticsearch.yml

http.cors.enabled: true //在最上面加入这三条语句

http.cors.allow-origin: "*"

http.cors.allow-credentials: true

将如下4条语句前的注释符去掉,并修改network.host的IP为本机IP。

cluster.name: my-application

node.name: node-1

network.host: 192.168.200.30

http.port: 9200

最后修改完之后保存退出。然后启动Elasticsearch并设置开机自启,命令如下:

[root@mall ~]# systemctl start elasticsearch

[root@mall ~]# systemctl enable elasticsearch

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

(4)启动Nginx服务

启动Nginx服务命令如下:

[root@mall ~]# systemctl start nginx

[root@mall ~]# systemctl enable nginx

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

至此,单节点部署应用商城的基本环境已经准备完毕,下一篇,我们部署前端和后端。

推荐阅读