Files
xiaoxia-saas/scripts/install_python310.sh
T
xiaoxia 8e52bfcc43
Check New Server Env / check (push) Successful in 2s
Downgrade New Runners to v0.2.6 / downgrade (push) Failing after 3s
add: python3.10 install script
2026-07-13 19:09:12 +08:00

85 lines
3.1 KiB
Bash

#!/bin/bash
# 安装Python 3.10.14到CentOS服务器
# 如果本地是Python 3.6就在本地装;否则通过SSH装到新服务器
set -e
NEW_SERVER="172.30.18.199"
SSH_KEY="/root/.ssh/new_server_ed25519"
PY_VER=$(python3 -c 'import sys; print("%d.%d" % sys.version_info[:2])' 2>/dev/null || echo "0.0")
echo "Current Python: $PY_VER"
do_install() {
echo "=== Install build deps ==="
if command -v yum &>/dev/null; then
yum install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make readline-devel sqlite-devel 2>&1 | tail -3
elif command -v apt-get &>/dev/null; then
apt-get update -qq && apt-get install -y build-essential zlib1g-dev libffi-dev libssl-dev wget 2>&1 | tail -3
fi
echo "=== Download Python 3.10.14 ==="
cd /tmp
[ -f Python-3.10.14.tgz ] || wget -q https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz
echo "=== Compile ==="
[ -d Python-3.10.14 ] || tar xzf Python-3.10.14.tgz
cd Python-3.10.14
./configure --prefix=/usr/local/python310 --with-ensurepip=install 2>&1 | tail -3
make -j$(nproc) 2>&1 | tail -10
make install 2>&1 | tail -3
echo "=== Set as default ==="
[ -f /usr/bin/python3 ] && mv /usr/bin/python3 /usr/bin/python3.bak 2>/dev/null || true
[ -f /usr/bin/pip3 ] && mv /usr/bin/pip3 /usr/bin/pip3.bak 2>/dev/null || true
ln -sf /usr/local/python310/bin/python3.10 /usr/bin/python3
ln -sf /usr/local/python310/bin/pip3.10 /usr/bin/pip3
ln -sf /usr/local/python310/bin/python3.10 /usr/local/bin/python3
ln -sf /usr/local/python310/bin/pip3.10 /usr/local/bin/pip3
echo "=== Verify ==="
python3 --version
pip3 --version
pip3 install --help 2>&1 | grep -q "break-system" && echo "break-system-packages: OK" || echo "WARN: no break-system"
}
fix_cmd_agent_port() {
echo "=== Fix CMD Agent port 5000->5927 ==="
[ -f /opt/cmd-agent/server.py ] || { echo "CMD Agent not found"; return 0; }
sed -i 's/port=5000/port=5927/g' /opt/cmd-agent/server.py
sed -i 's/port = 5000/port = 5927/g' /opt/cmd-agent/server.py
systemctl restart cmd-agent
sleep 2
ss -tlnp | grep 5927 && echo "CMD Agent: OK on 5927" || echo "CMD Agent: port check failed"
}
restart_runners() {
echo "=== Restart 6 runners ==="
for i in 1 2 3 4 5 6; do
systemctl restart act-runner-$i && echo "runner-$i restarted"
done
sleep 3
systemctl list-units 'act-runner-*' --no-legend
}
if [ "$PY_VER" = "3.6" ]; then
echo "On new server, installing locally..."
do_install
fix_cmd_agent_port
restart_runners
else
echo "On old server, installing via SSH to $NEW_SERVER..."
mkdir -p /root/.ssh
[ -f "$SSH_KEY" ] || { echo "SSH key not found at $SSH_KEY"; exit 1; }
chmod 600 "$SSH_KEY"
# 测试连接
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@$NEW_SERVER "echo SSH_OK"
# 传脚本并执行
scp -i "$SSH_KEY" -o StrictHostKeyChecking=no "$0" root@$NEW_SERVER:/tmp/install_python310.sh
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no root@$NEW_SERVER "bash /tmp/install_python310.sh"
fi
echo "=== ALL DONE ==="