jenkins二
破解管理员密码
1.假如我们忘记了Jenkins管理员密码了该怎么办呢?Jenkins没有用到数据库,所有的文件都是保存到xml文件里的
2.第一步找到admin所在的目录
[root@centos-03 ~]# cd /var/lib/jenkins/users/admin888/ [root@centos-03 admin888]# ll 总用量 4 -rw-r--r-- 1 jenkins jenkins 2197 6月 25 18:09 config.xml [root@centos-03 admin888]#
3.第二步修改config.xml文件,找到passwordHash所在的行用上图的字符替换,重启Jenkins,新密码就为aminglinux.com
[root@centos-03 admin888]# cat config.xml |grep passwordHash <passwordHash>#jbcrypt:$2a$10$/zhMy8Iy4OSvqIZjK2e7jO7i.WIL2sOLhqNF6sIhS6P7TruwZFVeu</passwordHash> [root@centos-03 admin888]#
4.修改密码在用户-》设置里面修改
部署java项目-创建私有仓库
Jenkins多用于Java项目,可以进行编译打包,项目开发完成之后,我们把代码放到git上,Jenkins把源代码拉过来然后用maven进行编译,编译完成之后打包,再把打的包部署到远程机器上,比如Tomcat里面,tomcat可以自动解压项目包。
1.在http://git.lishiming.net上注册一个账号,新建项目,命名为test-java,选择private,点击保存。
2.创建成功,这个页面不要关闭,新打开个相同的页面
3.点击用户头像下面的seting,然后点击ssh keys
4.将服务器上的公钥放到key里,点击保存
[root@centos-03 ~]# ls .ssh/id_rsa.pub .ssh/id_rsa.pub [root@centos-03 ~]# cat !$ cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYzwzucn1JkSSXBDNAZ9KNAbRFLUGn27xeJ/3H7bkXC8FpdNfesSuoHDHg3+RxLnOa7h5M2fLb/ThvPzpl8BA5PYdzY+adqjYzkaCubU/Yjt5GvZV0lTJN+Xsxf8X4wXQtZKQdgKKf+ejo6O7
fIlwPmypk9nd6RjgKoDe45s4jWHt0HttYCG+2IHLT+gMKcNPvkEPvRqnOlZMFW4e6fsyaBzfP+venLMU+ykuvmH9g3Sjh2dUF1wd3czxYcnxCFWbxxqkuH8VAUZFJ8DpBh3G6Cy/A4/5MzprKY/x3jpMfKbkrXkngcnfuCg9oEhTX9cNdbb3UUS
rc+lQNbj3aOMmL root@sunyujun02 [root@centos-03 ~]#
5.成功
6.现在我们就可以执行第一个页面的命令了,设置一个全局的设置
[root@centos-03 ~]# cd /home/ [root@centos-03 home]# ls jump test zhangsan [root@centos-03 home]# git config --global user.name "root" [root@centos-03 home]# git config --global user.email "278108678@qq.com" [root@centos-03 home]#
7.克隆
[root@centos-03 home]# git clone ssh://git@106.3.32.67:14822/admin888/test-java.git 正克隆到 'test-java'... The authenticity of host '[106.3.32.67]:14822 ([106.3.32.67]:14822)' can't be established. ECDSA key fingerprint is 6a:b3:54:d9:24:d4:eb:67:c5:b5:86:e6:fe:71:1b:ee. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[106.3.32.67]:14822' (ECDSA) to the list of known hosts. warning: 您似乎克隆了一个空版本库。 [root@centos-03 home]#
8.进入test-java目录执行git命令推到master
[root@centos-03 home]# cd test-java/ [root@centos-03 test-java]# touch README.md [root@centos-03 test-java]# git add README.md [root@centos-03 test-java]# git commit -m "add README" [master(根提交) f4be064] add README 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.md [root@centos-03 test-java]# git push -u origin master Counting objects: 3, done. Writing objects: 100% (3/3), 209 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To ssh://git@106.3.32.67:14822/admin888/test-java.git * [new branch] master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master。 [root@centos-03 test-java]#
9.在服务器上编辑下README.md文件然后推到github上
[root@centos-03 test-java]# vim README.md [root@centos-03 test-java]# cat README.md CHANGE [root@centos-03 test-java]# git add README.md [root@centos-03 test-java]# git commit -m "ch readme.md" [master 824beb2] ch readme.md 1 file changed, 1 insertion(+) [root@centos-03 test-java]# git push warning: push.default 未设置,它的默认值将会在 Git 2.0 由 'matching' 修改为 'simple'。若要不再显示本信息并在其默认值改变后维持当前使用习惯, 进行如下设置: git config --global push.default matching 若要不再显示本信息并从现在开始采用新的使用习惯,设置: git config --global push.default simple 参见 'git help config' 并查找 'push.default' 以获取更多信息。 ('simple' 模式由 Git 1.7.11 版本引入。如果您有时要使用老版本的 Git, 为保持兼容,请用 'current' 代替 'simple' 模式) Counting objects: 5, done. Writing objects: 100% (3/3), 240 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To ssh://git@106.3.32.67:14822/admin888/test-java.git f4be064..824beb2 master -> master [root@centos-03 test-java]#
10.推送成功
部署java项目-下载zrlog源码
1.下载zrlog
[root@centos-03 test-java]# cd ../ [root@centos-03 home]# [root@centos-03 home]# wget https://codeload.github.com/94fzb/zrlog/zip/master --2018-06-28 14:56:27-- https://codeload.github.com/94fzb/zrlog/zip/master 正在解析主机 codeload.github.com (codeload.github.com)... 13.229.189.0, 54.251.140.56, 13.250.162.133 正在连接 codeload.github.com (codeload.github.com)|13.229.189.0|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:2401337 (2.3M) [application/zip] 正在保存至: “master” 100%[============================================>] 2,401,337 191KB/s 用时 12s 2018-06-28 14:56:41 (191 KB/s) - 已保存 “master” [2401337/2401337]) [root@centos-03 home]#
2.解压master
[root@centos-03 home]# du -sh master 2.3M master [root@centos-03 home]# unzip master
3.将文件拷贝到test-java目录下
[root@centos-03 test-java]# ls [root@centos-03 test-java]# mv zrlog-master/* test-java/ [root@centos-03 test-java]# cd test-java/ [root@centos-03 test-java]# ls [root@centos-03 test-java]# git add . [root@centos-03 test-java]# git commit -m "add zrlog" [root@centos-03 test-java]# git push
4.完毕总结就是,搞了一个私有仓库,把源码放到我们的仓库里
安装tomcat
1.我们在另外一台机器(02服务器)上安装Tomcat
chattr命令防止系统中某个关键文件被修改
chattr +i /etc/fstab
2.下载tomcat
[root@centos-02 src]# cd /usr/local/src/ [root@centos-02 src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz --2018-06-28 15:53:41-- https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.32/bin/apache-tomcat-8.5.32.tar.gz Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 9584807 (9.1M) [application/octet-stream] Saving to: ‘apache-tomcat-8.5.32.tar.gz’ 100%[============================================>] 9,584,807 1.23MB/s in 7.6s 2018-06-28 15:53:49 (1.20 MB/s) - ‘apache-tomcat-8.5.32.tar.gz’ saved [9584807/9584807] [root@centos-02 src]#
3.解压
[root@centos-02 src]# tar zxvf apache-tomcat-8.5.32.tar.gz
4.移动到/usr/local/tomcat
[root@centos-02 src]# mv apache-tomcat-8.5.32 /usr/local/tomcat [root@centos-02 src]#
5.tomcat有一个管理界面我们需要配置管理员用户,编辑tomcat-users.xml文件添加配置
[root@centos-02 src]# vim /usr/local/tomcat/conf/tomcat-users.xml [root@centos-02 src]#
--> <role rolename="admin"/> # role配置角色 <role rolename="admin-gui"/> <role rolename="admin-script"/> <role rolename="manager"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/>
<user name="admin888" password="admin888" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" /> # user配置用户及用户的角色 </tomcat-users>
6.启动tomcat
[root@centos-02 tomcat]# cd /usr/local/tomcat/bin/ [root@centos-02 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 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. [root@centos-02 bin]# ps aux|grep tomcat root 3815 71.2 5.1 2257384 51068 pts/0 Sl 16:16 0:16 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=o
rg.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UM
ASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomc
at -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start root 3827 6.0 0.0 112664 936 pts/0 R+ 16:16 0:00 grep --color=auto tomcat [root@centos-02 bin]#
7.启动成功,不成功一般是防火墙弄的关掉iptables
8.点击manage webapp,403没有权限
9.编辑context.xml文件,默认允许的ip没有192.168.133网段我们需要补上
[root@centos-02 ~]# cd /usr/local/tomcat/
[root@centos-02 tomcat]# cd webapps/ [root@centos-02 webapps]# vim manager/META-INF/context.xml [root@centos-02 webapps]#
<Context antiResourceLocking="false" privileged="true" > <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.133.*" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.
(?:Linked)?HashMap"/> </Context>
10.重启tomcat,双击666,点击manage webapp弹出登录框
11.账号登录manage后台,其实为了能让用户访问manage就是为了让Jenkins能够访问到这个页面,通过这个页面的api接口发布我们的war包,maven这个插件可以将java源码编译成war包,然后再将这个包通过这个manage接口传送到远程的tomcat,传过来之后tomcat就自动解压发布了
部署java项目-安装maven
1.安装maver是为了编译java的源码并打包,访问http://maven.apache.org/download.cgi找到binary tar.gz包复制链接地址到服务器下载(在Jenkins所在的服务器上安装)。
http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
[root@centos-03 tomcat]# cd /usr/local/ [root@centos-03 local]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
[root@centos-03 local]# tar zxvf apache-maven-3.5.4-bin.tar.gz
2.查看maver版本
[root@centos-03 local]# ls apache-maven-3.5.4 bin boot conf lib LICENSE NOTICE README.txt [root@centos-03 local]# apache-maven-3.5.4/bin/mvn --version Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00) Maven home: /usr/local/apache-maven-3.5.4 Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix" [root@centos-03 local]#
3.不小心在02服务器上下载了包可以将包远程移动到03服务器重新解压
[root@centos-02 local]# scp apache-maven-3.5.4-bin.tar.gz centos-03:/usr/local/
4.配置Jenkins系统管理-》全局工具配置进行配置
部署java项目-安装插件
1.安装maven intergration和deplop to container,点击直接安装
2.重启Jenkins,浏览器访问Jenkins点击新建项目发现多了一个“构建一个maven项目选项”
[root@centos-03 conf]# systemctl restart jenkins [root@centos-03 conf]#
部署java项目-构建job
1.选择构建一个maven项目,填写项目名称test-java,点击确定
2.填写配置信息
3.有报错提示我们这是一个私有仓库需要我们配置用户名和密码,点击add添加用户名和私钥
[root@centos-03 conf]# cat /root/.ssh/id_rsa -----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEA2M8M7nJ9SZEklwQzQGfSjQG0RS1Bp9u8Xif9x+25FwvBaXTX 3rErqBwx4N/kcS5zmu4eTNny2/04bz86ZfAQOT2Hc2Pmnao2M5Ggrm1P2I7eRr2V dJUyTfl7MX/F+MF0LWSkHYCin/no6Oju3yJcD5sqZPZ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lymX91dTsjWtmEkOT+qkGw/iUOGeVcwwhA uc36vbUaWwrv8uzibSuIAqvZm5DaIDuEg3YfdJxDCIFW2yrTPNAScPY/pxNcLpnm asxvVFoU0Kdbkl0zJyfowpcAH7tzy6i8C0HprkzQUnwhjfbVZA5bCZLFZXAXfHUJ 3d4BAoGABifvGGtRUiOhdOeWXbb5kdwD0dbn+33b5XDMwaHrvU8CAxV3qcC2f4yp yGOH84LinfasLO0I6aNQ/XCCZcQ3yy1I/iiwVFmBvJEtVYO5Jfsb5TGm7coMwJe6 9YKUJ/NOBqEkaXzssVoUZhc+Kf37GQvH5VwlfHEaN5xZZ2TpOko= -----END RSA PRIVATE KEY----- [root@centos-03 conf]#
4.点击add之后再选择git
5.继续编辑build,build的配置其实就是maven编译我们的java源码生成包
clean install -D maven.test.skip=true (编译之前先clean,跳过测试)
6.构建后操作配置,添加邮箱保存
7.点击构建
8.看日志有报错
9.可能是openjdk的原因,我们需要下载一个java官网的jdk,然后在系统管理-》全局工具中配置下jdk
部署java项目-手动安装jdk
1.我们直接把之前安装的02服务器上的jdk1.8远程复制到03服务器上(也可以自己从java官网下载安装)
[root@centos-02 local]# ls apache-maven-3.5.4 bin games jdk1.8 lib64 nginx share tomcat apache-maven-3.5.4-bin.tar.gz etc include lib libexec sbin src [root@centos-02 local]# ls jdk1.8 bin include lib README.html THIRDPARTYLICENSEREADME-JAVAFX.txt COPYRIGHT javafx-src.zip LICENSE release THIRDPARTYLICENSEREADME.txt db jre man src.zip [root@centos-02 local]#
[root@centos-03 local]# scp -r 192.168.133.88:/usr/local/jdk1.8 /usr/local/jdk1.8
[root@centos-03 local]# ls apache-maven-3.5.4 bin etc include lib libexec records share apache-maven-3.5.4-bin.tar.gz domob games jdk1.8 lib64 nginx sbin src [root@centos-03 local]# cd jdk1.8/ [root@centos-03 jdk1.8]# ls bin include jre man src.zip COPYRIGHT javafx-src.zip lib README.html THIRDPARTYLICENSEREADME-JAVAFX.txt db jdk1.8 LICENSE release THIRDPARTYLICENSEREADME.txt [root@centos-03 jdk1.8]#
[root@centos-03 jdk1.8]# java -version openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-b10) OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode) [root@centos-03 jdk1.8]#
2.配置jdk系统管理-》全局工具配置,保存
3.重启Jenkins服务
[root@centos-03 jdk1.8]# systemctl restart jenkins
4.浏览器重新构建项目,点击立即构建。
5.成功了
部署java项目-发布war包
1.返回到工程继续点击配置,拉到最下面点击增加构建后操作步骤,选择deploy war to a container
2.配置container,后点击保存
3.再次点击立即构建,构建成功
[root@centos-02 ~]# ls /usr/local/tomcat/webapps/ docs examples host-manager manager ROOT [root@centos-02 ~]# ls /usr/local/tomcat/webapps/ docs examples host-manager manager ROOT zrlog-2.0.0 zrlog-2.0.0.war
4.访问zrblog博客
http://192.168.33.88:8080/zrlog-2.0.0