美文网首页
ubuntu安装jenkins

ubuntu安装jenkins

作者: wwmin_ | 来源:发表于2018-04-04 00:28 被阅读138次

    参考 https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Ubuntu#app-switcher

    安装

    wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
    sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    sudo apt-get update
    sudo apt-get install jenkins
    

    升级

    //Once installed like this, you can update to the later version of Jenkins (when it comes out) by running the following commands:
    sudo apt-get update
    sudo apt-get install jenkins
    

    安装包做了如下事情

    • Jenkins will be launched as a daemon up on start. See /etc/init.d/jenkins for more details.
    • The 'jenkins' user is created to run this service.
      Log file will be placed in /var/log/jenkins/jenkins.log. Check this file if you are troubleshooting Jenkins.
    • /etc/default/jenkins will capture configuration parameters for the launch like e.g JENKINS_HOME
    • By default, Jenkins listen on port 8080. Access this port with your browser to start configuration.

    If your /etc/init.d/jenkins file fails to start jenkins, edit the /etc/default/jenkins to replace the line
    HTTP_PORT=8080byHTTP_PORT=8081
    Here, 8081 was chosen but you can put another port available.

    完成之后,打开ip:8081即可看到jenkins

    jenkins
    第一次打开会要求输入密码
    可用cat /var/lib/jenkins/secrets/initialAdminPassword查看并复制密码
    选择安装插件
    一般选择推荐即可。
    开启jenkins之旅吧。

    遇到的问题总结:

    1. 按照windows的配置方式配置好之后,想把代码拉取到自定义的workspace目录下,在windows上正常运行,但是在ubuntu上报错了,

      自定义workspace
      后来分析原因是安装时jenkins用的是自己新建的用户叫jenkinsjenkins没有足够权限,不能创建文件夹导致,后取消自定义工作空间,后正常构建。jenkins默认工作目录/var/lib/jenkins/workspace/
    2. 构建node应用程序时需要用到npm命令npm install,但是会碰到
      npm WARN checkPermissions Missing write access to /var/lib/jenkins/workspace/meeting/node_modules的权限错误问题,这是需要提升权限,顾用sudo npm install,但是此时还会出现# [sudo: no tty present and no askpass program specified”的错误,由于帐号并没有开启免密码导致的 ,解决办法就是切换到root用户并添加jenkins的权限vim /etc/sudoers添加免密码jenkins ALL = NOPASSWD: ALL,也可以将jenkins用户添加可以用sudo执行命令

      jenkins权限及免密
      构建
    3. jenkins权限问题终极解决方案
      在Ubuntu下,当执行apt-get install方式安装Jenkins的时候,会自动创建jenkins用户,这是一个没有用户目录的账号。
      用root运行jenkins


      更换jenkins name

    修改/etc/default/jenkins文件,

    jenkins group name

    将jenkins账号分别加入到root组中
    gpasswd -a root jenkins
    把jenkins用户加入sudo用户组
    adduser jenkins sudo
    设置密码(也可以选择在visudo设置NOPASSWD让用户请求sudo权限时不需要输入密码)
    passwd jenkins
    然后重启服务
    service jenkins restart

    • 将jenkins 8080端口映射到80端口 参考jenkins官网
      在/etc/nginx/sites-available/ 下新建名为jenkins文件,将以下内容拷贝进去
    server {
        # listen 80;
        server_name jenkins.example.com;
        location / {
          proxy_set_header        Host $host:$server_port;
          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 $scheme;
     
          # Fix the "It appears that your reverse proxy set up is broken" error.
          proxy_pass          http://127.0.0.1:8080;
          proxy_read_timeout  90;
     
          proxy_redirect      http://127.0.0.1:8080 https://jenkins.example.com;
      
          # Required for new HTTP-based CLI
          proxy_http_version 1.1;
          proxy_request_buffering off;
          # workaround for https://issues.jenkins-ci.org/browse/JENKINS-45651
          add_header 'X-SSH-Endpoint' 'jenkins.domain.tld:50022' always;
        }
      }
    

    然后输入一下命令,在sites-enabled文件夹下建立jenkins文件的链接

    ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
    

    最后再重启nginx即可

    service nginx restart
    nginx -s reload
    //如果是用supervisor管理的nginx进程可以重新加载
    supervisorctl restart nginx
    

    <未完.>

    相关文章

      网友评论

          本文标题:ubuntu安装jenkins

          本文链接:https://www.haomeiwen.com/subject/fwehhftx.html