节点规划
IP | 主机名 | 节点 |
---|---|---|
192.168.100.10 | node-1 | Skywalking实验节点 |
192.168.100.20 | mall | 商城搭建节点 |
(1)修改主机名
修改主机名后,执行bash命令 以生效新主机名
[root@localhost ~]# hostnamectl set-hostname node-1
[root@localhost ~]# bash
[root@node-1 ~]#
(2)上传软件包并解压到/opt/目录下,进入解压的目录并创建data目录
[root@node-1 ~]# ls
anaconda-ks.cfg elasticsearch-7.17.0-linux-x86_64.tar.gz
[root@node-1 ~]# tar -zxvf elasticsearch-7.17.0-linux-x86_64.tar.gz -C /opt/
[root@node-1 ~]# cd /opt/elasticsearch-7.17.0/
[root@node-1 elasticsearch-7.17.0]# mkdir data
(3)修改Elasticsearch配置,在文件中找到并修改如下内容,如果找不到就添加到最后一行
[root@node-1 elasticsearch-7.17.0]# vi config/elasticsearch.yml # 注意我写的是相对路径
# 下面是修改的内容
cluster.name: my-application
node.name: node-1
path.data: /opt/elasticsearch-7.17.0/data
path.logs: /opt/elasticsearch-7.17.0/logs
network.host: 0.0.0.0
cluster.initial_master_nodes: ["node-1"]
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
(4)创建Elasticsearch启动用户,并设置数组及权限
[root@node-1 elasticsearch-7.17.0]# groupadd elsearch
[root@node-1 elasticsearch-7.17.0]# useradd -g elsearch -p elasticsearch elsearch
[root@node-1 elasticsearch-7.17.0]# chown -R elsearch:elsearch /opt/elasticsearch-7.17.0/
(5)修改资源限制及内核配置,添加如下内容
[root@node-1 elasticsearch-7.17.0]# vi /etc/security/limits.conf
* hard nofile 65535
* soft nofile 65535
[root@node-1 elasticsearch-7.17.0]# vi /etc/sysctl.conf
vm.max_map_count=262144
[root@node-1 elasticsearch-7.17.0]# sysctl -p
vm.max_map_count = 262144
[root@node-1 elasticsearch-7.17.0]# reboot
重启后等一段时间在重新连接
(6)启动Elasticsearch服务
[root@node-1 ~]# cd /opt/elasticsearch-7.17.0/
[root@node-1 elasticsearch-7.17.0]# su elsearch
[elsearch@node-1 elasticsearch-7.17.0]$ ./bin/elasticsearch -d
(7)查询端口,存在9200则启动成功
[elsearch@node-1 elasticsearch-7.17.0]$ netstat -ntpl
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
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 -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 :::9200 :::* LISTEN 2396/java
tcp6 0 0 :::9300 :::* LISTEN 2396/java
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 ::1:25 :::* LISTEN -
(8)切换至有桌面的虚拟环境中,使用浏览器访问192.168.100.10:9200(访问不了关闭防火墙,和SELinux)
[root@node-1 elasticsearch-7.17.0]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@node-1 elasticsearch-7.17.0]# setenforce 0
[root@node-1 elasticsearch-7.17.0]# vi /etc/sysconfig/selinux
....
..
SELINUX=disabled
...
..
(1)将提供的软件包上传至node-1节点/root/目录中,并设置jdk如下所示
[root@node-1 ~]# ls
jdk-8u144-linux-x64.tar.gz
[root@node-1 ~]# tar -zxvf jdk-8u144-linux-x64.tar.gz -C /usr/local/
修改profile环境变量文件
[root@node-1 ~]# vi /etc/profile # 在profile文件的最后一行添加如下内容
export JAVA_HOME=/usr/local/jdk1.8.0_144
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
[root@node-1 ~]# source /etc/profile
[root@node-1 ~]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
(2)将提供的软件包上传至node-1并解压到/opt目录下
[root@node-1 ~]# ls
apache-skywalking-apm-es7-8.0.0.tar.gz gpmall-single.tar.gz
[root@node-1 ~]# tar -zxvf apache-skywalking-apm-es7-8.0.0.tar.gz -C /opt/
(3)进入解压后的目录,修改OAP配置文件
[root@node-1 ~]# cd /opt/apache-skywalking-apm-bin-es7/
[root@node-1 apache-skywalking-apm-bin-es7]# vi config/application.yml
....
...
# 集群配置使用单机版
cluster:
selector: ${SW_CLUSTER:standalone}
standalone:
....
...
# 数据库使用
storage:
selector: ${SW_STORAGE:elasticsearch7}
....
..
....
elasticsearch7:
nameSpace: ${SW_NAMESPACE:""}
clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:192.168.100.10:9200}
注意:
(4)启动OAP服务,查询端口,存在11800与12800则启动成功
[root@node-1 apache-skywalking-apm-bin-es7]# ./bin/oapService.sh
SkyWalking OAP started successfully!
[root@node-1 apache-skywalking-apm-bin-es7]# 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 1188/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1446/master
tcp6 0 0 :::9200 :::* LISTEN 2396/java
tcp6 0 0 :::9300 :::* LISTEN 2396/java
tcp6 0 0 :::22 :::* LISTEN 1188/sshd
tcp6 0 0 :::11800 :::* LISTEN 19635/java
tcp6 0 0 ::1:25 :::* LISTEN 1446/master
tcp6 0 0 :::12800 :::* LISTEN 19635/java
(1)由于SkyWaliking UI的默认地址是8080,与很多中间件可能会纯在冲突,修改一下
[root@node-1 apache-skywalking-apm-bin-es7]# vi webapp/webapp.yml # 修改如下内容
.....
...
server:
port: 8888
...
..
(2)启动SkyWalking UI服务
[root@node-1 apache-skywalking-apm-bin-es7]# ./bin/webappService.sh
SkyWalking Web Application started successfully!
(3)查看端口,存在8888则成功启动
[root@node-1 apache-skywalking-apm-bin-es7]# 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 1188/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1446/master
tcp6 0 0 :::9200 :::* LISTEN 2396/java
tcp6 0 0 :::9300 :::* LISTEN 2396/java
tcp6 0 0 :::22 :::* LISTEN 1188/sshd
tcp6 0 0 :::8888 :::* LISTEN 23062/java
tcp6 0 0 :::11800 :::* LISTEN 19635/java
tcp6 0 0 ::1:25 :::* LISTEN 1446/master
tcp6 0 0 :::12800 :::* LISTEN 19635/java
(4)切换到桌面使用浏览器访问 192.168.100.10:8888
(1)修改mall节点主机名,修改主机名后用bash命令刷新生效主机名
[root@mall ~]# hostnamectl set-hostname mall
[root@mall ~]# bash
[root@mall ~]#
修改/etc/hosts配置文件如下:
[root@mall ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.20 mall
(2)配置本地yum源
上传软件包到root目录下并解压,配置local.repo文件
[root@mall ~]# ls
gpmall-single.tar.gz
[root@mall ~]# tar -zxvf gpmall-single.tar.gz -C /root/
[root@mall ~]# rm -rf /etc/yum.repos.d/*
[root@mall ~]# vi /etc/yum.repos.d/local.repo # 按照实际情况修改如下内容
[mall]
name=mall
baseurl=file:///root/gpmall-single/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_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
2)安装Redis缓存服务
[root@mall ~]# yum install -y redis
3)安装Nginx服务
[root@mall ~]# yum install -y nginx
4)安装MariaDB数据库
[root@mall ~]# yum install -y mariadb mariadb-server
安装ZooKeeper服务
[root@mall ~]# tar -zxvf gpmall-single/zookeeper-3.4.14.tar.gz -C /root/
进入到zookeeper-3.4.14/conf目录下,将zoo_sample.cfg文件重命名为zoo.cfg
[root@mall ~]# cd /root/zookeeper-3.4.14/conf/
[root@mall conf]# mv zoo_sample.cfg zoo.cfg
进入到zookeeper-3.4.14/bin目录下,启动ZooKeeper服务
[root@mall conf]# cd ../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
安装Kafka服务
[root@mall bin]# tar -zxvf /root/gpmall-single/kafka_2.11-1.1.1.tgz -C /root/
进入到kafka_2.11-1.1.1/bin目录下,启动Kafka服务
[root@mall bin]# cd /root/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
26324 Jps
22454 QuorumPeerMain
25564 Kafka
[root@mall bin]# netstat -ntpl # 运行结果查看到Kafka服务和9092端口,说明Kafka服务已启动
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 1482/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1223/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1482/master
tcp6 0 0 :::40001 :::* LISTEN 25564/java
tcp6 0 0 :::9092 :::* LISTEN 25564/java
tcp6 0 0 :::2181 :::* LISTEN 22454/java
tcp6 0 0 :::32881 :::* LISTEN 22454/java
tcp6 0 0 :::22 :::* LISTEN 1223/sshd
(4)启动服务
①启动数据库并设置
修改数据库配置文件并启动MariaDB数据库,设置root用户密码为123456,并创建gpmall数据库,将提供的gpmall.sql导入
修改/etc/my.cnf文件,添加字段
[root@mall bin]# cd
[root@mall ~]# vi /etc/my.cnf
[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
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.23-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.000 sec)
MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456' with grant option;
Query OK, 0 rows affected (0.000 sec)
创建数据库gpmall并导入/root/gpmall-single/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-single/gpmall.sql
退出数据库设置开机自启
MariaDB [gpmall]> exit
Bye
[root@mall ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
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。
[root@mall ~]# vi /etc/redis.conf
....
...
#bind 127.0.0.1
protected-mode no
....
..
[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.
③启动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.
(5)应用系统部署
使用提供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为前端包。(包在gpmall-single目录下)
①全局变量配置
修改/etc/hosts文件,修改项目全局配置文件如下(原有的192.168.100.20 mall 映射删除)
[root@mall ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.20 kafka.mall
192.168.100.20 mysql.mall
192.168.100.20 redis.mall
192.168.100.20 zookeeper.mall
②部署前端
清空默认项目路径下的文件,将dist目录下的文件,复制到Nginx默认项目路径(文件在gpmall-single目录下)。
[root@mall ~]# rm -rf /usr/share/nginx/html/*
[root@mall ~]# cp -rf gpmall-single/dist/* /usr/share/nginx/html/
修改Nginx配置文件/etc/nginx/nginx.conf,添加映射
http {
# 其他配置
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
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
到此前端部署完毕
③部署后端
将node-1节点的/opt/apache-skywalking-apm-bin-es7目录下的agent目录复制到mall节点下(密码为node-1的密码)
[root@mall ~]# scp -r 192.168.100.10:/opt/apache-skywalking-apm-bin-es7/agent /root
修改SkyWalking agent配置文件:
[root@mall ~]# vi agent/config/agent.config
....
agent.service_name=${SW_AGENT_NAME:my-application}
agent.sample_n_per_3_secs=${SW_AGENT_SAMPLE:1}
.....
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:192.168.100.10:11800}
将gpmall软件包中提供的4个jar包,放置探针并启动,通过设置启动参数的方式检测系统,启动命令如下:
[root@mall ~]# vi agent/config/agent.config
[root@mall ~]# nohup java -javaagent:/root/agent/skywalking-agent.jar -jar gpmall-single/shopping-provider-0.0.1-SNAPSHOT.jar &
[root@mall ~]# nohup java -javaagent:/root/agent/skywalking-agent.jar -jar gpmall-single/user-provider-0.0.1-SNAPSHOT.jar &
[root@mall ~]# nohup java -javaagent:/root/agent/skywalking-agent.jar -jar gpmall-single/gpmall-shopping-0.0.1-SNAPSHOT.jar &
[root@mall ~]# nohup java -javaagent:/root/agent/skywalking-agent.jar -jar gpmall-single/gpmall-user-0.0.1-SNAPSHOT.jar &
[root@mall ~]# setsebool -P httpd_can_network_connect 1 # httpd访问网络配置
④网站访问
打开浏览器,在地址栏中输入192.168.100.20 访问界面
单击右上角“头像”,进行登录操作,使用用户名/密码为test/test进行登录