Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkins 安装配置及与 gitlab 集成 #63

Open
felix-cao opened this issue Sep 4, 2018 · 3 comments
Open

Jenkins 安装配置及与 gitlab 集成 #63

felix-cao opened this issue Sep 4, 2018 · 3 comments

Comments

@felix-cao
Copy link
Owner

felix-cao commented Sep 4, 2018

一、安装

1.1 安装 JDK

  • yum 安装,我在用这种方式安装的时候,选择了 yum install java-1.8.0-openjdk.x86_64, echo $JAVA_HOME 时为空. 导致jenkins安装好后无法配置 JDK
  • sdkman 方式
$ sdk install java 8.282.08.1-amzn

1.2 安装 JENKINS

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum upgrade
sudo yum install jenkins
sudo systemctl daemon-reload

参考官网文档

二、修改配置

这里直接使用 root 系统用户是为了避免繁琐的文件权限问题

2.1修改端口和 jenkins 系统用户

jenkins 配置文件
vim /etc/sysconfig/jenkins

#监听端口
JENKINS_PORT="8081"
#修改配置
$JENKINS_USER="root"

注意, Jenkins 2.33后,这里的配置无效, 请在 /usr/lib/systemd/system/jenkins.service 中更改 UserEnvironment="JENKINS_PORT=8090"

image

2.2 更改文件权限

chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins

重启

service jenkins restart
ps -ef | grep jenkins
systemctl restart jenkins

2.3 解锁Jenkins

访问 http://${ip}:8081,提示解锁Jenkins

vi /var/lib/jenkins/secrets/initialAdminPassword

三、配置 JDK、maven、git

JDK 在 1.1 已经安装了,下面安装 mavengit

$ sdk install maven 3.6.3
$ yum install git

sdk 工具请参考 使用 sdkman 安装并维护多个版本的 JDK
查找命令行工具路径, 然后把这些路径配置到 jenkins 中

which maven
which git

1、安装 git

Manage Jenkins -> Manage plugins -> Available -> 输入 git -> 选择 git plugin(This plugin integrates Git with Jenkins)

2、全局配置

Manage Jenkins -> Global Tool Configuration -> 输入 git 命令行地址

四、gitlab 与 Jenkins 通信

4.1 安装 gitlab 插件

Manage Jenkins -> Manage plugins -> Available -> 输入 gitlab

image

4.2 新建项目, 配置触发器

New Item -> Build Triggers -> Build when a change is pushed to Gitlab...

image

image

4.3 gitlab 配置

image

image

image

image

image

image

image

image

Reference

@felix-cao
Copy link
Owner Author

felix-cao commented Mar 8, 2021

Jenkins 忘记管理员密码

1、修改 config.xml 文件中红色标记代码为 false

vi /var/lib/jenkins/config.xml

image

2、重启 jenkins 服务

systemctl restart jenkins

image

参考

@felix-cao
Copy link
Owner Author

查找 yum 安装的 java 路径

which java
ls -l /usr/lib/java/
ls -l /etc/alternatives/java

最终查找的 java 路径在:

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/bin

@felix-cao felix-cao changed the title Jenkins运行shell脚本权限终极解决办法 Jenkins 安装配置 Mar 9, 2021
@felix-cao felix-cao changed the title Jenkins 安装配置 Jenkins 安装配置及与 gitlab 集成 Mar 9, 2021
@felix-cao
Copy link
Owner Author

felix-cao commented Mar 25, 2022

Jenkins 2.33

最新版本的需要安装 Java 11, Centos7 系统环境下默认是安装了 Java 8, 这里先卸载一下 Java 8.

# 查看
rpm -qa | grep java
rpm -qa | grep jdk
# 批量卸载
rpm -qa | grep jdk | xargs rpm -e --nodeps
rpm -qa | grep java | xargs rpm -e --nodeps

卸载后 java -version 看一看

二、安装

2.1 yum 安装

yum search java-11-openjdk                                  # 可以不用执行,查找安装包
yum install -y java-11-openjdk java-11-openjdk-devel 

2.2 查找安装目录

ls -l $(which java)
# 或  which java

上面的命令如果输出的结果为:/usr/bin/java 则执行下面的命令

ls -lr /usr/bin/java

输出为 /usr/bin/java -> /etc/alternatives/java

ls -lrt /etc/alternatives/java 

输出为 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64/bin/java
上面的 /usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64 就是 JAVA 的安装路径

三、配置环境变量

vi /etc/profile, 在文件的底部加入:

# Java Environment
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/jre/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH

生效, source /etc/profile
测试结果, echo $JAVA_HOME

接下来参考 Jenkins 安装配置及与 gitlab 集成

四、防火墙

禁用/停止自带的firewalld服务

systemctl stop firewalld # 停止firewalld服务
systemctl mask firewalld # 禁用firewalld服务

安装iptable iptable-service

service iptables status # 先检查是否安装了iptables
yum install -y iptables # 安装iptables
yum update iptables  # 升级iptables
#安装iptables-services
yum install iptables-services
iptables -A INPUT -p tcp --dport 8090 -j ACCEPT # 开放8090端口
service iptables save # 保存上述规则

或直接 vi /etc/sysconfig/iptables, 输入 -A INPUT -p tcp --dport 8090 -j ACCEPT 即可
注册iptables服务

systemctl enable iptables.service # 相当于以前的chkconfig iptables on
systemctl start iptables.service # 开启服务
systemctl status iptables.service # 查看状态

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant