在自己的服务器上配overleaf


最近要写毕业论文什么的,因为目前在实习,可能会干完活后在公司的电脑上写毕业论文,也可能会自己在出租房写毕业论文,所以需要协同编辑。而我又不想要在https://www.overleaf.com/ 上完成,因为它加载缓慢,体验有一点差。所以我就想起来可以在自己的服务器上部署overleaf服务,这样就可以实现协同编辑,也不会因为加载缓慢而十分难受。

安装过程

首先安装最新版的docker,较为简单。

用docker 拉对应的镜像:

1
docker pull sharelatex/sharelatex

根据官网创建了文件夹来挂载容器中的文件夹:

1
mkdir ~/sharelatex/ ~/sharelatex_data/ ~/mongo_data/ ~/redis_data/

下载docker-compose.yml,将它放到~/sharelatex中。链接如下:

1
https://raw.githubusercontent.com/sharelatex/sharelatex/master/docker-compose.yml

对这个配置文件进行编辑,主要是因为它默认配置的80端口号已经被占用,所以我就给它随便换了个其他的端口号,就是第十五行的ports选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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:
- 8080:80
links:
- mongo
- redis
volumes:
- ~/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:
- ~/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:
- ~/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

然后进入~/sharelatex/执行:

1
docker-compose up -d

然后等待下载即可。

完成下载后,用浏览器打开:

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

完成管理员账号的注册。

安装完毕。

更新LaTeX版本

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

首先进入容器的bash:

1
docker exec -it sharelatex bash

然后进入texlive的位置:

1
cd /usr/local/texlive

然后执行以下命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 下载并运行升级脚本
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

配置中文字体

因为LaTeX默认带的中文字库缺乏很多生僻字,所以我加上了Windows的字库。首先将Windows系统下找到:

C:\Windows\Fonts,将这个文件夹用scp复制到服务器,然后进入Fonts文件夹执行:

1
rm -rf *.fon

然后将它拷贝到容器数据的挂载点中,即将字体文件夹传入容器。

进入容器:

1
2
3
docker exec -it sharelatex bash
cd /usr/share/fonts/
mkdir windows

然后将字体文件夹拷贝到新创建的window文件夹下,执行:

1
fc-cache

即可安装字体文件。

然后查看字体文件是否正确安装:

1
fc-list | grep windows

可以看到字体正确安装。如果需要使用其他字体也可以安装。

这样就完成了整个安装的过程,然后就可以愉快地使用自己的overleaf服务了。

参考

Quick-Start-Guide

Overleaf搭建

实践自部署Overleaf

基于overleaf搭建在线服务器,Overleaf以及sharelatex如何安装各种字库