目录
1.部署后端服务
注册中心eureka服务配置指定生产服务器地址
服务网关配置指定生产服务器地址
认证中心配置,数据库使用Jenkins中的数据库
活动微服务配置
数据库脚本导入Jenkins服务器中的MySQL
mysql> create database tensquare_user;
mysql> use tensquare_user;
mysql> source /opt/tensquare_user.sql;
mysql> create database tensquare_gathering;
mysql> use tensquare_gathering;
mysql> source /opt/tensquare_gathering.sql;
mysql> grant all privileges on *.* to 'root'@'%' identified by 'abc123' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec) #授权远程登录
准备完毕,可以直接部署所有微服务
查看生产服务器中容器列表
查看注册中心
使用postman测试后台数据连接
2.部署前端静态web网站
生产服务器安装Nginx服务器
[root@docker ~]# yum install epel-release
[root@docker ~]# yum -y install nginx
[root@docker ~]# vim /etc/nginx/nginx.conf
...
server {
listen 9090; #默认端口80,修改端口为9090
listen [::]:9090;
server_name _;
root /usr/share/nginx/html;
[root@docker ~]# systemctl enable nginx #设置开机启动
[root@docker ~]# systemctl start nginx #启动
[root@docker ~]# systemctl stop nginx #停止
[root@docker ~]# systemctl restart nginx #重启
浏览器访问
安装NodeJS插件
插件安装完成后
Manage Jenkins->Global Tool Configuration
创建前端流水线项目
在创建的项目里设置参数
编写流水线脚本
def git_auth="gitlab-auth-ssh"
node {
stage('pull code') {
//切换成变量,字符串符号使用双引号
checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: 'git@192.168.100.135:kgc/tensquare_front.git']]])
}
stage('make package,deploy') {
//使用nodejs的npm打包
nodejs('nodejs12'){
sh '''
npm install
npm run build
'''
}
//远程部署
sshPublisher(publishers: [sshPublisherDesc(configName: 'master_server', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '/usr/share/nginx/html', remoteDirectorySDF: false, removePrefix: 'dist', sourceFiles: 'dist/**')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
在本地找到前端项目
用小乌龟这个软件进行推送
推送完成后,查看是否推送成功
推送成功后,开始构建
构建成功后,查看能否看到后端的数据
生产服务器验证查看/usr/share/nginx/html根目录