更新 0g.sh

This commit is contained in:
smeb_y 2024-07-17 13:52:51 +00:00
parent 51b5d230b2
commit 4023f63f3e

208
0g.sh
View File

@ -39,10 +39,10 @@ function install_pm2() {
function check_go_installation() { function check_go_installation() {
if command -v go > /dev/null 2>&1; then if command -v go > /dev/null 2>&1; then
echo "Go 环境已安装" echo "Go 环境已安装"
return 0 return 0
else else
echo "Go 环境未安装,正在安装..." echo "Go 环境未安装,正在安装..."
return 1 return 1
fi fi
} }
@ -59,7 +59,7 @@ function install_node() {
# 更新和安装必要的软件 # 更新和安装必要的软件
sudo apt update && sudo apt upgrade -y sudo apt update && sudo apt upgrade -y
sudo apt install curl git wget htop tmux build-essential jq make lz4 gcc unzip liblz4-tool -y sudo apt install git wget build-essential jq make lz4 gcc liblz4-tool -y
# 安装 Go # 安装 Go
if ! check_go_installation; then if ! check_go_installation; then
@ -79,51 +79,52 @@ function install_node() {
export MONIKER="My_Node" export MONIKER="My_Node"
export WALLET_NAME="wallet" export WALLET_NAME="wallet"
# 获取初始文件和地址簿 # 初始化节点
cd $HOME cd $HOME
0gchaind init $MONIKER --chain-id zgtendermint_16600-2 0gchaind init $MONIKER --chain-id zgtendermint_16600-2
0gchaind config chain-id zgtendermint_16600-2 0gchaind config chain-id zgtendermint_16600-2
0gchaind config node tcp://localhost:13457 0gchaind config node tcp://localhost:13457
# 配置节点 # 配置创世文件
rm ~/.0gchain/config/genesis.json rm ~/.0gchain/config/genesis.json
wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json
0gchaind validate-genesis 0gchaind validate-genesis
# 配置节点 # 配置节点
SEEDS="" SEEDS="8f21742ea5487da6e0697ba7d7b36961d3599567@og-testnet-seed.itrocket.net:47656"
PEERS="4d98cf3cb2a61238a0b1557596cdc4b306472cb9@95.216.228.91:13456,c44baa3836d07f9ed9a832f819bcf19fda67cc5d@95.216.42.217:13456,81987895a11f6689ada254c6b57932ab7ed909b6@54.241.167.190:26656,010fb4de28667725a4fef26cdc7f9452cc34b16d@54.176.175.48:26656,e9b4bc203197b62cc7e6a80a64742e752f4210d5@54.193.250.204:26656,68b9145889e7576b652ca68d985826abd46ad660@18.166.164.232:26656" PEERS="4d98cf3cb2a61238a0b1557596cdc4b306472cb9@95.216.228.91:13456,c44baa3836d07f9ed9a832f819bcf19fda67cc5d@95.216.42.217:13456,81987895a11f6689ada254c6b57932ab7ed909b6@54.241.167.190:26656,010fb4de28667725a4fef26cdc7f9452cc34b16d@54.176.175.48:26656,e9b4bc203197b62cc7e6a80a64742e752f4210d5@54.193.250.204:26656,68b9145889e7576b652ca68d985826abd46ad660@18.166.164.232:26656"
sed -i "s/persistent_peers = \"\"/persistent_peers = \"$PEERS\"/" $HOME/.0gchain/config/config.toml sed -i "s/persistent_peers = \"\"/persistent_peers = \"$PEERS\"/" $HOME/.0gchain/config/config.toml
sed -i "s/seeds = \"\"/seeds = \"$SEEDS\"/" $HOME/.0gchain/config/config.toml sed -i "s/seeds = \"\"/seeds = \"$SEEDS\"/" $HOME/.0gchain/config/config.toml
sed -i -e 's/max_num_inbound_peers = 40/max_num_inbound_peers = 100/' -e 's/max_num_outbound_peers = 10/max_num_outbound_peers = 100/' $HOME/.0gchain/config/config.toml
wget -O $HOME/.0gchain/config/addrbook.json https://testnet-files.itrocket.net/og/addrbook.json
# 配置裁剪 # 配置裁剪
sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pex *=.*/pex = \"true\"/" $HOME/.0gchain/config/config.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"0\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"0\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" $HOME/.0gchain/config/app.toml sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" $HOME/.0gchain/config/app.toml
sed -i -e 's/max_num_inbound_peers = 40/max_num_inbound_peers = 100/' -e 's/max_num_outbound_peers = 10/max_num_outbound_peers = 100/' $HOME/.0gchain/config/config.toml
# 配置端口 # 配置端口
sed -i -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:13458\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:13457\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:13460\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:13456\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":13466\"%" $HOME/.0gchain/config/config.toml sed -i -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:13458\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:13457\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:13460\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:13456\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":13466\"%" $HOME/.0gchain/config/config.toml
sed -i -e "s%^address = \"tcp://localhost:1317\"%address = \"tcp://0.0.0.0:13417\"%; s%^address = \":8080\"%address = \":13480\"%; s%^address = \"0.0.0.0:9090\"%address = \"0.0.0.0:13490\"%; s%^address = \"localhost:9091\"%address = \"0.0.0.0:13491\"%; s%:8545%:13445%; s%:8546%:13446%; s%:6065%:13465%" $HOME/.0gchain/config/app.toml sed -i -e "s%^address = \"tcp://localhost:1317\"%address = \"tcp://0.0.0.0:13417\"%; s%^address = \":8080\"%address = \":13480\"%; s%^address = \"0.0.0.0:9090\"%address = \"0.0.0.0:13490\"%; s%^address = \"localhost:9091\"%address = \"0.0.0.0:13491\"%; s%:8545%:13445%; s%:8546%:13446%; s%:6065%:13465%" $HOME/.0gchain/config/app.toml
source $HOME/.bash_profile source $HOME/.bash_profile
# 使用 PM2 启动节点进程 # 使用 PM2 启动节点进程
pm2 start 0gchaind -- start && pm2 save && pm2 startup pm2 start 0gchaind -- start && pm2 save && pm2 startup
pm2 restart 0gchaind pm2 restart 0gchaind
echo '====================== 安装完成,请退出脚本后执行 source $HOME/.bash_profile 以加载环境变量===========================' echo '====================== 安装完成,请退出脚本后执行 source $HOME/.bash_profile 以加载环境变量==========================='
} }
# 查看0gai 服务状态 # 查看 PM2 服务状态
function check_service_status() { function check_service_status() {
pm2 list pm2 list
} }
# 0gai 节点日志查询 # 验证节点日志查询
function view_logs() { function view_logs() {
pm2 logs 0gchaind pm2 logs 0gchaind
} }
@ -134,7 +135,7 @@ function uninstall_node() {
read -r -p "请确认: " response read -r -p "请确认: " response
case "$response" in case "$response" in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
echo "开始卸载节点程序..." echo "开始卸载节点程序..."
pm2 stop 0gchaind && pm2 delete 0gchaind pm2 stop 0gchaind && pm2 delete 0gchaind
rm -rf $HOME/.0gchain $HOME/0gchain $(which 0gchaind) && rm -rf 0g-chain rm -rf $HOME/.0gchain $HOME/0gchain $(which 0gchaind) && rm -rf 0g-chain
@ -160,6 +161,7 @@ function import_wallet() {
# 查询余额 # 查询余额
function check_balances() { function check_balances() {
echo "请确认同步到最新区块之后再查询余额"
read -p "请输入钱包地址: " wallet_address read -p "请输入钱包地址: " wallet_address
0gchaind query bank balances "$wallet_address" 0gchaind query bank balances "$wallet_address"
} }
@ -200,41 +202,46 @@ function install_storage_node() {
sudo apt-get install clang cmake build-essential git screen cargo -y sudo apt-get install clang cmake build-essential git screen cargo -y
# 安装Go # 安装 Go
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
curl -L https://go.dev/dl/go1.22.0.linux-amd64.tar.gz | sudo tar -xzf - -C /usr/local curl -L https://go.dev/dl/go1.22.0.linux-amd64.tar.gz | sudo tar -xzf - -C /usr/local
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
source $HOME/.bash_profile source $HOME/.bash_profile
# 克隆仓库
git clone -b v0.3.3 https://github.com/0glabs/0g-storage-node.git
#进入对应目录构建 # 克隆仓库
git clone -b v0.3.4 https://github.com/0glabs/0g-storage-node.git
# 进入对应目录构建
cd 0g-storage-node cd 0g-storage-node
git submodule update --init git submodule update --init
# 构建代码 # 构建代码
echo "准备构建,该步骤消耗一段时间。请保持 SSH 不要断开。看到 Finish 字样为构建完成。"
cargo build --release cargo build --release
#后台运行 # 编辑配置
cd run
read -p "请输入你想导入的EVM钱包私钥不要有0x: " miner_key
read -p "请输入设备 IP 地址(本地机器请直接回车跳过): " public_address
read -p "请输入使用的 JSON-RPC : " json_rpc
sed -i '
s|# network_enr_address = ""|network_enr_address = "'$public_address'"|
s|# rpc_listen_address = ".*"|rpc_listen_address = "0.0.0.0:5678"|
s|# network_boot_nodes = \[\]|network_boot_nodes = \[\"/ip4/54.219.26.22/udp/1234/p2p/16Uiu2HAmTVDGNhkHD98zDnJxQWu3i1FL1aFYeh9wiQTNu4pDCgps\",\"/ip4/52.52.127.117/udp/1234/p2p/16Uiu2HAkzRjxK2gorngB1Xq84qDrT4hSVznYDHj6BkbaE4SGx9oS\",\"/ip4/18.167.69.68/udp/1234/p2p/16Uiu2HAm2k6ua2mGgvZ8rTMV8GhpW71aVzkQWy7D37TTDuLCpgmX\"\]|
s|# log_contract_address = ""|log_contract_address = "0x8873cc79c5b3b5666535C825205C9a128B1D75F1"|
s|# mine_contract_address = ""|mine_contract_address = "0x85F6722319538A805ED5733c5F4882d96F1C7384"|
s|# blockchain_rpc_endpoint = ".*"|blockchain_rpc_endpoint = "'$json_rpc'"|
s|# log_sync_start_block_number = 0|log_sync_start_block_number = 802|
s|# miner_key = ""|miner_key = "'$miner_key'"|
' $HOME/0g-storage-node/run/config.toml
# 启动
screen -dmS zgs_node_session $HOME/0g-storage-node/target/release/zgs_node --config $HOME/0g-storage-node/run/config.toml
read -p "请输入你想导入的EVM钱包私钥不要有0x: " minerkey echo '====================== 安装完成,使用 screen -ls 命令查询即可 ==========================='
read -p "请输入设备IP地址: " new_address
sed -i "s/miner_key = \"\"/miner_key = \"$minerkey\"/" config.toml
sed -i "s/log_contract_address = \"\"/log_contract_address = \"0x8873cc79c5b3b5666535C825205C9a128B1D75F1\"/" config.toml
sed -i "s/mine_contract_address = \"\"/mine_contract_address = \"0x85F6722319538A805ED5733c5F4882d96F1C7384\"/" config.toml
sed -i "s|^# *network_enr_address = \".*\"|network_enr_address = \"$new_address\"|" config.toml
sed -i 's/log_sync_start_block_number = [0-9]*/log_sync_start_block_number = 180000/' config.toml
screen -dmS zgs_node_session ../target/release/zgs_node --config config.toml
echo '====================== 安装完成使用screen命令查询即可 ==========================='
} }
@ -290,48 +297,77 @@ read -p "请输入钱包名称: " wallet_name
} }
# 查看存储节点同步状态 # 查看存储节点日志
function check_storage_status() { function check_storage_status() {
tail -f "$(find ~/0g-storage-node/run/log/ -type f -printf '%T+ %p\n' | sort -r | head -n 1 | cut -d' ' -f2-)" tail -f "$(find ~/0g-storage-node/run/log/ -type f -printf '%T+ %p\n' | sort -r | head -n 1 | cut -d' ' -f2-)"
} }
# 查看存储节点同步状态 # 重启存储节点
function start_storage() { function restart_storage() {
cd 0g-storage-node/run && screen -dmS zgs_node_session ../target/release/zgs_node --config config.toml # 退出现有进程
echo '====================== 启动成功请通过screen -r zgs_node_session 查询 ===========================' screen -S zgs_node_session -X quit
# 启动
screen -dmS zgs_node_session $HOME/0g-storage-node/target/release/zgs_node --config $HOME/0g-storage-node/run/config.toml
echo '====================== 启动成功请通过screen -r zgs_node_session 查询 ==========================='
} }
# 转换ETH地址 # 修改日志等级
function change_storage_log_level() {
echo "DEBUG(1) > INFO(2) > WARN(3) > ERROR(4)"
echo "DEBUG 等级日志文件最大ERROR 等级日志文件最小"
read -p "请选择日志等级(1-4): " level
case "$level" in
1)
echo "debug,hyper=info,h2=info" > $HOME/0g-storage-node/run/log_config ;;
2)
echo "info,hyper=info,h2=info" > $HOME/0g-storage-node/run/log_config ;;
3)
echo "warn,hyper=info,h2=info" > $HOME/0g-storage-node/run/log_config ;;
4)
echo "error,hyper=info,h2=info" > $HOME/0g-storage-node/run/log_config ;;
esac
echo "修改完成,请重新启动存储节点"
}
# 统计日志文件大小
function storage_logs_disk_usage(){
du -sh ~/0g-storage-node/run/log/
du -sh ~/0g-storage-node/run/log/*
}
# 删除存储节点日志
function delete_storage_logs(){
echo "确定删除存储节点日志?[Y/N]"
read -r -p "请确认: " response
case "$response" in
[yY][eE][sS]|[yY])
rm -r ~/0g-storage-node/run/log/*
echo "删除完成,请重启存储节点"
;;
*)
echo "取消操作"
;;
esac
}
# 转换 ETH 地址
function transfer_EIP() { function transfer_EIP() {
read -p "请输入你的钱包名称: " wallet_name read -p "请输入你的钱包名称: " wallet_name
echo "0x$(0gchaind debug addr $(0gchaind keys show $wallet_name -a) | grep hex | awk '{print $3}')" echo "0x$(0gchaind debug addr $(0gchaind keys show $wallet_name -a) | grep hex | awk '{print $3}')"
} }
# 卸载节点功能
function uninstall_old_node() {
echo "你确定要卸载0g ai 节点程序吗?这将会删除所有相关的数据。[Y/N]"
read -r -p "请确认: " response
case "$response" in
[yY][eE][sS]|[yY])
echo "开始卸载节点程序..."
pm2 stop 0gchaind && pm2 delete 0gchaind
rm -rf $HOME/.0gchain $HOME/0gchain $(which 0gchaind) && rm -rf 0gchaind
echo "节点程序卸载完成。"
;;
*)
echo "取消卸载操作。"
;;
esac
}
# 导出验证者key # 导出验证者key
function export_priv_validator_key() { function export_priv_validator_key() {
echo "====================请将下方所有内容备份到自己的记事本或者excel表格中记录===========================================" echo "====================请将下方所有内容备份到自己的记事本或者excel表格中记录==========================================="
cat ~/.0gchain/config/priv_validator_key.json cat ~/.0gchain/config/priv_validator_key.json
} }
function uninstall_storage_node() { function uninstall_storage_node() {
@ -339,7 +375,7 @@ function uninstall_storage_node() {
read -r -p "请确认: " response read -r -p "请确认: " response
case "$response" in case "$response" in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
echo "开始卸载节点程序..." echo "开始卸载节点程序..."
rm -rf $HOME/0g-storage-node rm -rf $HOME/0g-storage-node
echo "节点程序卸载完成。" echo "节点程序卸载完成。"
@ -351,10 +387,21 @@ function uninstall_storage_node() {
} }
function update_script() { function update_script() {
SCRIPT_PATH="./0g.sh" # 定义脚本路径
SCRIPT_URL="https://raw.githubusercontent.com/a3165458/0g.ai/main/0g.sh" SCRIPT_URL="https://raw.githubusercontent.com/a3165458/0g.ai/main/0g.sh"
curl -o $SCRIPT_PATH $SCRIPT_URL
chmod +x $SCRIPT_PATH # 备份原始脚本
echo "脚本已更新。请退出脚本后执行bash 0g.sh 重新运行此脚本。" cp $SCRIPT_PATH "${SCRIPT_PATH}.bak"
# 下载新脚本并检查是否成功
if curl -o $SCRIPT_PATH $SCRIPT_URL; then
chmod +x $SCRIPT_PATH
echo "脚本已更新。请退出脚本后执行bash 0g.sh 重新运行此脚本。"
else
echo "更新失败。正在恢复原始脚本。"
mv "${SCRIPT_PATH}.bak" $SCRIPT_PATH
fi
} }
# 主菜单 # 主菜单
@ -375,22 +422,23 @@ function main_menu() {
echo "5. 查看节点同步状态" echo "5. 查看节点同步状态"
echo "6. 查看当前服务状态" echo "6. 查看当前服务状态"
echo "7. 运行日志查询" echo "7. 运行日志查询"
echo "9. 创建验证者" echo "8. 卸载0gchain验证者节点"
echo "9. 创建验证者"
echo "10. 给自己验证者地址质押代币" echo "10. 给自己验证者地址质押代币"
echo "11. 转换ETH地址" echo "11. 转换ETH地址"
echo "=======================存储节点功能================================" echo "=======================存储节点功能================================"
echo "12. 创建存储节点" echo "12. 创建存储节点"
echo "13. 查看存储节点日志" echo "13. 查看存储节点日志"
echo "14. 单独启动存储节点代码,适用于需要修改存储路径等功能修改过后使用" echo "14. 重启存储节点"
echo "17. 卸载存储节点(卸载前请先停止对应的存储节点进程)" echo "15. 卸载存储节点"
echo "=======================卸载evmos测试网节点功能================================" echo "18. 修改日志等级"
echo "8. 卸载0gchain验证者节点" echo "19. 统计日志文件大小"
echo "15. 卸载旧evmos验证者节点" echo "20. 删除存储节点日志"
echo "=======================备份功能================================" echo "=======================备份功能================================"
echo "16. 备份验证者私钥" echo "16. 备份验证者私钥"
echo "=======================================================" echo "======================================================="
echo "18. 更新本脚本" echo "17. 更新本脚本"
read -p "请输入选项1-18: " OPTION read -p "请输入选项1-20: " OPTION
case $OPTION in case $OPTION in
1) install_node ;; 1) install_node ;;
@ -406,18 +454,20 @@ function main_menu() {
11) transfer_EIP ;; 11) transfer_EIP ;;
12) install_storage_node ;; 12) install_storage_node ;;
13) check_storage_status ;; 13) check_storage_status ;;
14) start_storage ;; 14) restart_storage ;;
15) uninstall_old_node ;; 15) uninstall_storage_node ;;
16) export_priv_validator_key ;; 16) export_priv_validator_key ;;
17) uninstall_storage_node ;; 17) update_script ;;
18) update_script ;; 18) change_storage_log_level ;;
19) storage_logs_disk_usage ;;
20) delete_storage_logs ;;
*) echo "无效选项。" ;; *) echo "无效选项。" ;;
esac esac
echo "按任意键返回主菜单..." echo "按任意键返回主菜单..."
read -n 1 read -n 1
done done
} }
# 显示主菜单 # 显示主菜单
main_menu main_menu