因为 centos8不维护了 ,源都失效 ,首先更换阿里的源。
sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
安装 wget 命令:
yum install wget
找到 Anaconda 官网下载地址 选择合适版本 : (https://repo.anaconda.com/archive/)
打不开就想想别的办法。
我选择 最新的 然后下载到本地 如下 :
wget https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh
给执行权限:
Chmod +x ./Anaconda3-2024.02-1-Linux-x86_64.sh
执行:
./Anaconda3-2024.02-1-Linux-x86_64.sh
安装步骤 下一步 回车 遇到 yes or no 果断选择 yes。
安装完成后 刷新:
source .bashrc
创建python 项目目录并给权限,上传文件。
mkdir /www
chmod -R 755 /www
编写 xxx.sh:
#!/bin/bash
. /etc/profile
. ~/.bash_profile
python /www/xxx-py/xxx.py
给.sh 脚本可执行权限。
chmod +x xxx.sh
设置 crontab 定时执行脚本 写入log。
crontab -e
分 日 月 * * /www/xxx-py/xxx.sh >> /www/xxx-py/xxx.log 2>&1
完成等待 执行.
ps:
过程中可能会遇到 没有 xxx module python 的引用包, 就直接 pip install xxx 即可。
编写的 shell 脚本 与遇到 win 和linux 的格式问题,安装 yum install dos2unix。
执行 如下 方式:
dos2unix your_script.sh
sed -i 's/\r//' your_script.sh
另外 可以使用 (date +"%Y-%m-%d %H:%M:%S")方法查看服务器当前时间 辅助编写cron.
--- 希望这篇小记能对你有帮助。