准备工作
本期讲解开源的Sharelatex (本地版overleaf)的部署流程,以及遇到的一些坑!
创建工作目录
cd /home
mkdir sharelatex
cd sharelatex
mkdir sharelatex_data
mkdir mongo_data
mkdir redis_data创建并修改docker-compose.yml
在目录/home/sharelatex 中,下载github上最新版的docker-compose.yml,并进行修改
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:
- 5000:80 #修改成自己准备在服务器上开放的端口,如5000:80,不要和其他应用端口冲突
stop_grace_period: 60s
volumes:
- ~/sharelatex_data:/var/lib/overleaf
########################################################################
#### 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:
OVERLEAF_APP_NAME: Overleaf Community Edition
OVERLEAF_MONGO_URL: mongodb://mongo/sharelatex
# Same property, unfortunately with different names in
# different locations
OVERLEAF_REDIS_HOST: redis
REDIS_HOST: redis
ENABLED_LINKED_FILE_TYPES: "project_file,project_output_file"
# Enables Thumbnail generation using ImageMagick
ENABLE_CONVERSIONS: "true"
# Disables email confirmation requirement
EMAIL_CONFIRMATION_DISABLED: "true"
## Set for SSL via nginx-proxy
# VIRTUAL_HOST: 103.112.212.22
# OVERLEAF_SITE_URL: http://overleaf.example.com
# OVERLEAF_NAV_TITLE: Overleaf Community Edition
# OVERLEAF_HEADER_IMAGE_URL: http://example.com/mylogo.png
# OVERLEAF_ADMIN_EMAIL: [email protected]
# OVERLEAF_LEFT_FOOTER: '[{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
# OVERLEAF_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'
# OVERLEAF_EMAIL_FROM_ADDRESS: ""
# OVERLEAF_EMAIL_AWS_SES_ACCESS_KEY_ID:
# OVERLEAF_EMAIL_AWS_SES_SECRET_KEY:
# OVERLEAF_EMAIL_SMTP_HOST: ""
# OVERLEAF_EMAIL_SMTP_PORT: 587
# OVERLEAF_EMAIL_SMTP_SECURE: "false"
# OVERLEAF_EMAIL_SMTP_USER: ""
# OVERLEAF_EMAIL_SMTP_PASS: ""
# OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH: "false"
# OVERLEAF_EMAIL_SMTP_IGNORE_TLS: "false"
# OVERLEAF_EMAIL_SMTP_NAME: '127.0.0.1'
# OVERLEAF_EMAIL_SMTP_LOGGER: true
# OVERLEAF_CUSTOM_EMAIL_FOOTER: "This system is run by department x"
# ENABLE_CRON_RESOURCE_DELETION: true
################
## Server Pro ##
################
# 注意非Pro,不要开启任何Pro相关的功能
## The Community Edition is intended for use in environments where all users are trusted and is not appropriate for
## scenarios where isolation of users is required. Sandboxed Compiles are not available in the Community Edition,
## so the following environment variables must be commented out to avoid compile issues.
##
## Sandboxed Compiles: https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/server-pro-only-configuration/sandboxed-compiles
# SANDBOXED_COMPILES: "false"
### Bind-mount source for /var/lib/overleaf/data/compiles inside the container.
# SANDBOXED_COMPILES_HOST_DIR_COMPILES: "/home/user/sharelatex_data/data/compiles"
### Bind-mount source for /var/lib/overleaf/data/output inside the container.
# SANDBOXED_COMPILES_HOST_DIR_OUTPUT: "/home/user/sharelatex_data/data/output"
### Backwards compatibility (before Server Pro 5.5)
# DOCKER_RUNNER: "true"
# SANDBOXED_COMPILES_SIBLING_CONTAINERS: "true"
## Works with test LDAP server shown at bottom of docker compose
# OVERLEAF_LDAP_URL: 'ldap://ldap:389'
# OVERLEAF_LDAP_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
# OVERLEAF_LDAP_SEARCH_FILTER: '(uid={{username}})'
# OVERLEAF_LDAP_BIND_DN: 'cn=admin,dc=planetexpress,dc=com'
# OVERLEAF_LDAP_BIND_CREDENTIALS: 'GoodNewsEveryone'
# OVERLEAF_LDAP_EMAIL_ATT: 'mail'
# OVERLEAF_LDAP_NAME_ATT: 'cn'
# OVERLEAF_LDAP_LAST_NAME_ATT: 'sn'
# OVERLEAF_LDAP_UPDATE_USER_DETAILS_ON_LOGIN: 'true'
# OVERLEAF_TEMPLATES_USER_ID: "578773160210479700917ee5"
# OVERLEAF_NEW_PROJECT_TEMPLATE_LINKS: '[ {"name":"All Templates","url":"/templates/all"}]'
# OVERLEAF_PROXY_LEARN: "true"
mongo:
restart: always
image: docker.1ms.run/mongo:8.0 # 最新版不肯用可降低版本
container_name: mongo
command: "--replSet overleaf"
volumes:
- ~/mongo_data:/data/db
- ./bin/shared/mongodb-init-replica-set.js:/docker-entrypoint-initdb.d/mongodb-init-replica-set.js
environment:
MONGO_INITDB_DATABASE: sharelatex
extra_hosts:
# Required when using the automatic database setup for initializing the replica set.
# This override is not needed when running the setup after starting up mongo.
- mongo:127.0.0.1
healthcheck:
test: echo 'db.stats().ok' | mongosh localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
redis:
restart: always
image: docker.1ms.run/redis:6.2 # 最新版不肯用可降低版本
container_name: redis
volumes:
- ~/redis_data:/data
# ldap:
# restart: always
# image: rroemhild/test-openldap
# container_name: ldap
# 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/overleaf/tmp:/etc/nginx/certs
可选:
增加挂载texlive包文件夹如下,可以把texlive完整包挂载到容器外,为update后不从新下载包文件准备!
volumes:
- ~/sharelatex_data:/var/lib/sharelatex
- ~/sharelatex_texlive://usr/local/texlive
- /var/run/docker.sock:/var/run/docker.sock
# - /var/clsi/compiles:/var/www/sharelatex/clsi/compiles所在的工作目录/home/sharelatex/中运行如下命令
sudo docker-compose up -d检查是否安装完成
docker ps发现容器已经启动
其他docker命令
docker-compose down # 删除容器并清除容器内的数据和设置
docker-compose stop # 停止已经处于运行状态的容器,但不删除它
docker-compose start # 启动已经存在的服务容器对容器内的tlmgr进行更新
docker exec -it sharelatex bin/bash
tlmgr update --self --all
tlmgr install scheme-full全部的tex live包有超过4000个,需要安装很长时间,耐心等待,如发现停止安装,再次执行tlmgr install scheme-full继续安装,直到全部安装完成。
解决中文字体问题
把Windows系统中的字体放入sharelate容器中
把Windows系统中C:\Windows\Fonts的字体压缩成Fonts.zip文件,把Font.zip传入容器中
进入容器的/usr/share/fonts/目录中创建windows文件夹
docker exec -it sharelatex bin/bash
cd /usr/share/fonts/
mkdir windows退出容器到服务器字体压缩文件所在的工作目录中进行copy文件命令操作
cd /home/sharelatex
docker cp Fonts.zip sharelatex:/usr/share/fonts/windows/进入sharelatex容器中的/usr/share/fonts/windows/目录,进行解压缩并把所有字体移动到/usr/share/fonts/windows/目录下,然后可以删除压缩包和Fonts空文件夹
docker exec -it sharelatex bin/bash
cd /usr/share/fonts/windows/
unzip Fonts.zip
cd Fonts
mv * ../
cd ..
rm Fonts.zip
rmdir Fonts更新字体,并查看
fc-cache
fc-list服务器访问
http://ip:5000 ,该地址会显示正常的Shareleaf登陆页 (记得开启访问端口)
容器备份
docker commit sharelatex sharelatex/sharelatex:texlive-full这样备份后,可以得到新备份的容器比原来多tex live包和字体
以后需要修改docker-compose.yml文件中 image: sharelatex sharelatex/sharelatex:texlive-full(改成commit后的目标镜像名)后再docker-compose up。
账户设置
sudo docker exec sharelatex /bin/bash -c "cd /var/www/sharelatex; grunt user:create-admin --email [email protected]"注:"[email protected]"为自己想要设置成管理员的邮箱
设置管理员密码:
上面管理员账户命令执行后,会跳出url地址,把地址复制到浏览器上,前面改成服务器ip即可设置管理员密码
在管理用户界面设置用户
一些其他命令
登录overleaf:
在sharelatex容器在运行状态下,打开客户端浏览器输入http://ip:5000
输入用户名密码登录
在服务器中进入数据库:
sudo docker exec -it mongo bin/bash进入数据库后列出sharelatex的用户:
mongoexport -d sharelatex -c users -f email参考
Latex编辑之服务器自建开源Sharelatex(overleaf) - 知乎
overleaf/overleaf: A web-based collaborative LaTeX editor
安装完成后其他bug问题,可以到github中寻找解决方法或提问
评论区