前言

Latex是科研论文写作的重要工具,因为排版方式相对word来说更加灵活且严谨,所以在学术圈子里得到广泛应用,博主本人也是经常使用Latex写论文,但是Latex需要在各个主机上安装对应软件和环境,所以部署起来相对复杂,这里采用Overleaf的方法来搭建一个在线的编辑环境,这样在任何平台都可以直接使用,非常方便,而且相比较官方的Overleaf网站没有存储空间的限制,所以有明显的优势,接下来介绍一下如何使用Docker安装Overleaf程序。

安装

1、Docker安装

这部分不再展开,博客之前的文章中已经有详细说明,大家可以去翻阅

2、Sharelatex安装

  • 创建存放程序的文件夹

    mkdir /root/app/Overleaf
    mkdir /root/app/Overleaf/sharelatex/ /root/app/Overleaf/sharelatex_data/ /root/app/Overleaf/mongo_data/ /root/app/Overleaf/redis_data/
  • 拉取sharelatex镜像

    cd /root/app/Overleaf
    docker pull sharelatex/sharelatex
  • 下载docker-compose.yml

    cd /root/app/Overleaf/sharelatex
    
    wget https://raw.githubusercontent.com/sharelatex/sharelatex/master/docker-compose.yml

    获得文件后注意对上述文件的内容进行编辑和修改,主要是对应的外部端口和映射路径

    version: '2.2'
    services:
        sharelatex:
            restart: always
            # Server Pro users:
            # image: quay.io/sharelatex/sharelatex-pro
            image: sharelatex/sharelatex
            container_name: sharelatex
            depends_on:
                mongo:
                    condition: service_healthy
                redis:
                    condition: service_started
            ports:
                - 5080:80
            links:
                - mongo
                - redis
            volumes:
                - /root/docker/Overleaf/sharelatex_data:/var/lib/sharelatex
                ########################################################################
                ####  Server Pro: Uncomment the following line to mount the docker  ####
                ####             socket, required for Sibling Containers to work    ####
                ########################################################################
                # - /var/run/docker.sock:/var/run/docker.sock
            environment:
    
                SHARELATEX_APP_NAME: Overleaf Community Edition
    
                SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
    
                # Same property, unfortunately with different names in
                # different locations
                SHARELATEX_REDIS_HOST: redis
                REDIS_HOST: redis
    
                ENABLED_LINKED_FILE_TYPES: 'url,project_file'
    
                # Enables Thumbnail generation using ImageMagick
                ENABLE_CONVERSIONS: 'true'
    
                # Disables email confirmation requirement
                EMAIL_CONFIRMATION_DISABLED: 'true'
    
                # temporary fix for LuaLaTex compiles
                # see https://github.com/overleaf/overleaf/issues/695
                TEXMFVAR: /var/lib/sharelatex/tmp/texmf-var
    
                ## Set for SSL via nginx-proxy
                #VIRTUAL_HOST: 103.112.212.22
    
                # SHARELATEX_SITE_URL: http://sharelatex.mydomain.com
                # SHARELATEX_NAV_TITLE: Our ShareLaTeX Instance
                # SHARELATEX_HEADER_IMAGE_URL: http://somewhere.com/mylogo.png
                # SHARELATEX_ADMIN_EMAIL: support@it.com
    
                # SHARELATEX_LEFT_FOOTER: '[{"text": "Powered by <a href=\"https://www.sharelatex.com\">ShareLaTeX</a> 2016"},{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
                # SHARELATEX_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'
    
                # SHARELATEX_EMAIL_FROM_ADDRESS: "team@sharelatex.com"
    
                # SHARELATEX_EMAIL_AWS_SES_ACCESS_KEY_ID:
                # SHARELATEX_EMAIL_AWS_SES_SECRET_KEY:
    
                # SHARELATEX_EMAIL_SMTP_HOST: smtp.mydomain.com
                # SHARELATEX_EMAIL_SMTP_PORT: 587
                # SHARELATEX_EMAIL_SMTP_SECURE: false
                # SHARELATEX_EMAIL_SMTP_USER:
                # SHARELATEX_EMAIL_SMTP_PASS:
                # SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH: true
                # SHARELATEX_EMAIL_SMTP_IGNORE_TLS: false
                # SHARELATEX_EMAIL_SMTP_NAME: '127.0.0.1'
                # SHARELATEX_EMAIL_SMTP_LOGGER: true
                # SHARELATEX_CUSTOM_EMAIL_FOOTER: "This system is run by department x"
    
                ################
                ## Server Pro ##
                ################
    
                # SANDBOXED_COMPILES: 'true'
    
                # SANDBOXED_COMPILES_SIBLING_CONTAINERS: 'true'
                # SANDBOXED_COMPILES_HOST_DIR: '/var/sharelatex_data/data/compiles'
                # SYNCTEX_BIN_HOST_PATH: '/var/sharelatex_data/bin/synctex'
    
                # DOCKER_RUNNER: 'false'
    
                ## Works with test LDAP server shown at bottom of docker compose
                # SHARELATEX_LDAP_URL: 'ldap://ldap:389'
                # SHARELATEX_LDAP_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
                # SHARELATEX_LDAP_SEARCH_FILTER: '(uid={{username}})'
                # SHARELATEX_LDAP_BIND_DN: 'cn=admin,dc=planetexpress,dc=com'
                # SHARELATEX_LDAP_BIND_CREDENTIALS: 'GoodNewsEveryone'
                # SHARELATEX_LDAP_EMAIL_ATT: 'mail'
                # SHARELATEX_LDAP_NAME_ATT: 'cn'
                # SHARELATEX_LDAP_LAST_NAME_ATT: 'sn'
                # SHARELATEX_LDAP_UPDATE_USER_DETAILS_ON_LOGIN: 'true'
    
                # SHARELATEX_TEMPLATES_USER_ID: "578773160210479700917ee5"
                # SHARELATEX_NEW_PROJECT_TEMPLATE_LINKS: '[ {"name":"All Templates","url":"/templates/all"}]'
    
    
                # SHARELATEX_PROXY_LEARN: "true"
    
        mongo:
            restart: always
            image: mongo:4.0
            container_name: mongo
            expose:
                - 27017
            volumes:
                - /root/docker/Overleaf/mongo_data:/data/db
            healthcheck:
                test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
                interval: 10s
                timeout: 10s
                retries: 5
    
        redis:
            restart: always
            image: redis:5
            container_name: redis
            expose:
                - 6379
            volumes:
                - /root/docker/Overleaf/redis_data:/data
    
        # ldap:
        #    restart: always
        #    image: rroemhild/test-openldap
        #    container_name: ldap
        #    expose:
        #        - 389
    
        # See https://github.com/jwilder/nginx-proxy for documentation on how to configure the nginx-proxy container,
        # and https://github.com/overleaf/overleaf/wiki/HTTPS-reverse-proxy-using-Nginx for an example of some recommended
        # settings. We recommend using a properly managed nginx instance outside of the Overleaf Server Pro setup,
        # but the example here can be used if you'd prefer to run everything with docker-compose
    
        # nginx-proxy:
        #     image: jwilder/nginx-proxy
        #     container_name: nginx-proxy
        #     ports:
        #       #- "80:80"
        #       - "443:443"
        #     volumes:
        #       - /var/run/docker.sock:/tmp/docker.sock:ro
        #       - /home/sharelatex/tmp:/etc/nginx/certs
    
  • 运行docker镜像

    cd /root/app/Overleaf/sharelatex
    
    docker-compose up -d

    启动镜像之后就可以访问网站

    ip:port/launchpad
    # 例如: 1.1.1.1:1234/launchpad

​ 这样就根据网页的提示设置管理员账号和密码

  • 反向代理设置
    反向代理设置的方法很多,博主这里使用的是NPM的方式进行代理,设置好ssl证书之后就可以采用https的方式进行访问了

    这里要注意Websockets支持需要打开

3、更新获取完整版本

以上安装的overleaf配套的LaTeX不是完整版,所以我把毕设的模板套上去之后发现运行后报错了,然后就了解到得把LaTeX进行更新。

首先进入容器的bash:

docker exec -it sharelatex bash

然后进入texlive的位置:

cd /usr/local/texlive

然后执行以下命令:

# 下载并运行升级脚本
wget http://mirror.ctan.org/systems/texlive/tlnet/update-tlmgr-latest.sh
sh update-tlmgr-latest.sh -- --upgrade

# 更换texlive的下载源
tlmgr option repository https://mirrors.sustech.edu.cn/CTAN/systems/texlive/tlnet/

# 升级tlmgr
tlmgr update --self --all

# 安装完整版texlive(漫长的等待,不要让shell断开)
tlmgr install scheme-full

# 退出sharelatex的命令行界面,并重启sharelatex容器
exit
docker restart sharelatex

这里特别需要注意,SSH连接不能断开,可以采用如下的方式解决:

编辑/etc/ssh/sshd_config,添加配置项:

ClientAliveInterval 600      
ClientAliveCountMax 10

ClientAliveInterval 600 表示每600秒发送一次请求, 从而保持连接。

ClientAliveCountMax 10 表示服务器发出请求后客户端没有响应的次数达到10次,就自动断开连接。

则无响应的SSH客户端将在大约600x10=6000秒后断开连接。

最后修改:2023 年 02 月 06 日
如果觉得我的文章对你有用,请随意赞赏