(1)了解应用系统需要的基础服务。
(2)安装应用系统需要的基础服务。
| IP 地址 | 主机名 | 节点 |
|---|---|---|
| 192.168.200.128 | mall | 单节点服务器 |
使用 VMWare Workstation 软 件安装 CentOS 7 操作系统,最小化安装 CentOS 7系统,YUM 源使用提供的本地gpmall-repo 包,安装基础环境。
关闭防火墙和selinux,清空防火墙规则,所使用包均从本地上传。
包地址:链接
将提供的 packages 包上传到服务器的/root 目录下,并配置本地 local.repo 文件
cat /etc/yum.repos.d/local.repo [mall] name=mall baseurl=file:///root/gpmall-repo gpgcheck=0 enabled=1安装基础服务
安装基础服务,包括 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_332" OpenJDK Runtime Environment (build 1.8.0_332-b09) OpenJDK 64-Bit Server VM (build 25.332-b09, 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
安装 ZooKeeper 服务,将提供的 zookeeper-3.4.14.tar.gz 上传至云主机的/opt 内,解压压缩包命令如下:
[root@mall ~]# 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: /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
安装 Kafka 服务,将提供的 kafka_2.11-1.1.1.tgz 包上传到云主机的/opt 目录下,解压该压缩包,命令如下:
tar -zxvf kafka_2.11-1.1.1.tgz
进入到 kafka_2.11-1.1.1/bin 目录下,启动 Kafka 服务,命令如下:
[root@mall bin]# ./kafka-server-start.sh -daemon ../config/server.properties
使用 jps 或者 netstat –ntpl 命令查看 Kafka 9092端口是否成功启动,命令如下:
[root@mall bin]# jps 10129 QuorumPeerMain 19220 Jps 10763 Kafka
[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 1008/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 887/master tcp6 0 0 :::9092 :::* LISTEN 6039/java tcp6 0 0 :::46949 :::* LISTEN 6039/java tcp6 0 0 :::2181 :::* LISTEN 1722/java tcp6 0 0 :::48677 :::* LISTEN 1722/java tcp6 0 0 :::22 :::* LISTEN 1008/sshd tcp6 0 0 ::1:25 :::* LISTEN 887/master启动服务
修改数据库配置文件并启动 MariaDB 数据库,设置 root 用户密码为 123456,并创建gpmall 数据库,将提供的 gpmall.sql 导入。
修改/etc/my.cnf 文件,添加字段如下所示:
[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 ~]# mysqladmin -uroot password 123456 [root@mall ~]# mysql -uroot –p123456
设置 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.00 sec) MariaDB [(none)]> use gpmall; MariaDB [mall]> source /root/gpmall.sql MariaDB [mall]> Ctrl-C -- exit! Aborted [root@mall ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.启动 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.配置 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: 172.16.51.29 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.启动 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.
使 用CRT上传 提 供的 gpmall-shopping-0.0.1-SNAPSHOT.jar 、 gpmall-user-0.0.1-SNAPSHOT.jar 、shopping-provider-0.0.1-SNAPSHOT.jar、user-provider-0.0.1-SNAPSHOT.jar 、dist 这 5 个包部署应用系统,其中 4 个 jar 包为后端服务包,dist 为前端包。
全局变量配置修改/etc/hosts 文件,修改项目全局配置文件如下
[root@server ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.200.128 kafka.mall 192.168.200.128 mysql.mall 192.168.200.128 redis.mall 192.168.200.128 zookeeper.mall部署前端
将 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,添加映射
如果没有default.conf文件修改yum源再安装。
[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;
重启 Nginx 服务,命令如下:
[root@mall ~]# systemctl restart nginx
到此,前端部署完毕。
部署后端将提供的 4 个 jar 包上传到服务器的/root 目录下,并启动,启动命令如下:
[root@mall gpmall]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar & [1] 6432 [root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’ [root@mall gpmall]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar & [2] 6475 [root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’ [root@mall gpmall]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar & [3] 6523 [root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’ [root@mall gpmall]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar & [4] 6563 [root@mall gpmall]# nohup: ignoring input and appending output to ‘nohup.out’
按照顺序运行 4 个 jar 包后,至此后端服务部署完毕。
网站访问打开浏览器,在地址栏中输入 http://IP,访问界面
单击右上角“头像”,进行登录操作,使用用户名/密码为 test/test 进行登录
登录后,可进行购买商品操作,单击首页“地平线 8 号”旅行箱图片
单机完“现在购买”按钮,跳转到提交订单界面
至此,单机部署应用系统完成。



