单节点部署Gpmall

目录

一  、实验目标

二  、实验分析

2.1 规划节点

2.2 基础准备

三  、应用系统基础服务安装

3.1 修改主机名

3.2 配置本地YUM源

3.3 安装基础服务

3.3.1 安装Java环境

3.3.2 安装Redis缓存服务

3.3.3 安装Elasticsearch服务

3.3.4 安装Nginx服务

3.3.5 安装Mariadb服务

3.3.6 安装ZooKeeper服务

3.3.7 安装Kafka服务

3.4 启动服务

3.4.1 启动数据库并配置

3.4.2 启动Redis服务

3.4.3 配置Elasticsearch服务并启动

3.4.4 启动Nginx服务

四  、实验实施

4.1 全局变量配置

4.2 部署前端

4.3 部署后端

4.4 网站访问


一  、实验目标

  1. 了解应用系统需要的基础服务。
  2. 安装应用系统需要的基础服务。
  3. 了解应用系统的部署架构。
  4. 单节点部署gpmall

二  、实验分析

2.1 规划节点

IP地址

主机名

节点

192.168.32.133

Mall

单节点服务器 

2.2 基础准备

使用VMware软件安装Centos操作系统,镜像使用提供的Centos-7x86_64-DVD-1804.iso,最小化安装Centos7系统,YUM源使用提供的本地gpmall-repo包,安装基础环境。

三  、应用系统基础服务安装

3.1 修改主机名

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

[root@localhost ~]# 登出

[root@mall ~]# hostnamectl

   Static hostname: mall

         Icon name: computer-vm

           Chassis: vm

        Machine ID: cb43f51351f8442ea04c753cab14a828

           Boot ID: 9b5b0d53ba944951ab3f815d26463790

    Virtualization: vmware

  Operating System: CentOS Linux 7 (Core)

       CPE OS Name: cpe:/o:centos:centos:7

            Kernel: Linux 3.10.0-862.el7.x86_64

      Architecture: x86-64

修改/etc/hosts配置文件

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.32.133  mall

3.2 配置本地YUM源

将提供的packages包上传到/root目录下,并配置本地local.repo文件。(不需要删除本地自带的YUM源)

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

[mall]

name=mall

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

gpgcheck=0

enabled=1

3.3 安装基础服务

安装基础服务,包括Java JDK 环境库、数据库、Redis、Nginx等,安装基础服务的命令。

3.3.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_312"

OpenJDK Runtime Environment (build 1.8.0_312-b07)

OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

3.3.2 安装Redis缓存服务

[root@mall ~]# yum install -y redis

3.3.3 安装Elasticsearch服务

[root@mall ~]# yum install elasticsearch -y

3.3.4 安装Nginx服务

[root@mall ~]# yum install nginx -y

3.3.5 安装Mariadb服务

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

3.3.6 安装ZooKeeper服务

将提供的zookeeper-3.4.14.tar.gz上传至云主机的/opt内并进行解压。

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

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

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

进入到zookeeper-3.4.14/bin目录下,启动ZooKeeper服务。

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

ZooKeeper JMX enabled by default

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

Starting zookeeper ... STARTED

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

ZooKeeper JMX enabled by default

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

Mode: standalone

3.3.7 安装Kafka服务

将提供的kafka_2.11-1.1.1.tgz包上传到/opt目录下,解压该压缩包。

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

进入到kafka_2.11-1.1.1/bin目录下,启动Kafka服务。

[root@mall opt]# cd kafka_2.11-1.1.1/bin/
[root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties

使用jps或者netstat -ntpl命令查看kafka是否成功启动

[root@mall bin]# jps

10868 Kafka

10506 QuorumPeerMain

10911 Jps
[root@mall bin]# netstat -ntpl

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1108/sshd          

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1400/master        

tcp6       0      0 :::9092                 :::*                    LISTEN      10868/java         

tcp6       0      0 :::2181                 :::*                    LISTEN      10506/java         

tcp6       0      0 :::39251                :::*                    LISTEN      10506/java         

tcp6       0      0 :::36213                :::*                    LISTEN      10868/java         

tcp6       0      0 :::22                   :::*                    LISTEN      1108/sshd          

tcp6       0      0 ::1:25                  :::*                    LISTEN      1400/master

运行结果查看到kafka服务和9092端口,说明kafka已启动。

3.4 启动服务

3.4.1 启动数据库并配置

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

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

[root@mall ~]# cat /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

启动数据库。

[root@mall ~]# systemctl start mariadb

设置root用户的密码为123456并登录。

[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:

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!
[root@mall ~]# mysql -uroot -p123456

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

Your MariaDB connection id is 15

Server version: 10.3.18-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)]>

设置root用户的权限。

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)

将gpmall.sql文件上传到/root目录下。创建数据库gpmall并导入gpmall.sql文件。

MariaDB [(none)]> create database gpmall;

Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> use gpmall;

Database changed

MariaDB [gpmall]> source /root/gpmall.sql

Query OK, 0 rows affected (0.000 sec)

退出数据库并设置开机自启。

MariaDB [mall]> Ctrl-C -- exit!

Aborted

[root@mall ~]# systemctl enable mariadb

3.4.2 启动Redis服务

修改Redis配置文件,编辑/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.4.3 配置Elasticsearch服务并启动

配置Elasticsearch服务。

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

在文件上加入这3条语句。

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.32.133

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.

3.4.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.

四  、实验实施

4.1 全局变量配置

修改/etc/hosts文件,修改项目全局配置文件。

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.32.133 mall

192.168.32.133 kafka.mall

192.168.32.133 mysql.mall

192.168.32.133 redis.mall

192.168.32.133 zookeeper.mall

4.2 部署前端

将dist目录上传至服务器的/root目录下。接着将dist目录下的文件,复制到Nginx默认项目路径。

[root@mall ~]# rm -rf /usr/share/nginx/html/*

[root@mall ~]# cp -rvf dist/* /usr/share/nginx/html/

修改Nginx配置文件/etc/nginx/conf.d/default.conf,添加映射

server {

    listen       80;

    server_name  localhost;


    #charset koi8-r;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {

        root   /usr/share/nginx/html;

        index  index.html index.htm;

    }

     location /user {

            proxy_pass http://127.0.0.1:8082;

        }

    location /shopping {

            proxy_pass http://127.0.0.1:8081;

        }

    location /cashier {

            proxy_pass http://127.0.0.1:8083;

        }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ .php$ {

    #    proxy_pass   http://127.0.0.1;

    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    #location ~ .php$ {

    #    root           html;

    #    fastcgi_pass   127.0.0.1:9000;

    #    fastcgi_index  index.php;

    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    #    include        fastcgi_params;

    #}

    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /.ht {

    #    deny  all;

    #}

}

重启Nginx服务。

[root@mall ~]# systemctl restart nginx

4.3 部署后端

将提供的4个jar包上传到服务器的/root目录下,并启动。

[root@mall ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &

[1] 2085

[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@mall ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &

[2] 2137

[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@mall ~]#  nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &

[3] 2172

[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@mall ~]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &

[4] 2202

[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

按照顺序运行4个jar包,后端部署完毕。

4.4 网站访问

打开浏览器,访问192.168.32.133。

单击右上角“头像”,进行登录操作,使用用户名/密码为test/test进行登录。

进入购买界面,单击“现在购买”进行购买商品操作。

单击“现在购买”跳转到提交订单界面。

单机部署应用系统完成。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>