| IP地址 |主机名 | 节点 |
|–|–|–|–|–|
|192.168.0.11|gpmall |云服务器 |
|192.168.0.12|redis |云数据库redis |
|192.168.0.13|mysql|云数据库MySQL|
使用公有云服务器,要求centos7.5,云数据库MySQL5.6,Redis数据库为4.0,内存容量1GB.
(1)登录云主机
(2)修改主机名
hostnamectl set-hostname gpmall
修改/etc/hosts
[root@gpmall ~]# cat /etc/hosts
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 gpmall gpmall
(3)配置yum源
[root@gpmall ~]# cat /etc/yum.repos.d/local.repo
[mall]
name=mall
baseurl=file:///root/gpmall-repo
gpgcheck=0
enabled=1
(4)
安装基础服务
安装基础服务,包括Java JDK, Nginx等。
(4.1) 安装Java环境
[root@gpmall ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@gpmall ~]# 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)
(4.2)安装elasticsearch服务
[root@gpmall ~]# yum -y install elasticsearch
(4.3)安装nginx服务
[root@gpmall ~]# yum -y install nginx
(4.4)安装ZooKeeper服务
将zookeeper-3.4.14.tar.gz移动到opt目录下,解压命令如下:
[root@gpmall ~]# tar -zxvf zookeeper-3.4.14.tar.gz
进入到zookeeper-3.4.14/conf目录下,将zoo_sample.cfg文件重命名为zoo.cfg,
[root@gpmall conf]# mv zoo_sample.cfg zoo.cfg
进入到zookeeper-3.4.14/bin目录下,启动zookeeper,命令如下:
[root@gpmall 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@gpmall bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: standalone
(4.5)安装kafka服务
将提供的kafka_2.11-1.1.1.tar.gz移动到opt目录下,解压该压缩包,命令如下:
[root@gpmall ~]# tar -zxvf kafka_2.11-1.1.1.tgz
进入到kafka_2.11-1.1.1/bin目录下,启动Kafka服务,命令如下:
[root@gpmall bin]# ./kafka-server-start.sh -daemon ../config/server.properties
使用jps或者netstat -ntpl 命令查看Kafka是否成功启动,命令如下:
[root@gpmall bin]# jps
658 WrapperSimpleApp
8388 QuorumPeerMain
8775 Jps
8711 Kafka
[root@gpmall bin]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 895/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1732/sshd
tcp6 0 0 ::1:25 :::* LISTEN 895/master
tcp6 0 0 :::43136 :::* LISTEN 8388/java
tcp6 0 0 :::9092 :::* LISTEN 8711/java
tcp6 0 0 :::2181 :::* LISTEN 8388/java
tcp6 0 0 :::33397 :::* LISTEN 8711/java
tcp6 0 0 :::22 :::* LISTEN 1732/sshd
运行结果查看到Kafka服务和9092,说明Kafka服务已启动
(5)
启动服务
(5.1)管理云数据库
登录云数据库导入gpmall.sql数据库
导入完成后可以看到
(5.2)配置Elasticsearch服务并启动
配置Elasticsearch服务命令如下:
[root@gpmall ~]# vim /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.1.183
http.port: 9200
最后修改完之后保存退出。然后启动Elasticsearch并设置开机自启,命令如下:
[root@gpmall ~]# systemctl start elasticsearch
[root@gpmall ~]# systemctl enable elasticsearch
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
(5.3)启动nginx服务
启动命令如下
[root@gpmall ~]# systemctl start nginx
[root@gpmall ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
(6)应用系统部署
(6.1) 全局变量配置
修改/etc/hosts文件,修改全局配置文见如下
cat /etc/hosts
192.168.1.83 gpmall
192.168.1.83 kafka.mall
192.168.1.99 mysql.mall
192.168.1.82 redis.mall
192.168.1.83 zookeeper.mall
(6.2) 部署前端
将dist目录下文件复制到Nginx默认路径(首先清空默认路径下的文件)
[root@gpmall ~]# rm -rf /usr/share/nginx/html/*
[root@gpmall ~]# cp -rvf dist/* /usr/share/nginx/html/
修改Nginx配置文件/etc/nginx/nginx.conf,添加映射如下:
[root@gpmall ~]# vim /etc/nginx/nginx.conf
location / {
root /usr/share/nginx/html;
index index.html index.html;
}
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;
}
重启Nginx服务,命令如下
[root@gpmall ~]# systemctl restart nginx
到此,前端部署完毕
(6.3) 部署后端
将提供的4个JAR包上传到/root目录下,并启动,命令如下:
[root@gpmall ~]# nohup java -jar shopping-provider-0.0.1-SNAPSHOT.jar &
[1] 19268
[root@gpmall ~]# nohup java -jar user-provider-0.0.1-SNAPSHOT.jar &
[2] 19312
[root@gpmall ~]# nohup java -jar gpmall-shopping-0.0.1-SNAPSHOT.jar &
[3] 19365
[root@gpmall ~]# nohup java -jar gpmall-user-0.0.1-SNAPSHOT.jar &
[4] 19423
按照顺序执行4个jar包,至此,后端服务部署完毕。
(6.4)网站访问。
打开浏览器,输入http://ip,访问界面。