jeesns项目代码部署and自动上线

root
233
文章
0
评论
2020年3月3日12:24:22 评论 6044字阅读20分8秒

jeesns项目代码自动上线

经过上一次失败的教训,这一次通过学习了maven项目管理工具,肯定能部署成功的。失败案例jeesns项目上线(失败案例)这对java项目的部署是一次很好的学习

Jenkins上的操作

新建一个项目,类型选maven

源码管理里获取git,gitlab上的项目地址(偷笑,这里偷了贪,图片用的大转盘项目的,哈哈)

配置密钥

配置一下,这里提示找不到maven的路径。因为我们maven是手动安装的, 不是jenkins自动安装,需要指定一下maven所在的路径

解决这问题方法:

在选全局配置选项

找到maven选项,取消自动安装

进行指定maven,安装路径

再看看问题已经解决了

 

手动打包就成功

 

但用Jenkins自动打包就不行了,报错

[INFO] jeesns ............................................. SUCCESS [  0.474 s]
[INFO] jeesns-service ..................................... FAILURE [  0.276 s]
[INFO] jeesns-web ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.832 s
[INFO] Finished at: 2020-03-03T12:14:26+08:00
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal on project jeesns-service: Could not resolve dependencies for project com.lxinet:jeesns-service:jar:1.4.2: Failure to find com.lxinet:jeesns-core:jar:1.4.2 in https://maven.aliyun.com/repository/public was cached in the local repository, resolution will not be reattempted until the update interval of aliyunmaven has elapsed or updates are forced -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[JENKINS] Archiving /var/lib/jenkins/workspace/jeesns-job/pom.xml to com.lxinet/jeesns/1.4.2/jeesns-1.4.2.pom
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :jeesns-service

卡住了,这个问题有待解决....

我怎么排查都不知道到底是哪里错了,已经好多天了,就在一筹莫展之时,难道是软件代码本身的问题?,然后我去下载了,jeesns_v1.3版本的,把原先的那个1.4从远程仓库删除,发现正常了,我真是个机灵鬼

jenkins虐我千百遍,我带它如...rz,哼哼,来来来,继续肝,肝起来

 

Tomcat服务器上操作

部署tomcat和数据库

这里我只需要部署tomcat,mysql我已经提前部署好了

[root@kk tools]# tar xf apache-tomcat-8.5.50.tar.gz 
[root@kk tools]# ln -s apache-tomcat-8.5.50 tomcat

还需要安装jdk,因为我以前安装过jdk,要找jdk的默认安装路径方法:

首先是确认是否安装JDK

[root@kk tools]# java -cersion
Unrecognized option: -cersion
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

然后查找java命令的位置

[root@kk tools]# which java
/usr/bin/java

查找java命令的位置所对于的软链地址

[root@kk tools]# ls -l /usr/bin/java
lrwxrwxrwx. 1 root root 22 Sep  3 08:23 /usr/bin/java -> /etc/alternatives/java

最后通过软链地址查找JDK的安装目录

[root@kk tools]# ls -l /etc/alternatives/java
lrwxrwxrwx. 1 root root 72 Sep  3 08:23 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre/bin/java

修改文件

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre/lib/security/java.security

[root@kk tools]# vim /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre/lib/security/java.security

在117行,修改

securerandom.source=file:/dev/urandom

启动tomcat

[root@kk tools]# sh tomcat/bin/startup.sh
Using CATALINA_BASE:   /server/tools/tomcat
Using CATALINA_HOME:   /server/tools/tomcat
Using CATALINA_TMPDIR: /server/tools/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /server/tools/tomcat/bin/bootstrap.jar:/server/tools/tomcat/bin/tomcat-juli.jar
Tomcat started.


创建jeesns的数据库

下载安装过程就不写了,不会的请看一下编译安装MySQL

mysql> create database jeesns;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| jeesns             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.03 sec)

将jeesns的数据库表导入数据库

这里你去jeenkins上把表发过来,或者用rsync把表拉去过来

因为jeesns项目在gitlab仓库上由jenkins持续集成工具拉去到本地192.168.5.31服务器上,jeesnsn项目的数据表要先传到tomcat服务器,tomcat服务器IP192.168.5.41,才能导入数据库

/var/lib/jenkins/workspace/jeesns-job/jeesns-web/database

[root@nfs01 database]# pwd
/var/lib/jenkins/workspace/jeesns-job/jeesns-web/database
[root@nfs01 database]# ll
total 40
-rwxr-xr-x 1 jenkins jenkins 28667 Mar  3 15:16 jeesns.sql
-rw-r--r-- 1 jenkins jenkins  3491 Mar  3 15:16 update_1.2.0to1.2.1.sql
-rw-r--r-- 1 jenkins jenkins  1026 Mar  3 15:16 update_1.2.1to1.3.sql
-rw-r--r-- 1 jenkins jenkins  1344 Mar  3 15:16 update_1.3to1.3.1.sql
[root@nfs01 database]# rsync -avz jeesns.sql root@192.168.5.41:/server/tools/
sending incremental file list
jeesns.sql

sent 5711 bytes  received 31 bytes  11484.00 bytes/sec
total size is 28667  speedup is 4.99

去192.168.5.41服务器上确认一下

[root@backup ~]# cd /server/tools/
[root@backup tools]# ll
total 507540
drwxr-xr-x 9 root root       220 Mar  3 17:17 apache-tomcat-8.5.50
-rwxr-xr-x 1  665  665     28667 Mar  3 15:16 jeesns.sql

把jeesns.sql进行导入数据库

[root@backup tools]# mysql -uroot -pHe30772818. jeesns < /server/tools/jeesns.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

查看是否导入成功

[root@backup tools]# mysql -uroot -pHe30772818. -e "use jeesns;show tables"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------------+
| Tables_in_jeesns          |
+---------------------------+
| tbl_action                |
| tbl_action_log            |
| tbl_ads                   |
| tbl_archive               |
| tbl_archive_favor         |
| tbl_article               |
| tbl_article_cate          |
| tbl_article_comment       |
| tbl_checkin               |
| tbl_config                |
| tbl_group                 |
| tbl_group_fans            |
| tbl_group_topic           |
| tbl_group_topic_comment   |
| tbl_group_topic_type      |
| tbl_group_type            |
| tbl_link                  |
| tbl_member                |
| tbl_member_fans           |
| tbl_member_level          |
| tbl_member_token          |
| tbl_memgroup              |
| tbl_message               |
| tbl_picture               |
| tbl_picture_album         |
| tbl_picture_album_comment |
| tbl_picture_album_favor   |
| tbl_picture_comment       |
| tbl_picture_favor         |
| tbl_picture_tag           |
| tbl_score_detail          |
| tbl_score_rule            |
| tbl_tag                   |
| tbl_validate_code         |
| tbl_weibo                 |
| tbl_weibo_comment         |
| tbl_weibo_favor           |
| tbl_weibo_topic           |
+---------------------------+

 

编写Shell脚本

这个脚本编写好,放在jenkins服务器上

[root@nfs01 scripts]# vim jeesns.sh 
#!/bin/bash
Tomcat_IP=192.168.5.41
Tomcat_Dir=/server/tools/tomcat/webapps
Jeesns_war=/var/lib/jenkins/workspace/jeesns-job/jeesns-web/target/jeesns-web.war
TIME=`date +%F-%H-%M-%S`
ssh root@$Tomcat_IP "cp -a  ${Tomcat_Dir}/ROOT.war /opt/ROOT-${TIME}.war"

ssh root@$Tomcat_IP "rm -rf  ${Tomcat_Dir}/*"
scp -rp $Jeesns_war ${Tomcat_IP}:${Tomcat_Dir}/ROOT.war

 

回到jeekins上操作

在jeesns-job项目里添加构建,具体细节请对照文章Jenkins+Gitlab+Shell脚本 实现手动代码上线

保存后,点立即构建,先用手动的方式,检查是否成功

成功了,非常好,手动部署代码上线,已经完成,现在配置自动上线

自动上线

这里要是看不懂,可以看一下文章Jenkins+Gitlab 实现代码自动化上线

在jenkins上jeesns-job项目中添加触发器

把这个令牌保存下来,去gitlab上进行一一关联

最好进行测试,查看测试结构,验证我就不严重了,可以参考推荐的文章

终于成功了,不容易,不容易,不容易

 

 

继续阅读
weinxin
我的微信
这是我的微信扫一扫
  • 文本由 发表于 2020年3月3日12:24:22
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Jenkins的Pipeline项目 Devops

Jenkins的Pipeline项目

Pipeline项目 CI/CD持续集成/持续部署 持续集成是一种软件开发实践,团队开发成员经常集成它们的工作,通过每个成员每天至少集成一次,也就意味着每天可能发生多次集成。每次集成都通过自动化的构建...
maven工具,搭建私服nexus Devops

maven工具,搭建私服nexus

maven项目管理工具 Maven是一个项目管理的综合工具。Maven提供给开发人员构建一个完整的生命周期框架。 开发团队可以自动完成该项目的基础设施建设,Maven使用标准的目录结构和默认构建生命周...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: