jenkins安装与配置
Posted 我是一只小小茑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jenkins安装与配置相关的知识,希望对你有一定的参考价值。
jenkins安装与配置
1.软件版本信息
centos7.9 |
jenkins.war |
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 export JAVA_HOME=/usr/local/java export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin #maven env export MAVEN_HOME=/usr/local/maven export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin #nexus env export NEXUS_HOME=/usr/local/nexus export PATH=$PATH:$NEXUS_HOME/bin #node env export NODE_HOME=/usr/local/node export PATH=$PATH:$NODE_HOME/bin [root@localhost opt]# 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环境信息
export JAVA_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: 234 20 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 : tomcat start | stop | restart ;; esac exit 0 |
[root@A bin]# chkconfig tomcat on
3.4)启动tomcat服务:
[root@A bin]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/java/jre Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Using CATALINA_OPTS: Tomcat started. |
[root@A bin]# 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 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 dist html&&tar zcvf html.tar.gz html |
Source files: | html.tar.gz |
Remove prefix: | |
Remote directory: | /home/bjdcs/nginx/assemble/assemble |
Exec command: | /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 mv html `date +%F+%S`_html >/etc/null 2>&1 fi if [ ! -f$file ];then echo "$file not found" exit 2 else tar zxvf $file >/etc/null 2>&1 && rm -rf $file fi docker restart $server >/etc/null 2>&1 |
5.7)创建java项目
clean package |
Source files | target/*.jar |
Remove prefix | target/ |
Remote directory | /home/bjdcs/jar/assemble |
Exec command | docker restart assemble-jar |
jenkins到此就配置完成
以上是关于jenkins安装与配置的主要内容,如果未能解决你的问题,请参考以下文章