centos7 搭建CTFD基础环境

安装docker docker-compose

docker docker-compose

安装CTFd

安装CTFd的方式比较多,选择的dokcer-compose方式来安装

下载ctfd

git clone https://github.com/CTFd/CTFd.git
cd CTFd
ll
#其中CTFd文件为网页的主要文件
-rw-r--r--.  1 root root  91112 Dec 30 10:35 CHANGELOG.md
drwxr-xr-x.  3 root root     19 Dec 30 10:35 conf
-rw-r--r--.  1 root root   1277 Dec 30 10:35 CONTRIBUTING.md
drwxr-xr-x. 16 root root   4096 Dec 30 10:35 CTFd
-rw-r--r--.  1 root root    450 Dec 30 10:35 development.txt
-rw-r--r--.  1 root root   1459 Dec 30 14:44 docker-compose.yml
-rwxr-xr-x.  1 root root   1010 Dec 30 10:35 docker-entrypoint.sh
-rw-r--r--.  1 root root    938 Dec 30 10:35 Dockerfile
-rw-r--r--.  1 root root    770 Dec 30 10:35 export.py
-rw-r--r--.  1 root root    303 Dec 30 10:35 import.py
-rw-r--r--.  1 root root  11314 Dec 30 10:35 LICENSE
-rw-r--r--.  1 root root    841 Dec 30 10:35 Makefile
-rw-r--r--.  1 root root   1853 Dec 30 10:35 manage.py
drwxr-xr-x.  3 root root    107 Dec 30 10:35 migrations
-rw-r--r--.  1 root root   2629 Dec 30 10:35 package.json
-rw-r--r--.  1 root root    818 Dec 30 10:35 ping.py
-rw-r--r--.  1 root root  10991 Dec 30 10:35 populate.py
-rwxr-xr-x.  1 root root    166 Dec 30 10:35 prepare.sh
-rw-r--r--.  1 root root   4352 Dec 30 10:35 README.md
-rw-r--r--.  1 root root    569 Dec 30 10:35 requirements.in
-rw-r--r--.  1 root root   3371 Dec 30 10:35 requirements.txt
drwxr-xr-x.  2 root root     53 Dec 30 10:35 scripts
-rw-r--r--.  1 root root    209 Dec 30 10:35 SECURITY.md
-rw-r--r--.  1 root root   1353 Dec 30 10:35 serve.py
-rw-r--r--.  1 root root     65 Dec 30 10:35 setup.cfg
drwxr-xr-x. 11 root root   4096 Dec 30 10:35 tests
-rw-r--r--.  1 root root   2516 Dec 30 10:35 Vagrantfile
-rw-r--r--.  1 root root   9954 Dec 30 10:35 webpack.config.js
-rw-r--r--.  1 root root    315 Dec 30 10:35 wsgi.py
-rw-r--r--.  1 root root 278548 Dec 30 10:35 yarn.lock

修改docker-compose.yml

vim docker-composet.yml
version: '2'

services:
  ctfd:
    build: .
    user: root
    restart: always
    ports:
      - "8000:8000"
    environment:
      #这个地方的.ctfd_secret_key参考官方的用head -c 64 /dev/urandom > .ctfd_secret_key来生成
      #https://docs.ctfd.io/docs/deployment/installation
      - SECRET_KEY=/root/CTFd/.ctfd_secret_key  
      - UPLOAD_FOLDER=/var/uploads
      - DATABASE_URL=mysql+pymysql://ctfd:ctfd@db/ctfd
      - REDIS_URL=redis://cache:6379
      - WORKERS=4
      - LOG_FOLDER=/var/log/CTFd
      - ACCESS_LOG=-
      - ERROR_LOG=-
      - REVERSE_PROXY=true
    volumes:
#     - .data/CTFd/logs:/var/log/CTFd  #这个地方直接注释掉
#     - .data/CTFd/uploads:/var/uploads #这个地方直接注释掉
      - .data/CTFd:/root/CTFd/CTFd   #这个地方新添加,将挂载CTFd到本地的CTFd文件,方便文件修改
      - .:/opt/CTFd:ro
    depends_on:
      - db
    networks:
        default:
        internal:

  nginx:
    image: nginx:1.17
    restart: always
    volumes:
      - ./conf/nginx/http.conf:/etc/nginx/nginx.conf
    ports:
      - 80:80
    depends_on:
      - ctfd

  db:
    image: mariadb:10.4.12
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=ctfd
      - MYSQL_USER=ctfd
      - MYSQL_PASSWORD=ctfd
      - MYSQL_DATABASE=ctfd
    volumes:
      - .data/mysql:/var/lib/mysql
    networks:
        internal:
    # This command is required to set important mariadb defaults
    command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --wait_timeout=28800, --log-warnings=0]

  cache:
    image: redis:4
    restart: always
    volumes:
    - .data/redis:/data
    networks:
        internal:

networks:
    default:
    internal:
        internal: true

修改CSS中的文件

由于github中的ctfd默认的引用的css目录为CTFd/CTFd/themes/core/static/css/fonts.min.css
其中有
@import url(https://use.fontawesome.com/releases/v5.9.0/css/all.css);
@import url(https://fonts.googleapis.com/css?family=Lato:400,400i,700,700i|Raleway:400,400i,700,700i&subset=latin-ext);
这两个加载特别慢,导致访问ctfd网页特别慢,在这里先把这两个引用处理掉,

第一个可以直接替换成

@import url(https://cdn.bootcss.com/font-awesome/5.13.0/css/all.css)

第二个可以先下载下来直接访问https://fonts.googleapis.com/css?family=Lato:400,400i,700,700i|Raleway:400,400i,700,700i&subset=latin-ext

然后css目录下新建一个css文件直接,并将下载下来的代码粘贴到文件中(我自己取的名字是:fonts.googleapis.com.css.Lato.css),最后直接引用
@import "fonts.googleapis.com.css.Lato.css";

下载下来的文件还有很多字体也是有问题的比如:以https://fonts.gstatic.com/******开头的很多字体也比较慢,直接下载到CTFd/CTFd/themes/core/static/fonts/目录中

#进入到fonts目录中运行如下指令:
wget https://fonts.gstatic.com/s/lato/v20/S6u8w4BMUTPHjxsAUi-qJCY.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6u8w4BMUTPHjxsAXC-q.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6u_w4BMUTPHjxsI5wq_FQft1dw.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6u_w4BMUTPHjxsI5wq_Gwft.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6uyw4BMUTPHjxAwXjeu.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6uyw4BMUTPHjx4wXg.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6u9w4BMUTPHh6UVSwaPGR_p.woff2
wget https://fonts.gstatic.com/s/lato/v20/S6u9w4BMUTPHh6UVSwiPGQ.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4WjMDr4fIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4WjMDrcfIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4WjMDrwfIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4WjMDr0fIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4WjMDrMfIA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4Y_LDr4fIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4Y_LDrcfIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4Y_LDrwfIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4Y_LDr0fIA9c.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Pt_g8zYS_SKggPNyCgSQamb1W0lwk4S4Y_LDrMfIA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCFPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCMPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCHPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCGPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVvaorCIPrE.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVs9pbCFPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVs9pbCMPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVs9pbCHPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVs9pbCGPrEHJA.woff2
wget https://fonts.gstatic.com/s/raleway/v22/1Ptxg8zYS_SKggPN4iEgvnHyvveLxVs9pbCIPrE.woff2

全部下载之后 ,修改fonts.googleapis.com.css.Lato.css中的内容,
将所有的:src: url(https://fonts.gstatic.com/***/1PT***woff2) format('woff2');
修改为: src: url(../fonts/S6u8w4BMUTPHjxsAXC-q.woff2) format('woff2');
保存后CSS文件就Over了

运行docker-compose

进入到CTFd/目录下运行
docker-compose up -d
访问{host}:80就可以到主页面,然后自己再配置相关内容
整个过程安装运行起来比较方便 ,但是速度的优化会花费一些时间

你可能感兴趣的:(centos7 搭建CTFD基础环境)