入职新公司,一家创业型小公司,所有东西都要亲力亲为,忽然发现自己眼高手低了,以前好多事情安排手下兄弟做了,自己其实不熟悉细节,惭愧,例如jenkins,公司一直在用,但我还真没动手去弄过,好在也很简单,随手记录一下。
1.从Oracle官方网站下载jdk最新版安装包jdk-8u121-linux-x64.rpm
2.安装jdk,java安装完毕后目录是:/usr/java/jdk1.8.0_121/bin/java
]# yum
localinstall jdk-8u121-linux-x64.rpm
3.确认默认的java版本
]# java
-version
4.如果系统中安装了多个版本的java,可以使用alternative命令修改
]#
alternatives --config java
输入数字,选择正确的版本即可。
5.将java相关环境变量写入/etc/environment
]# echo
"export JAVA_HOME=/usr/java/jdk1.8.0_121" >>
/etc/environment
]# echo
"export JRE_HOME=/usr/java/jdk1.8.0_121/jre" >>
/etc/environment
]# echo
"export
PATH=$PATH:/usr/java/jdk1.8.0_121/bin:/usr/java/jdk1.8.0_121/jre/bin"
>> /etc/environment
6.安装nginx
]# yum
install nginx
]# vi
/etc/nginx/conf.d/jenkins.conf
upstream
jenkins {
server
127.0.0.1:8080;
}
server
{
listen
80
default;
server_name your_jenkins_site.com;
access_log
/var/log/nginx/jenkins.access.log;
error_log
/var/log/nginx/jenkins.error.log;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
location /
{
proxy_pass
http://jenkins;
proxy_next_upstream error
timeout invalid_header http_500 http_502 http_503
http_504;
proxy_redirect
off;
proxy_set_header
Host
$host;
proxy_set_header
X-Real-IP
$remote_addr;
proxy_set_header
X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header
X-Forwarded-Proto
https;
}
}
]# nginx
-t
]#
systemctl start nginx
]#
systemctl enable nginx
6.安装jenkins
]# wget
-O /etc/yum.repos.d/jenkins.repo
https://pkg.jenkins.io/redhat-stable/jenkins.repo
]# rpm
--import
https://pkg.jenkins.io/redhat-stable/jenkins.io.key
]# yum
install jenkins
]#
service jenkins start
]#
systemctl enable jenkins
7.Jenkins基本配置
打开浏览器,访问http://your_jenkins_site.com,按照提示配置即可,过程中创建一个“admin”用户。
刚安装好的jenkins没有启用认证,所有不安全,我们开启认证:
选择左侧菜单的“系统管理”,点击‘Configure Global
Security‘,勾选‘启用安全’
选在使用“Jenkins专有用户数据库”,首选策略选择“安全矩阵”,“匿名用户”那一行,确认只有View字段的read被勾选,其他为空。
点击“添加用户/组:”,输入amdin,点击“添加”,勾选“admin”用户的Overall字段的“Administer”。
点击页面下部“保存”。
参考文档:
https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/#
https://www.digitalocean.com/community/tutorials/how-to-install-java-on-centos-and-fedora
https://www.rosehosting.com/blog/install-and-configure-jenkins-with-nginx-as-a-reverse-proxy-on-centos-7/
https://wiki.jenkins-ci.org/display/JENKINS/Tomcat
http://fableking.iteye.com/blog/1850824