
如何关闭宝塔防火墙
为了防止宝塔防火墙拉黑CDN节点,需要关闭宝塔的防火墙。方法如下:1. 关闭Nginx免费防火墙软件商店-》找到Nginx免费防火墙,点击设置弹出设置页面,点击关闭防火墙,如图:

2. 关闭Nginx付费防火墙如果购买有Nginx付费的防火墙,在左侧菜单点击防火墙,切换到全局设置,点击防火墙开关关闭,如图:

如何搬迁主控
注意:下面的迁移步骤不包括迁移elasticsearch的数据1 备份旧主控数据在旧主控执行如下命令开始备份
cd /root
curl http://us.centos.bz/cdnfly/backup_master.sh -o backup_master.sh
chmod +x backup_master.sh
./backup_master.sh
这时候将在目录/root下,打包生成cdn.sql.gz文件,请把这个文件传输到新主控的/root/目录下,可以使用scp命令,命令如下:
cd /root
scp cdn.sql.gz root@新主控IP:/root/
2 在新机器安装好主控程序首先登录cdnfly.cn,更新授权为新主控ip,并清空机器码登录旧主控机器,执行如下命令查看版本:
grep VERSION_NAME /opt/cdnfly/master/conf/config.py
如下图,版本为v4.1.6:

登录新机器,执行如下命令安装:
curl http://dl.cdnfly.cn/cdnfly/master.sh -o master.sh
chmod +x master.sh
./master.sh --ver v4.1.60
其中v4.1.60替换成自己的主控版本号3 登录新主控,恢复备份和config. py,初始化es1)执行如下命令恢复数据库
cd /root
curl http://us.centos.bz/cdnfly/restore_master.sh -o restore_master.sh
chmod +x restore_master.sh
./restore_master.sh
2)执行命令恢复config.py文件:
scp root@旧主控IP:/opt/cdnfly/master/conf/config.py /opt/cdnfly/master/conf/config.py
3)执行如下命令初始化es:
cd /tmp
wget us.centos.bz/cdnfly/int_es.sh -O int_es.sh
chmod +x int_es.sh
./int_es.sh /home/es
supervisorctl -c /opt/cdnfly/master/conf/supervisord.conf restart all
其中/var/lib/elasticsearch为es的数据目录,可以更改成其它的,比如/home/es
4 替换节点里的主控IP登录新主控后台,切换到“系统管理”-》“维护操作”,在节点配置的主控IP栏 ,输入新主控IP,点击创建设置任务按照,如图:

点击查看任务,等任务全部完成后,执行第2步操作。
5 迁移完成1). 登录旧主控服务器,关闭旧主控,执行:
systemctl stop mysql || systemctl stop mariadb
supervisorctl -c /opt/cdnfly/master/conf/supervisord.conf stop all
sed -i '/cdnfly/d' /etc/rc.local || true
sed -i '/cdnfly/d' /etc/rc.d/rc.local || true
2). 登录新主控后台,在首页点击检查agent,如果没有错误,表示主控迁移完成。
如何获取授权
如何授权到期,或者在授权前安装程序,可以登录主控,执行如下命令获取授权:
# 获取授权
source /opt/venv/bin/activate
cd /opt/cdnfly/master/view
ret=`python -c "import util;print util.get_auth_code()" || true`
[[ $ret == "(True, None)" ]] && echo "已获取到授权" || echo "未授权,原因:"$ret
deactivate
如何取消管理端域名绑定
在主控上执行如下命令
mysql -uroot -p@cdnflypass cdn -e "update config set value='' where name='admin_domain';"
mysql -uroot -p@cdnflypass cdn -e "update config set value='' where name='user_domain';"
如何重置主控密码
执行如下命令,重置密码为cdnfly,用户名不变
mysql -uroot -p@cdnflypass cdn -e 'update user set password="$2b$12$UV5ttpNQizMfO.tiBk9ereZ53hDBW0.kak3qa/GRP6aVBfNMB1NsK" where id=1'
如何初始化elasticsearch
当elasticsearch出现无法解决的异常,或者elasticsearch数据占满了硬盘,可以执行此操作来初始化elasticsearch,注意:初始化elasticsearch会清空其所有的数据。执行如下命令初始化:
cd /tmp
wget http://us.centos.bz/cdnfly/int_es.sh -O int_es.sh
chmod +x int_es.sh
./int_es.sh /home/es
其中/home/es为es的数据目录,也可以更改成其它的。
如何更换主控IP
如果只是更换主控IP,不迁移主控,执行如下操作。1)首先登录官网修改授权的主控 IP2)在主控后台,找到“系统管理”-》“维护操作”,在“节点配置的主控IP”输入新主控IP,点击“创建设置任务”,之后点击“查看任务”查看设置进度,如图:

手动更换:
new_master_ip="这里替换为主控IP"
es_pwd="这里替换为es密码"
sed -i "s/ES_IP =.*/ES_IP = \"$new_master_ip\"/" /opt/cdnfly/agent/conf/config.py
sed -i "s/MASTER_IP.*/MASTER_IP = \"$new_master_ip\"/g" /opt/cdnfly/agent/conf/config.py
sed -i "s/hosts:.*/hosts: [\"$new_master_ip:9200\"]/" /opt/cdnfly/agent/conf/filebeat.yml
chattr -i /usr/local/openresty/nginx/conf/ /usr/local/openresty/nginx/conf/listen_80.conf /usr/local/openresty/nginx/conf/listen_other.conf
sed -i "s#http://.*:88#http://$new_master_ip:88#" /usr/local/openresty/nginx/conf/listen_80.conf /usr/local/openresty/nginx/conf/listen_other.conf
chattr +i /usr/local/openresty/nginx/conf/ /usr/local/openresty/nginx/conf/listen_80.conf /usr/local/openresty/nginx/conf/listen_other.conf
sed -i "s/ES_PWD =.*/ES_PWD = \"$es_pwd\"/" /opt/cdnfly/agent/conf/config.py
sed -i "s/password:.*/password: \"$es_pwd\"/" /opt/cdnfly/agent/conf/filebeat.yml
sed -i "s/agent-pwd:.*/agent-pwd: \"$es_pwd\"/" /opt/cdnfly/agent/conf/filebeat.yml
ps aux | grep [/]usr/local/openresty/nginx/sbin/nginx | awk '{print $2}' | xargs kill -HUP || true
supervisorctl -c /opt/cdnfly/agent/conf/supervisord.conf restart filebeat
supervisorctl -c /opt/cdnfly/agent/conf/supervisord.conf restart agent
supervisorctl -c /opt/cdnfly/agent/conf/supervisord.conf restart task
注:es密码在主控的/opt/cdnfly/master/conf/config.py里的LOG_PWD
安装代理软件
当主控无法直接与节点连接时,可以通过代理来连接,这里介绍安装代理软件的方法,目前只支持centos系统,安装命令如下
cd /tmp
wget http://us.centos.bz/cdnfly/install_proxy.sh
chmod +x install_proxy.sh
./install_proxy.sh
安装完成后,会显示代理的端口,用户名和密码。
手动备份数据库
cd /root
curl http://us.centos.bz/cdnfly/backup_master.sh -o backup_master.sh
chmod +x backup_master.sh
./backup_master.sh
手动恢复数据库
假设数据库备份文件在/root/cdn.sql.gz,执行如下命令恢复
eval `grep "MYSQL_PASS" /opt/cdnfly/master/conf/config.py`
mysql -uroot -p$MYSQL_PASS "drop database cdn;create database cdn;"
gunzip < /root/cdn.sql.gz | mysql -uroot -p$MYSQL_PASS cdn
清空绑定的域名
eval `grep "MYSQL_PASS" /opt/cdnfly/master/conf/config.py`
mysql -uroot -p$MYSQL_PASS cdn -e "update config set value='' where name='bind-master-host';"
cd /opt/cdnfly/master/conf
sed -i 's/ALLOW_HOSTS.*/ALLOW_HOSTS=""/' config.py
supervisorctl restart all
重新注册节点
当安装节点完成时,没有在cdn后台的待初始化列表发现此节点时,可以执行如下命令来重新注册。
cd /tmp/ && curl -m 5 http://dl.cdnfly.cn/cdnfly/add-node.sh -o add-node.sh || curl -m 5 http://dl2.cdnfly.cn/cdnfly/add-node.sh &&