centos7.2系统部署应用系统商城(单节点)

网上购物,我相信在现如今互联网如此发达的时代下,各位都有使用过。那么本次实验将以centos7.2系统的一台主机即单节点来实现部署本地的网上应用系统商城。

本次所需要的实验资源包已上传至百度网盘,需要自取。

链接:https://pan.baidu.com/s/1a-7_iAIX0DBAMkF9bhiTcA?pwd=2333 
提取码:2333 
复制这段内容后打开百度网盘手机App,操作更方便哦。

因为是本地搭建的,所以不需要通外网,网卡模式就不做要求了,至于地址配置也可以依据个人喜好定义。如果是初学者建议将地址网段改为和我一样跟着做。以防止地址修改不得当导致实验失败。个人配置网段如下:

首先开机以后先配置网卡地址(还是那句话,你要dhcp做也可以,但是地址会波动不稳定。)

记得重启网络服务。

然后我们修改一下主机名,随后提前做好主机映射。防止后续安装的各个服务组建起来却无法连通解析的情况。bash命令是用来立即刷新系统信息的,可以看到执行命令后主机名默认由localhost变成了mall。(在这个实验中的主机名必须是mall,因为到时候跑的jar项目包中的各个服务的主机名都是配置为mall。)

进入主机映射文件进行配置。可以看到我们需要用到的服务都进行了主机地址映射。

上传软件资源包配置本地yum源。

先把本地网络源给移走,然后自己编辑一份本地源文件。

然后创建本地仓库目录加镜像挂载。

将软件资源包通过ssh等方式上传,我这边对应我本地源的配置文件放在了root目录下。

安装java环境。

安装完毕以后检查版本。

安装redis缓存服务。

安装nginx服务和mariadb数据库。

安装到一半想起来防火墙没关,这里把防火墙关一下。(做这些个人学习实验一定要记得开始实验前就把防火墙统统关干净)

我们这次直接深入到防火墙的配置文件中进行关闭,防止虚拟机重启后防火墙自己又启动导致实验各服务无法连通。

我们再继续安装zookeeper服务。

这里采用的是本地安装包直接上传解压使用,我将该服务文件解压至opt目录下使用。

之后进到该服务的配置文件目录下将模板配置文件更名为配置文件,再到启动目录进行启动。

查看一下服务的状态有没有问题。

我们再安装一个Kafka服务,同样采用本地安装包上传解压的方式使用。换汤不换药几乎一样的步骤。

我还是上传在root目录下所有待会解压我会cd回root目录下进行。

然后进入到启动目录下使用命令启动。

使用jps命令查看是否启动。

当然安装网络工具包后查看端口也可以。

接着我们修改数据库配置文件并启动数据库,然后上传数据库文件进行导入。

#
# 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

启动数据库。

之后初始化数据库修改数据库密码为123456(这里一定要是123456的数据库密码,因为后面打包好的jar项目包中对mysql数据库的配置密码设为123456了,你改成其他的会导致到时候启动jar项目无法访问连接数据库。)

[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:                               #输入数据库root密码123456
Re-enter new password:                        #重复输入密码123456
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!

随后登录mysql中设置root用户权限。

[root@mall ~]# mysql -u root -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
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)]> 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)

创建数据库并导入sql数据库文件。这里依旧是把sql数据库文件上传至root目录。

因为我们这次实验是单节点部署,所以是这个资源包中的sql文件。

MariaDB [(none)]> create database gpmall;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> use gpmall;
MariaDB [mall]> source /root/gpmall.sql

ctrl+c键退出数据库界面,当然输入exit命令回车也行。

然后我们将数据库添加为自启动也可以顺路重启一下数据库。

接下来我们需要启动redis缓存服务。

先修改配置文件。

进入vi界面后输入如下命令回车快速跳转到该条目进行修改。

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

最后启动该服务并且添加自启动条目。

最后我们配置nginx部署前端即网站页面。

同样将单节点资源文件夹中的dist目录上传至root目录下。

接着先清空nginx网页目录下的默认网页然后复制替换上我们dist中的网页。

因为这个文件夹在root目录下,所以记得cd到root目录上执行复制命令。

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

接着进入nginx的默认配置文件中添加服务代理配置。

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

新加了3块代理服务配置用于对应上后端jar的配置来让整个应用系统商城运行起来。

重启服务。

最后我们来部署后端,上传4个jar包来运行。这边一定要按顺序来运行。

如果确定自己的搭建都没问题了陆续使用如下命令来跑。一共就4条命令,忽略输出是这条不是手打的命令而是执行这个命令给的回显。

[root@mall ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[1] 14758
[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@mall ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 14811
[1]   退出 1                nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar
[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[2]+  退出 1                nohup java -jar user-provider-0.0.1-SNAPSHOT.jar
[root@mall ~]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[1] 14863
[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@mall ~]#  nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[2] 14887
[root@mall ~]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@mall ~]#

如果不确定自己跑的有没有问题就不要加上nohup这个命令来跑jar包,这可以会展示运行过程的回显给我们看。如果出问题了则会卡住报错,可以根据报错来找到问题所在并解决再重新跑一遍至整个应用商城可以起来为止。每跑一个都会有大量运行过程的回显,成功有成功的英文提示,失败了则会抛出异常并且告知原因。一定要跑完一个并且成功了再回车出来跑一下个,有失败的地方就要退出来先去解决。

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

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

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

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

[root@mall ~]#

这是我不通过忽略回显参数命令跑的第一个包,最后就提示连接上了并且告诉我这个SpringBoot项目等待一会即可,这就说明跑好了第一个。我们继续跑下一个一直到全跑完就行了。

第二包是这样的成功回显。

第三包。

最后一包。

接着我们使用本地机的浏览器输入ip地址便可以访问到我们的本地电商平台了。

打开浏览器,在地址栏中输入http://172.16.51.29,访问界面。

这还没有结束实验,我们需要继续测试其余的服务是否生效可用。

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

登录后我们随便点个东西买买看。

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

我们也能看到,当我进行一些操作的时候,后台也会返回回显给我。

以及我做出了一些错误的数据添加更新请求也会返回报错回显。

那么,本次使用centos7.2系统单节点部署应用系统商城的实验就完成啦!

  • 38
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值