环境变量问题

node/npm 命令报不存在设置方法

首选安装 node 设置软连接 https://www.iyouhun.com/post-125.html

然后在服务器中输出环境变量

echo $PATH
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

在 Jenkins 系统管理,系统配置中,设置全局属性,添加环境变量

npx 命令不可用

nodejs安装包的bin目录下有npx,但是还是报错

我的安装目录是在/root/node-v16.13.0-linux-x64/bin/

给npx添加执行权限(如果没有)

chmod 777 npx

创建软连接到usr/local/bin

sudo ln -s /root/node-v16.13.0-linux-x64/bin/npx /usr/local/bin

检查

npx -v
# 6.14.8

使用 nvm 管理 node 版本

有时候 node 版本需要降低或者升级 可以用此工具

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash

# 如果没装 git 先装 git
sudo yum install git

安装完后,如果是用xshell连远程主机的话,先重连一次,不然会发现提示找不到nvm命令

可能出现依旧提示找不到nvm命令,那么请使用source命令,如下

source ~/.bashrc

# 如果是zsh的话,请用
source ~/.zshrc

使用特定版本

# 先安装才能使用
nvm install 11.13.0

# 使用
nvm use 11.13.0

# 卸载
nvm uninstall 11.13.0

Jenkins 绑定域名

在nginx配置文件做如下配置

# 记得在防火墙打开443端口
upstream jenkins {
  keepalive 32; # keepalive connections
  server 127.0.0.1:8080; # jenkins ip and port
}

# Required for Jenkins websocket agents
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
    listen 443 ssl;
    #配置HTTPS的默认访问端口为443。
    #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
    #如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
    server_name 你的域名; #需要将yourdomain.com替换成证书绑定的域名。
    # root /usr/share/nginx/html;
    # index index.html index.htm;
    ssl_certificate cert/你的证书文件.pem;  #需要将cert-file-name.pem替换成已上传的证书文件的名称。
    ssl_certificate_key cert/你的证书密钥.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #表示使用的加密套件的类型。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
    ssl_prefer_server_ciphers on;

    # pass through headers from Jenkins that Nginx considers invalid
  ignore_invalid_headers off;

  location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
    # rewrite all static files into requests to the root
    # E.g /static/12345678/css/something.css will become /css/something.css
    rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
  }

  location /userContent {
    # have nginx handle all the static requests to userContent folder
    # note : This is the $JENKINS_HOME dir
    root /var/lib/jenkins/;
    if (!-f $request_filename){
      # this file does not exist, might be a directory or a /**view** url
      rewrite (.*) /$1 last;
      break;
    }
    sendfile on;
  }

    # 拦截Jenkins请求
    location /jenkins {
      sendfile off;
      proxy_pass         http://jenkins;
      proxy_redirect     default;
      proxy_http_version 1.1;

      # Required for Jenkins websocket agents
      proxy_set_header   Connection        $connection_upgrade;
      proxy_set_header   Upgrade           $http_upgrade;

      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 $scheme;
      proxy_max_temp_file_size 0;

      #this is the maximum upload size
      client_max_body_size       10m;
      client_body_buffer_size    128k;

      proxy_connect_timeout      90;
      proxy_send_timeout         90;
      proxy_read_timeout         90;
      proxy_buffering            off;
      proxy_request_buffering    off; # Required for HTTP CLI commands
      proxy_set_header Connection ""; # Clear for keepalive
  }
}

然后在 Jenkins 系统配置里设置 Jenkins URL 为你绑定的域名

贴一下我的宝塔Nginx 配置

upstream jenkins {
  keepalive 32; # keepalive connections
  server 127.0.0.1:8080; # jenkins ip and port
}
# Required for Jenkins websocket agents
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}
server
{
    listen 80;
        listen 443 ssl http2;
    server_name jenkins.iyouhun.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/jenkins.iyouhun.com;

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /www/server/panel/vhost/cert/jenkins.iyouhun.com/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/jenkins.iyouhun.com/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;

    #SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-00.conf;
    #PHP-INFO-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/jenkins.iyouhun.com.conf;
    #REWRITE-END

    # pass through headers from Jenkins that Nginx considers invalid
    ignore_invalid_headers off;

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
      # rewrite all static files into requests to the root
      # E.g /static/12345678/css/something.css will become /css/something.css
      rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
    }

    location /userContent {
      # have nginx handle all the static requests to userContent folder
      # note : This is the $JENKINS_HOME dir
      root /var/lib/jenkins/;
      if (!-f $request_filename){
        # this file does not exist, might be a directory or a /**view** url
        rewrite (.*) /$1 last;
        break;
      }
      sendfile on;
    }

      # 拦截Jenkins请求
      location / {
      sendfile off;
      proxy_pass         http://jenkins;
      proxy_redirect     default;
      proxy_http_version 1.1;

      # Required for Jenkins websocket agents
      proxy_set_header   Connection        $connection_upgrade;
      proxy_set_header   Upgrade           $http_upgrade;

      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 $scheme;
      proxy_max_temp_file_size 0;

      #this is the maximum upload size
      client_max_body_size       10m;
      client_body_buffer_size    128k;

      proxy_connect_timeout      90;
      proxy_send_timeout         90;
      proxy_read_timeout         90;
      proxy_buffering            off;
      proxy_request_buffering    off; # Required for HTTP CLI commands
      proxy_set_header Connection ""; # Clear for keepalive
    }
    access_log  /www/wwwlogs/jenkins.iyouhun.com.log;
    error_log  /www/wwwlogs/jenkins.iyouhun.com.error.log;
}

宝塔面板Openssl问题

如果事先安装了宝塔再去安装 Jenkins 然后使用 ssl 时可能会报错

/usr/local/curl/bin/curl: error while loading shared libraries: libssl.so.1.0.0

从网上重新下载一个 Openssl 重新覆盖安装

我的在目录 /usr/local/openssl

然后记得设置软连接

ln -s /usr/local/openssl/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.0
ln -s /usr/local/openssl/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.0

欢迎留言

2 条评论