• centos7中同时使用多版本nodejs的配置


    系统里面已经按照了node14版本,新的项目需要node10,担心不同的nodejs存在兼容性问题,故在系统中安装不同的nodejs版本

    1.采用二进制安装的方法

    nodejs二进制下载地址:https://nodejs.org/dist/

    cd /usr/local
    wget https://nodejs.org/dist/v10.22.1/node-v10.22.1-linux-x64.tar.gz
    tar xf node-v10.22.1-linux-x64.tar.gz
    mv node-v10.22.1-linux-x64 node-v10.22.1

    # 生成nodejs10版本的特定命令
    ln -s /usr/local/node-v10.22.1/bin/node /usr/bin/node10
    ln -s /usr/local/node-v10.22.1/bin/npm /usr/bin/npm10
    [root@jenkins_server:/usr/local/node-v10.22.1/bin]# npm10 --version
    6.14.6
    [root@jenkins_server:/usr/local/node-v10.22.1/bin]# node10 --version
    v10.22.1

    # 安装cnpm
    npm10 install -g cnpm --registry=https://registry.npm.taobao.org


    2.在jenkins的web部分配置的shell

    #!/bin/bash

    # 此脚本功能为根据构建时选择的参数,同步 /data/www/vhosts/h5.chinasoft.io 下的文件同步到远程中转机器
    # 2020.1027 初始化脚本

    #非apache用户运行脚本,则退出
    if [ `whoami` != "apache" ];then
    echo "only apache can run me"
    exit 1
    fi

    echo "xxx"
    ## 1.定义变量
    dir_name=bak.$(date +%Y-%m-%d-%H-%M-%S)
    project_dir=/data/www/vhosts/h5.chinasoft.io


    ## 2.备份代码函数
    function func_project_backup(){
    cp -a $project_dir/ /data/data_backup/h5.chinasoft.io_$dir_name
    }
    func_project_backup

    ## 3.判断代码发布目录变量是否为空
    if [ ! $project_dir ];then
       echo "$project_dir IS NULL ,shell exit!!!!"
       exit 1
    fi

    ## 2.判断同步状态
    function func_rsync_status(){
    if [[ $? == 0 || $? == 23 ]];then
            rsync_edit=1
    else
            rsync_edit=0
            echo "`date` 同步到本地目标失败! "
            exit 1
    fi
    }

    ## 4.同步到本地待发路径
    function func_rsync_project_local(){
        echo "=========================== start building h5.chinasoft.io ================================="
        cd $WORKSPACE/
        echo $GIT_BRANCH
        /usr/bin/node10 -v
        /usr/bin/npm10 -v
        cnpm install
        /usr/bin/npm10 run build

        echo "#########从临时目录同步本机到待发目录 $project_dir #########"
        /usr/local/bin/rsync -zvau -progress $WORKSPACE/dist/ $project_dir/httpdocs/
        func_rsync_status

    }
    func_rsync_project_local

    ## 5.推送代码到远程中转机并发布(发布到线上)

    echo "------------------------------------ rsync start prod -----------------------------------------"
    chown -R apache.users $project_dir/
    sleep 1

    /bin/bash /usr/local/worksh/jeninks_task/chinasoft_io_h5.chinasoft.io.sh

    echo "------------------------------------ rsync done prod -----------------------------------------"

    ## 7.通过插件执行远程中转机上的同步脚本


    3.jenkins中推送任务

    [root@jenkins_server:~]# cat /usr/local/worksh/jeninks_task/chinasoft_io_h5.chinasoft.io.sh
    #!/bin/bash
    #############################################
    ## 设置变量和GET请求过来的变量
    ## GET请求传过来的文件所在目录,目录路径写全路径了
    #dir=$1
    passfile="/data/www/.rsync/pass.chinasoft_io_h5.chinasoft.io"

    # 非apache用户运行脚本,则退出
    if [ `whoami` != "apache" ];then
    echo " only apache can run me"
    exit 1
    fi

    # 判断同步状态
    function func_rsync_status(){
    if [[ $? == 0 || $? == 23 ]];then
            rsync_edit=1
    else
            rsync_edit=0
            echo "`date` 同步到目标失败! "
            exit 1
    fi
    }

    # 判断目录是否为空函数
    function func_is_empty_dir(){
        return `ls -A $1|wc -w`
    }

    # 代码发目录
    project_dir="/data/www/vhosts/h5.chinasoft.io/"

    # 判断待发目录是否为空,为空则退出
    if func_is_empty_dir $project_dir
    then
        echo " $project_dir is empty , exit!!!!"
        exit 1
    else
        echo " $project_dir 可以发布"    
    fi

    ## 设置变量,目标服务器
    server_ip_list="1.1.1.1"

    # src directory
    src_directory="h5.chinasoft.io"

    # dst directory
    dst_directory="h5.chinasoft.io"

    exclude_list="--exclude=.svn --exclude=.git --exclude=.gitignore --exclude=*.log --exclude=.gitattributes --exclude=.env --exclude=vendor"


    function h5.chinasoft.io_rsync()
    {

    # rsync ip_list
    for ip in ${server_ip_list}
    do
            echo "####################rsync ${ip} start################################"
            rsync -zavP --bwlimit=1000 ${exclude_list} --password-file=${passfile} /data/www/vhosts/${src_directory}/ apache@${ip}::apache_h5.chinasoft.io
            func_rsync_status
            echo "################### rsync ${ip} end #######################"
    done
    }

    h5.chinasoft.io_rsync

    yum不同版本的安装参考:https://github.com/nodesource/distributions

  • 相关阅读:
    《剑指offer》JavaScript版(4-6题)
    HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)
    POJ 1436 Horizontally Visible Segments
    FOJ 2105 Digits Count
    HDU 4890 One to Four(2014 Multi-University Training Contest 3)
    HDU 4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
    HDU 4893 Wow! Such Sequence!(2014 Multi-University Training Contest 3)
    POJ 3225 Help with Intervals
    HDU 1698 Just a Hook
    POJ 2886 Who Gets the Most Candies?
  • 原文地址:https://www.cnblogs.com/reblue520/p/13890995.html
Copyright © 2020-2023  润新知