828华为云征文 | 云服务器Flexus X实例,Docker集成搭建斗地主
华为云端口放行
- 服务器放行对应端口8078
Docker安装并配置镜像加速
1、购买华为云 Flexus X 实例
Flexus云服务器X实例-华为云 (huaweicloud.com)
2、docker安装
yum install -y docker-ce
3、验证 Docker 是否安装成功,启动docker服务并设置开机自启动,且查看docker状态
docker --version systemctl enable docker systemctl start docker systemctl status docker
4、docker-ce下载
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
5、路径/etc/yum.repos.d修改配置文件
[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/source/stable enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/source/test enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://repo.huaweicloud.com/docker-ce/linux/centos/9.9/source/nightly enabled=0 gpgcheck=1 gpgkey=https://repo.huaweicloud.com/docker-ce/linux/centos/gpg
6、清除和构建缓存
yum clean all yum makecache
7、docker配置镜像加速(在华为云镜像中心可获取自己的镜像加速配置)
8、创建镜像加速配置文件
vim /etc/docker/daemon.json
{ "registry-mirrors": [ "https://fd0cfec0ac0d446db7fd9d27e92d4a8e.mirror.swr.myhuaweicloud.com" ] }
9、重新加载配置文件,重新启动docker,查看是否配置成功
systemctl daemon-reload systemctl restart docker.service
10、docker info查看配置信息,是否配置成功镜像加速
docker info
搭建斗地主
1、创建工作目录
mkdir -p /data/etcd-data
2、安装git
yum install git -y
3、克隆依赖到本地并将文件解压到工作目录
git clone https://github.com/openinggame/qp.git
4、解压mongodb和mysql到/data
tar zxf mongodb.tar.gz -C /data tar zxf mysqldb.tar.gz -C /data
5、下载镜像到本地
docker pull mysql:8.0.23 docker pull mongo:4.4.4 docker pull quay.io/coreos/etcd:v3.2.32 docker pull wurstmeister/zookeeper docker pull wurstmeister/kafka:2.12-2.3.0 docker pull redis:latest docker pull openinggame/web:v1 docker pull openinggame/server:v1
6、创建集群网络
docker network create -d bridge game
7、修改/data/qp路径下的docker-compose.yml文件
vim docker-compose.yml
version: "3.0" services: web: container_name: web0 image: openinggame/web:v1 ports: - "8078:80" environment: - API_HOST=60.204.147.160 networks: - game depends_on: - server server: container_name: server0 image: openinggame/server:v1 ports: - "81:81" networks: - game depends_on: - etcd - kafka - redis1 - mysql - mongodb mysql: image: mysql:8.0.23 container_name: mysql0 command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci restart: unless-stopped environment: MYSQL_ROOT_PASSWORD: root volumes: - /data/mysql:/var/lib/mysql - mysqlconf:/etc/mysql/conf.d networks: - game redis0: container_name: redis0 image: redis:latest volumes: - redisdata0:/data command: redis-server --requirepass 123456 networks: - game depends_on: - etcd redis1: container_name: redis1 image: redis:latest volumes: - redisdata1:/data command: redis-server --requirepass 123456 networks: - game depends_on: - etcd redis2: container_name: redis2 image: redis:latest volumes: - redisdata2:/data command: redis-server --requirepass 123456 networks: - game depends_on: - mysql - etcd - redis1 zookeeper: container_name: zookeeper image: wurstmeister/zookeeper restart: always networks: - game kafka: container_name: kafka0 image: wurstmeister/kafka:2.12-2.3.0 environment: - KAFKA_BROKER_ID=0 - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka0:9092 - KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 volumes: - /var/run/docker.sock:/var/run/docker.sock restart: always depends_on: - zookeeper networks: - game etcd: image: quay.io/coreos/etcd:v3.2.32 container_name: etcd0 environment: ETCDCTL_API: 3 command: - etcd - --name=etcd0 - --data-dir=/data/etcd-data - --advertise-client-urls=http://etcd0:2379 - --listen-client-urls=http://0.0.0.0:2379 restart: always volumes: - etcd0_data:/etcd-data networks: - game mongodb: container_name: mongodb0 image: mongo:4.4.4 restart: always volumes: - /data/mongo_data:/data/db - mongodb_logs:/data/logs command: --auth networks: - game depends_on: - etcd volumes: mysqlconf: mongodb_logs: etcd0_data: redisdata0: redisdata1: redisdata2: networks: game: external: true
8、启动游戏集群
docker-compose up -d
9、浏览器地址访问公网IP:8078(如果此界面进不去说明有可能被隔离了)
总结
828华为云服务器Flexus X实例,Docker集成搭建斗地主,可以实现金币自由,自主搭建游戏,如果有小伙伴需要搭建,可以购买华为云服务器搭建学习!
华为云828 Flexus X实例