说明
win系统的话此教程基本无用,这里只针对基于mac或者其他linux系统(当然win装个xshell模拟终端也行)此处项目官方文档目前已关闭注册.话不多说,开始!
在你的机器上安装docker ce
1.卸载机器上可能存在的docker
sudo apt-get update//更新APT库
sudo apt-get upgrade
sudo apt-get remove docker docker-engine docker.io//卸载机器上可能存在的docker
2.安装
- 由于 apt 源使用 HTTPS 因此,需要添加使用HTTPS 传输的软件包以及 CA 证书。
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
- 把官方源替换为清华源,同时添加软件源的 GPG 密钥和docker软件源
#1.官方源替换为清华源
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
#官方源操作方法
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#2.添加软件源的 GPG 密钥和docker软件源
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
#官方源
#sudo add-apt-repository \
#"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
#$(lsb_release -cs) \
#stable
#3.更新APT
sudo apt-get update
- 安装docker并启动,测试正确性。
sudo apt-get install docker-ce
sudo systemctl enable docker
sudo systemctl start docker
sudo docker run hello-world
#出现以下信息则安装成功
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:445b2fe9afea8b4aa0b2f27fe49dd6ad130dfe7a8fd0832be5de99625dad47cd
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
镜像加速
/etc/docker/daemon.json写入以下内容
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
应用修改并重启
sudo systemctl daemon-reload
sudo systemctl restart docker
至此,docker环境OK。
进行酷q相关配置
不巧的是目前酷q官网已关闭注册(还好我注册的早qaq),同时酷q只支持x86_64平台,要保证自己的
ecs/机器 上的对应端口是开放的。
下载并初始化
docker pull coolq/wine-coolq//下载 酷Q Docker 镜像
mkdir /root/coolq-data # 任意路径均可(存放 酷Q 数据)
运行酷Q镜像
docker run --name=coolq --rm -p `开放的端口号`:9000 -v `刚才创建文件夹的绝对路径`:/home/user/coolq -e VNC_PASSWD=`机器人密码` -e COOLQ_ACCOUNT=`机器人账号` coolq/wine-coolq
访问
1.以上操作进行完当你看到[CQDaemon] Started CoolQ 说明已启动成功
2.浏览器中访问http://你的服务器IP:你的端口即可访问.
服务器端实现酷q进程后台运行
原因:SIGHUP信号导致ssh关闭,正在运行的程序会死掉.
screen命令
流行的Linux发行版通常会自带screen实用程序,没有的话,可以从GNU screen的官方网站下载
1).输入screen后会车进入子界面,
2).执行你的后台代码
3).按ctrl+a再按d切换至后台会显示[detached]的字样此时断开ssh也能后台执行了。
4).停止后台:
screen –ls #显示后台信息
screen –r #切换至对应子界面
# ctrl+d结束子界面
也可以:
#如果有 N 个screen,关闭所有screen
screen -ls|awk 'NR>=2&&NR<=N{print $1}'|awk '{print "screen -S "$1" -X quit"}'|sh
如发生进程一场中断,也可以使用
Supervisor自动唤起。Supervisor推荐教程
服务器和本地机拷贝文件
# 假设服务器IP地址为xxxx
# 1.从服务器复制文件到本地:
scp root@192.168.1.100:/data/test.txt /home/myfile/
# 2.从服务器复制文件夹到本地:
scp -r root@192.168.1.100:/data/ /home/myfile/
# 3.从本地复制文件到服务器:
scp /home/myfile/test.txt root@192.168.1.100:/data/
# 4.从本地复制文件夹到服务器:
scp -r /home/myfile/ root@192.168.1.100:/data/
结束
如果你完成了以上操作,那么你的机器人就可以后台自己跑起来了。