腾讯云镜主机安全——安装脚本分析

#!/bin/bash
if [ `id -u` -ne 0 ];then 
     echo "Yunjing software must run as root. Please check your account"
     exit 0
fi
system_info=`uname -a`
Is64BitSystem=` echo $system_info | grep -c "x86_64" `
if [ $Is64BitSystem -le 0 ]; then
    echo "Your system is not 64-Bit. That Yunjing is not support yet."
    exit 0
fi

1-11行分析:

1) .首先判断当前用户是不是root用户,获取当前系统信息,并判断是否为64位系统,如果不是则退出安装。


stop_server="service YDService stop"
reload_server=""
regist_server="chkconfig --add YDService"
init_d_path="/etc/rc.d/init.d"
service_script_name="YDService"
rc_local_path="/etc/rc.d/rc.local"


12-19行分析:

2) .对变量赋值。 


if type systemctl >/dev/null 2>&1; then 
  init_d_path="/usr/lib/systemd/system" 
  service_script_name="YDService.service"
  stop_server="systemctl stop YDService.service"
  reload_server="systemctl daemon-reload"
  regist_server="systemctl enable YDService.service"
fi

 20-27行分析:

3) .判断systemctl命令是否存在,如果存在则需要对步骤二变量进行调整


#ubuntu or debian no gawk command
IsUbuntuOrDebian=` echo $system_info | grep -i -c "ubuntu\|debian" ` 
if [ $IsUbuntuOrDebian -gt 0 ]; then
version() { echo "$@" | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; }
init_d_path="/etc/init.d"
rc_local_path="/etc/rc.local"
service_script_name="YDService"
stop_server=""
regist_server="update-rc.d YDService defaults"
  if type systemctl >/dev/null 2>&1; then
    init_d_path="/lib/systemd/system"
    service_script_name="YDService.service"
    stop_server=""
    reload_server=""
    regist_server="systemctl enable YDService.service"
  fi
else
version() { echo "$@" | gawk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'; }
fi

28-46行分析:

4) .判断系统是否为Ubuntu或者Debian系统如果是则修改变量值



IsSuse=` echo $system_info | grep -c "sles" ` 
if [ $IsSuse -gt 0 ]; then
init_d_path="/etc/init.d"
  if type systemctl >/dev/null 2>&1; then
    init_d_path="/etc/systemd/system"
  fi
fi

47-54行分析:

5) .判断是否为suse系统,如果是则修改变量



if type rc-update >/dev/null 2>&1; then 
  init_d_path="/etc/init.d" 
  service_script_name="YDGentooService"
  stop_server=""
  regist_server="rc-update add YDGentooService default"
fi

55-62行分析:

6) .判断rc-update命令是否存在,如果存在则修改启动项添加方式


add_crontab=""
if [ -e '/usr/share/coreos/lsb-release' ]; then
  init_d_path="/etc/systemd/system" 
  service_script_name="YDCoreService.service"
  stop_server=""
  regist_server="systemctl enable YDCoreService.service"
fi


63-71行分析:

7).判断/usr/share/coreos/lsb-release文件是否存在,如果存在修改变量的值


first_version=2.6.32
second_version=`uname -r`
if [ "$(version "$first_version")" -gt "$(version "$second_version")" ]; then
     echo "Your system version is too old. That Yunjing is not support yet."
     exit 0
fi

72-77行分析:

8) .判断内核版本是否为2.6.32以上,如果不是则退出安装。


if [ -w '/usr' ]; then
    myPath="/usr/local/qcloud"
else
    myPath="/var/lib/qcloud"
fi
CURPATH="$( cd "$( dirname $0 )" && pwd )"
echo "checking the md5 file..."
md5_local=`md5sum ${CURPATH}/ydeyesinst_linux64.tar.gz | awk '{print $1}' `
md5_server=`head -1 ${CURPATH}/ydeyesinst_linux64.md5 | awk '{print $1}' `

78-86行分析:

9) .判断/usr路径是否存在,如果存在安装路径的值为/usr/local/qcloud,否则为/var/lib/qcloud。获取当前脚本绝对路径CURPATH。检测安装包MD5值,并获取安装包中记录的MD5进行比较。


if [ "$md5_local"x = "$md5_server"x ]
then
	echo "check package success"

	if [ ! -e "$myPath" ]; then
    mkdir -p "$myPath"
	fi   
	if [ ! -e "$myPath/YunJing" ]; then
    mkdir -p "$myPath/YunJing"
	fi 
	
	tar -zxvf ${CURPATH}/ydeyesinst_linux64.tar.gz -C $myPath/YunJing >/dev/null 2>&1
	#delete crontab
	if ! [ -e '/usr/share/coreos/lsb-release' ]; 
	then
	    chmod 700 $myPath/YunJing/YDDelCrontab.sh
	    $myPath/YunJing/YDDelCrontab.sh
	    add_crontab="$myPath/YunJing/YDAddCrontab.sh"  
	    if [ $? -ne 0 ];then
	        line="$myPath/YunJing/YDCrontab.sh"
	        (crontab -u root -l | grep -v "$line") | crontab -u root -
	    fi
	fi
	

	if [ -f "${CURPATH}/ydeyes.xml" ]
	then 
	cp -rf ${CURPATH}/ydeyes.xml $myPath/YunJing/conf/ydeyes.xml
	fi
	if [ -f "${CURPATH}/security.dat" ]
	then 
	cp -rf ${CURPATH}/security.dat $myPath/YunJing/conf/security.dat
	fi

87-119行分析:

10) .判断安装包MD5值与记录中是否匹配,如果匹配则继续进行,创建$myPath/YunJing安装目录,并把安装包ydeyesinst_linux64.tar.gz解压至$myPath/YunJing路径下。

       判断/usr/share/coreos/lsb-release文件是否存在,如果不存在则修改脚本YDDelCrontab.sh权限为700,并执行该脚本(注:该脚本稍后分析)。如果执行失败直接执行YDCrontab.sh脚本,进行定时任务添加。

       判断ydeyes.xml文件是否存在,如果存在则把安装包中所带的ydeyes.xml文件内容拷贝至$myPath/YunJing/conf/ydeyes.xml文件中

       判断security.dat文件是否存在,如果存在则把安装包中所带的security.dat文件内容拷贝至$myPath/YunJing/conf/security.dat文件中


	chmod 700 $myPath/YunJing/conf
	chmod 700 $myPath/YunJing/YDLive
	chmod 700 $myPath/YunJing/YDEyes
	chmod 600 $myPath/YunJing/conf/ydeyes.xml
	chmod 700 $myPath/YunJing/YDLive/YDLive
	chmod 700 $myPath/YunJing/YDEyes/YDService
	chmod 700 $myPath/YunJing/uninst.sh
	chmod 700 $myPath/YunJing/startYD.sh
	chmod 700 $myPath/YunJing/YDCrontab.sh
	chmod 700 $myPath/YunJing
    chmod 700 $myPath/YunJing/YDEdr
	chmod 700 $myPath/YunJing/YDAddCrontab.sh
	
    if [ -e "$init_d_path" ]
    then
        if [ -f "$init_d_path" ] && [ "$init_d_path" == "/usr/lib/systemd/system" ]
        then
            echo "repair invalid service root: $init_d_path"
            rm -f $init_d_path
        fi
    fi
        
    if [ ! -e "$init_d_path" ]
    then
        echo "create service root $init_d_path"
        mkdir -p $init_d_path
    fi
    
    if [ -d "$init_d_path" ]
    then
        echo "register service to $init_d_path"
        cp  $myPath/YunJing/$service_script_name $init_d_path
    fi

120-153行分析;

11) .修改文件权限为700.把YDCoreService.service服务添加至自启动列表


  if [ "$service_script_name"x = "YDService.service"x ]
  then 
    chmod 644 $init_d_path/$service_script_name
  else
    chmod 744 $init_d_path/$service_script_name
  fi

  if [ "$service_script_name"x = "YDCoreService.service"x ]
  then
    chmod 644 $init_d_path/$service_script_name
  fi  
  
  rm -f $myPath/YunJing/$service_script_name 
  $reload_server
  sleep 2
  $stop_server
	sleep 3
	ProcVer=`pidof YDService`
	if [ $ProcVer ]; then
	$myPath/YunJing/YDEyes/YDService -kill $ProcVer
	fi
	ProcVer=`pidof YDLive`
	if [ $ProcVer ]; then
	$myPath/YunJing/YDEyes/YDService -kill $ProcVer
	fi
	ProcVer=`pidof YDService`
	if [ $ProcVer ]; then
	$myPath/YunJing/YDEyes/YDService -kill $ProcVer
	fi
	ProcVer=`pidof YDEdr`
	if [ $ProcVer ]; then
	$myPath/YunJing/YDEyes/YDService -kill $ProcVer
	fi

154-186行分析:

12) .判断服务名称并赋予相应的权限,并重新加载执行。2秒后关闭然后进行进程查询如果存在则使用kill杀掉。


 if [ "$service_script_name"x = "YDCoreService.service"x ]; then
  systemctl start YDCoreService.service
  else  
	$myPath/YunJing/YDEyes/YDService&
	sleep 1
	$myPath/YunJing/YDLive/YDLive &
  fi

  $regist_server
  $add_crontab
  sed -i '/YunJing\/YDEyes\/YDService/d' $rc_local_path
  sed -i '/YunJing\/YDLive\/YDLive/d' $rc_local_path
  
	
	echo "install package success"
else
	echo "package is invalidate"
fi
rm -f ${CURPATH}/ydeyesinst_linux64.tar.gz
rm -f ${CURPATH}/ydeyesinst_linux64.md5
rm -f ${CURPATH}/yunjinginstall_linux64.sh
rm -f ${CURPATH}/ydeyes.xml
rm -f ${CURPATH}/self_cloud_install_linux64.sh

187-209行分析:

      判断服务执行权限并执行相应服务,注册服务至服务管理列表中,添加服务到定时启动列表

### 如何在腾讯云服务器上安装和运行 TensorBoard #### 安装 TensorFlow 和 TensorBoard 为了能够在腾讯云服务器上使用 TensorBoard,首先需要确保已经安装了 TensorFlow 及其附带的 TensorBoard 工具。可以通过以下命令完成安装: ```bash pip install tensorflow ``` 此命令会自动安装最新版本的 TensorFlow 以及配套的 TensorBoard[^1]。 #### 配置日志目录并启动 TensorBoard TensorBoard 的核心功能之一是从指定的日志目录读取数据,并将其可视化。因此,在运行模型训练之前,需先定义一个保存日志的位置。例如,假设我们将日志存放在 `./logs` 文件夹中,则可以在 Python 脚本中加入如下代码片段以记录训练过程的数据: ```python import tensorflow as tf # 创建 SummaryWriter 对象并将日志写入到 ./logs 中 log_dir = "./logs" writer = tf.summary.create_file_writer(log_dir) with writer.as_default(): for step in range(100): # 假设这是某个指标值 value = (step / 10)**2 tf.summary.scalar('example_metric', data=value, step=step) ``` 当脚本执行完毕后,会在当前工作目录下生成名为 `logs` 的文件夹,其中包含了 TensorBoard 所需的所有数据[^3]。 接着,在终端中切换至项目根目录并通过下面这条指令开启 TensorBoard 服务: ```bash tensorboard --logdir=./logs --host=0.0.0.0 ``` 这里设置了 `--host=0.0.0.0` 参数允许外部 IP 地址访问该服务;默认情况下仅限本地回环地址(即 `localhost` 或者 `127.0.0.1`)。如果忽略这个参数,那么即使完成了后续步骤也无法正常浏览页面[^4]。 #### 使用 SSH 端口转发技术连接远端服务器上的 TensorBoard 实例 由于大多数云计算实例并没有直接暴露给互联网的真实 IPv4 地址,所以单纯依靠上面的方法还不足以让个人电脑上的浏览器能够加载来自腾讯云主机内的网页资源。此时可采用 Secure Shell 协议建立安全隧道来进行通信桥接操作——具体做法如下所示: 1. 打开一个新的命令行窗口; 2. 输入类似于这样的语句来创建一条通往目标机器8080号端口的安全通道: ```bash ssh -N -L 6006:127.0.0.1:6006 username@your_server_ip_address ``` 替换掉这里的占位符部分:将 `username` 改成实际登录名;把 `your_server_ip_address` 设定为目标 VPS 的公网 IP 地址或者域名形式表示法。 一旦建立起上述映射关系之后,就可以像平常一样打开任意一款现代 Web 浏览器程序,并在其地址栏键入 `http://localhost:6006/` 来预览远程站点内容了! 另外值得注意的是,某些特殊场景可能还需要额外考虑防火墙策略设置等问题才能顺利完成整个流程[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值