安装宝塔、MySQL、Redis、nginx等

可以看我之前写的 homie 配的安装步骤:https://www.yuque.com/yuqueyonghujneqfl/mdllyi/oorztzenfglow99q?singleDoc#

安装 RabbitMQ

和安装 Redis 类似,进入宝塔的软件商店搜索 RabbiMQ,点击管理权限设置 MQ 的用户名和密码,同时 prod.yml 的 RabbitMQ 的用户名和密码和这个是一样的,另外别忘了在服务器和宝塔面板开放15672端口和5672端口

img

在浏览器访问 服务IP地址:15672 点击Admin的 Tab 栏,点击 Admin,点击 set permission,保证admin 角色有权限

img

img

注意:在服务器和宝塔面板开放MySQL(3306)、Redis(6379)、nginx(80)、RabbitMQ(15672、5672)等端口

前端部署

修改 app.tsx 文件,添加线上地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import Footer from '@/components/Footer';
import {Question} from '@/components/RightContent';
import {getLoginUserUsingGET} from '@/services/yubi/userController';
import {SettingDrawer} from '@ant-design/pro-components';
import type {RunTimeLayoutConfig} from '@umijs/max';
import {history} from '@umijs/max';
import {AvatarDropdown, AvatarName} from './components/RightContent/AvatarDropdown';
import {errorConfig} from './requestConfig';

const isDev = process.env.NODE_ENV === 'development';
const loginPath = '/user/login';

/**
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* */
export async function getInitialState(): Promise<{
currentUser?: API.LoginUserVO;
settings?: any;
}> {
const fetchUserInfo = async () => {
// 如果不是登录页面,执行
const { location } = history;

try {
const res = await getLoginUserUsingGET();
return res.data;
} catch (error) {
history.push(loginPath);
}
return undefined;
};

if (location.pathname !== loginPath) {
const currentUser = await fetchUserInfo();
return {
currentUser,
};
}
return {};
}

// ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
return {
...(initialState as { currentUser?: API.LoginUserVO; settings?: any; }).settings,
actionsRender: () => [<Question key="doc" />],
avatarProps: {
src: initialState?.currentUser?.userAvatar,
title: <AvatarName />,
render: (_, avatarChildren) => {
return <AvatarDropdown>{avatarChildren}</AvatarDropdown>;
},
},
waterMarkProps: {
content: initialState?.currentUser?.userName,
},
footerRender: () => <Footer />,
onPageChange: () => {
const { location } = history;
// 如果没有登录,重定向到 login
if (!initialState?.currentUser && location.pathname !== loginPath) {
history.push(loginPath);
}
},
layoutBgImgList: [
{
src: 'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/D2LWSqNny4sAAAAAAAAAAAAAFl94AQBr',
left: 85,
bottom: 100,
height: '303px',
},
{
src: 'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/C2TWRpJpiC0AAAAAAAAAAAAAFl94AQBr',
bottom: -68,
right: -45,
height: '303px',
},
{
src: 'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/F6vSTbj8KpYAAAAAAAAAAAAAFl94AQBr',
bottom: 0,
left: 0,
width: '331px',
},
],
menuHeaderRender: undefined,
// 自定义 403 页面
// unAccessible: <div>unAccessible</div>,
// 增加一个 loading 的状态
childrenRender: (children) => {
// if (initialState?.loading) return <PageLoading />;
return (
<>
{children}
<SettingDrawer
disableUrlParams
enableDarkTheme
settings={initialState?.settings}
onSettingChange={(settings) => {
setInitialState((preInitialState) => ({
...preInitialState,
settings,
}));
}}
/>
</>
);
},
...initialState?.settings,
};
};

/**
* @name request 配置,可以配置错误处理
* 它基于 axios 和 ahooks 的 useRequest 提供了一套统一的网络请求和错误处理方案。
* @doc https://umijs.org/docs/max/request#配置
*/
export const request = {
baseURL: isDev ? 'http://localhost:8081' : 'http://backendlingxibi.hejiajun.icu', // 后端地址
withCredentials: true,
...errorConfig,
};

点击 package.json 文件执行 build 开始打包

随后在宝塔 PHP 项目新建一个站点,设置一个域名

img

修改 nginx 配置文件,添加如下配置,防止出现 404

1
2
3
location / {
try_files $uri /index.html;
}

注意:服务器开放 nginx 的80端口

后端部署

在后端配置跨域

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
// 覆盖所有请求
registry.addMapping("/**")
// 允许发送 Cookie
.allowCredentials(true)
// 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突)
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.exposedHeaders("*");
}
}

修改 RedissonConfig 类添加 Redis 密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {

private String host;

private String port;

private String password;

@Bean
public RedissonClient redissonClient(){
// 1. 创建配置
Config config = new Config();
String redisAddress = String.format("redis://%s:%s", host, port);
config.useSingleServer().setAddress(redisAddress).setDatabase(1).setPassword(password);//设置单个服务器,设置地址,选择数据库
// 2. 创建实例
RedissonClient redisson = Redisson.create(config);
return redisson;
}
}

修改 prod-yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
server:
address: 0.0.0.0
port: 8081
servlet:
context-path: /api
# cookie 30 天过期
session:
cookie:
max-age: 2592000
domain: 顶级域名
same-site: lax
secure: false
spring:
# 数据库配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://服务器地址/lingxibi
username: 账号
password: 密码
session:
store-type: redis
timeout: 2592000
# Redis 配置
redis:
database: 0
host: localhost
port: 6379
password: 密码
rabbitmq:
host: localhost
port: 5672
username: 账号
password: 密码
publisher-confirm-type: correlated #开启发布确认模式为异步确认
publisher-returns: true
# Elasticsearch 配置
elasticsearch:
uris: http://服务器地址:9200
username: 账号
password: 密码
application:
name: Lingxi-BI
# 接口文档的配置
springdoc:
group-configs:
- group: 'default'
packages-to-scan: com.hjj.lingxibi.controller
# MyBatis-Plus配置
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: isDelete
logic-delete-value: 1
logic-not-delete-value: 0

# 鱼聪明AI配置
yuapi:
client:
access-key:
secret-key:

随后点击利用 Maven 打包 Java 项目

点击左侧 Tab 栏文件新建后端文件夹为 lingxi-backend 并把打包后的 jar 包放在该文件夹下

img

在网站的 Java 项目中添加 Java 项目,,同时服务器和宝塔面板开放 8081 端口,注意项目 jar 路径要和上面 jar 包路径一样

img

在 PHP 项目中新建一个站点,此域名为后端域名与前端 app.tsx 中的线上地址一致

img

接着再点击此站点点击方向代理,配置方向代理,为了不把后端地址暴露出来

img

最后启动 Java 项目,成功了就很好,没有成功就查看项目日志看哪里报错了

注意:服务器开放 Spring Boot 端口 8081

Centos 安装 ELK

Centos 安装 Elasticsearch 和 ik 分词器

只看 Elasticsearch 和 ik 分词器的安装步骤就行,其他不用看

教程1:https://blog.csdn.net/qq_45502336/article/details/122023493

教程2:https://blog.csdn.net/smilehappiness/article/details/118466378

下载地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/install-elasticsearch.html

Centos 安装 kibana

教程:https://blog.csdn.net/qq_29917503/article/details/126768884

在浏览器输入 IP地址:5601,进入 kibana 点击dev tool,随后创建 chart_v1 索引

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
PUT chart_v1
{
"aliases": {
"chart": {}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"goal": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"chartData": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"chartType": {
"type": "keyword"
},
"genResult": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "keyword"
},
"userId": {
"type": "keyword"
},
"createTime": {
"type": "date"
},
"updateTime": {
"type": "date"
},
"isDelete": {
"type": "keyword"
}
}
}
}

Centos 安装 logstash

https://blog.csdn.net/made4971/article/details/119322088 (跟着安装就行,不比跟着他一样做同步)

logstash 同步 MySQL 数据到 ES

进入 MySQL 官网:https://dev.mysql.com/downloads/connector/j/ 下载 mysql-connector-j 的压缩包

img

利用 finalshell 工具把它丢在 logstash 安装目录的根目录下面,注意是根目录不是 bin 目录

img

接着解压压缩包

1
unzip mysql-connector-j-8.3.0.zip

解压完会得到一个文件夹,随后进入文件夹,把 jar 包移动 logstash 根目录下面,然后再把压缩包删除

1
2
3
cd mysql-connector-j-8.3.0
mv mysql-connector-j-8.3.0.jar ../
rm -f mysql-connector-j-8.3.0.zip

进入 lostash 的 bin 目录创建 bitask.conf 文件 ,写入如下配置,

1
vim bin/bitask.conf

bitask.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
input {
jdbc {
jdbc_driver_library => "E:\study\ELK\logstash-7.17.18\config\mysql-connector-j-8.0.31.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/lingxibi"
jdbc_user => "数据库账号"
jdbc_password => "数据库密码"
use_column_value => true
tracking_column => "updatetime"
tracking_column_type => "timestamp"
schedule => "*/5 * * * *"
statement => "SELECT * from chart where updateTime > :sql_last_value and updateTime < now() order by updateTime desc"
jdbc_default_timezone => "Asia/Shanghai"
}
}

filter {
mutate {
rename => {
"updatetime" => "updateTime"
"userid" => "userId"
"createtime" => "createTime"
"isdelete" => "isDelete"
"charttype" => "chartType"
"data" => "chartData"
}
remove_field => ["genchart", "genresult", "execmessage"]
}
}


output {
stdout { codec => rubydebug }
elasticsearch {
hosts => "127.0.0.1:9200"
index => "chart_v1"
document_id => "%{id}"
}
}

最后进入 bin 目录启动 logstash

1
2
cd bin
./logstash -f bitask.conf

注意:

  1. ES、kibana、logstash 和 ik 分词器的版本要一致,我的都是 7.17.18,别安装 8.x 版本(bug 多)。
  2. ES 和 kibana 启动不能使用 root 用户启动,必须要新建一个新的用户来启动
  3. ES、kibana 的端口一定要在服务器和宝塔面板中开发,9200、5601