博观而约取,厚积而薄发。这篇文章主要讲述jenkins安装与配置相关的知识,希望能为你提供帮助。
jenkins安装与配置1.软件版本信息
centos7.9 |
jenkins.war |
【jenkins安装与配置】 apache-tomcat-8.5.72.tar.gz |
jdk-8u161-linux-x64.tar.gz |
nexus-3.36.0-01-unix.tar.gz |
node-v14.17.6-linux-x64.tar.gz |
apache-maven-3.8.3-bin.zip |
2.系统环境变量配置(追加)
[root@A opt]# cat /etc/profile
#java env exportJAVA_HOME=/usr/local/java exportCLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar exportPATH=$PATH:$JAVA_HOME/bin #maven env exportMAVEN_HOME=/usr/local/maven exportPATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin #nexus env exportNEXUS_HOME=/usr/local/nexus exportPATH=$PATH:$NEXUS_HOME/bin #node env exportNODE_HOME=/usr/local/node exportPATH=$PATH:$NODE_HOME/bin [root@localhostopt]# source /etc/profile |
2.1)安装配置nrm[root@A ~]#npm install -g nrm
[root@A ~]# nrm add cict ??http://192.168.2.10:4873??
add registry cict success |
[root@A ~]# nrm add cict-main ??http://36.148.1.242:4873/??
add registry cict-main success |
[root@A ~]# nrm use cict-main
[root@A ~]# nrm test
2.2)安装配置pm2 (图库需要使用)[root@A ~]#]#npm install -g pm2
[root@A bin]# pwd /home/nodejs/sky-drive/bjdcs/bin
[root@A bin]# cat www | grep "const port"
const port =normalizePort(process.env.PORT || 10000); |
[root@A bin]#pm2 start www -n bjdcs-10000
[root@A bin]#pm2 startup
[root@A bin]#pm2 save
[root@A bin]# pm2 list
┌─────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│
id │ name │ namespace │ version │ mode │ pid
│ uptime │ ? │
status │ cpu │ mem
│ user │ watching │
├─────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ bjdcs-10000 │ default │ 0.0.0
│ fork │ 1328 │ 23m
│ 0 │ online │ 0%
│ 32.9mb │ root │ disabled │
└─────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
2.3)查看环境变量是否生效
3.修改tomcat配置
3.1)修改/tomcat/conf/server.xml 配置文件的端口信息,防止应用端口冲突
8080,8005,8009修改这个三端口
3.2)修改/tomcat/bin/catalina.sh 配置,增加java环境信息
exportJAVA_HOME=/usr/local/java |
export JRE_HOME=/usr/local/java/jre |
3.3)增加开机启动tomcat
[root@A bin]# cat /etc/init.d/tomcat
#!/bin/bash # description:Tomcat7 Start Stop Restart # processname:tomcat7 # chkconfig: 23420 80 CATALINA_HOME=/usr/local/tomcat case $1 in start) sh$CATALINA_HOME/bin/startup.sh ; ; stop) sh$CATALINA_HOME/bin/shutdown.sh ; ; restart) sh$CATALINA_HOME/bin/shutdown.sh sh$CATALINA_HOME/bin/startup.sh ; ; *) echo please use : tomcatstart | stop | restart ; ; esac exit 0 |
[root@A bin]# chkconfig tomcat on
3.4)启动tomcat服务:
[root@A bin]# /usr/local/tomcat/bin/startup.sh
UsingCATALINA_BASE: /usr/local/tomcat UsingCATALINA_HOME: /usr/local/tomcat UsingCATALINA_TMPDIR: /usr/local/tomcat/temp UsingJRE_HOME: /usr/local/java/jre UsingCLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar UsingCATALINA_OPTS: Tomcat started. |
[root@A bin]# netstat -ntpl
Active Internetconnections (only servers) Proto Recv-QSend-Q Local Address ForeignAddress State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 883/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1115/master tcp6 0 0 :::10000 :::* LISTEN 1328/node /home/nod tcp6 0 0 :::22 :::* LISTEN 883/sshd tcp6 0 0 :::1080 :::* LISTEN 912/java tcp6 0 0 ::1:25 :::* LISTEN 1115/master tcp6 0 0 127.0.0.1:1005 :::* LISTEN 912/java |
4.修改maven配置
/usr/local/maven/conf/settings.xml(增加nexus仓库的地址和账户和password,然后进去nexus仓库检查是否正常)
< server> < id> nexus< /id> < username> admin< /username> < password> passw0rd< /password> < /server> < server> < id> maven-releases< /id> < username> admin< /username> < password> passw0rd< /password> < /server> < server> < id> maven-snapshots< /id> < username> admin< /username> < password> passw0rd< /password> < /server> < server> < id> 3rdParty< /id> < username> admin< /username> < password> passw0rd< /password> < /server> < /servers> < mirror> < id> nexus< /id> < mirrorOf> *,!jeecg,!jeecg-snapshots< /mirrorOf> < url> http://192.168.2.202:8081/repository/maven-public/< /url> < /mirror> < profile> < id> nexus< /id> < repositories> < repository> < id> nexus< /id> < name> *< /name> < url> http://192.168.2.202:8081/repository/maven-public/< /url> < releases> < enabled> true< /enabled> < /releases> < snapshots> < enabled> true< /enabled> < /snapshots> < /repository> < /repositories> < pluginRepositories> < pluginRepository> < id> nexus< /id> < name> *< /name> < url> http://192.168.2.202:8081/repository/maven-public/< /url> < releases> < enabled> true< /enabled> < /releases> < snapshots> < enabled> true< /enabled> < /snapshots> < /pluginRepository> < /pluginRepositories> < /profile> |
5.首次使用jenkins配置
5.1)系统管理--插件管理--可选插件:
Publish Over SSH,GitLab,Gitlab Hook,NodeJS,Maven
Integration(或者Pipeline Maven Integration)
5.2)系统管理--全局工具配置
5.3)配置gitlab
系统管理--系统配置
5.4)打开gitlab网站:设置API-=token
5.5)配置Publish
over SSH
[root@A .ssh]# ssh-keygen(jenkins机器上)
[root@A .ssh]# ssh-copy-id 192.168.2.202(192.168.2.202是WEB设备)
系统管理--系统配置
5.6)创建web任务
执行Shell: | rm -rf html* npm install & & npm run build mv disthtml& & tar zcvf html.tar.gz html |
Source files: | html.tar.gz |
Removeprefix: | |
Remotedirectory: | /home/bjdcs/nginx/assemble/assemble |
Execcommand: | /home/bjdcs/nginx/assemble/assemble/onstart.sh |
脚本放在web机器 |
[root@localhost~]# cat /home/bjdcs/nginx/assemble/assemble/onstart.sh |
#!/bin/bash dir=/home/bjdcs/nginx/assemble/assemble file=html.tar.gz server=nginx-assemble-web if [ ! -d$dir ]; then echo"$dir not found" exit 1 else cd$dir mvhtml `date +%F+%S`_html > /etc/null 2> & 1 fi if [ !-f$file ]; then echo"$file not found" exit2 else tarzxvf $file > /etc/null 2> & 1 & & rm -rf $file fi docker restart$server > /etc/null 2> & 1 |
5.7)创建java项目
clean package |
Sourcefiles | target/*.jar |
Removeprefix | target/ |
Remotedirectory | /home/bjdcs/jar/assemble |
Execcommand | docker restartassemble-jar |
jenkins到此就配置完成
推荐阅读
- LINUX下载编译ldns
- TCP长连接实践与挑战
- 搏动"城市之肾",可视化突破海绵城市发展困境
- 搭建npm的私有verdaccio 仓库
- shell脚本中ssh命令远程调用java启动脚本无法启动java进程
- 运维面试问道 网站出现502 如何排查
- linux 搭建ELFK6.8.0集群
- MySQL8中的函数索引
- 个人日常行为准则2022.01.28