ShareLaTeX安装、配置与部署

服务器操作系统

Ubuntu 16.04.6 LTS

安装docker

1
sudo apt install docker.io

查看是否安装成功

1
docker -v

确认curl等工具已安装**

1
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

下载ShareLaTeX及compose file

1
sudo docker pull sharelatex/sharelatex

配置数据文件夹**

1
2
3
4
5
6
cd ~
mkdir sharelatex
cd sharelatex
mkdir sharelatex_data
mkdir mongo_data
mkdir redis_data

下载docker-compose.yml,并存在~/sharelatex/目录下

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
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
privileged: true
ports:
- 80:80
links:
- mongo
- redis
volumes:
- ~/sharelatex_data:/var/lib/sharelatex
- /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'

## 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: [email protected]

# 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: "[email protected]"

# 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_CUSTOM_EMAIL_FOOTER: "<div>This system is run by department x </div>"

################
## 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
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
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
sudo docker-compose up

新建管理员账号

1
sudo docker exec sharelatex /bin/bash -c "cd /var/www/sharelatex; grunt user:create-admin [email protected]"

设置账号密码

进入容器

1
sudo docker exec -it sharelatex bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 下载并运行升级脚本
wget http://mirror.ctan.org/systems/texlive/tlnet/update-tlmgr-latest.sh
sh update-tlmgr-latest.sh -- --upgrade

# 更换texlive的下载源,例如国内的清华源
tlmgr option repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet/

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

# 更新字体缓存(好像没成功,但是不影响下面操作)
luaotfload-tool -fu

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

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

配置中文写作环境

  • 将Windows字体库(即目录C:\windows\fonts)上传到host机,如果Windows安装了Git可以使用scp命令直接上传
  • 在host机下把fonts目录打包并传到sharelatex容器中
1
2
3
4
5
6
7
8
9
10
11
12
13
# 进入fonts目录
cd fonts/

# 删除其中的.fon字体文件(该种格式文件在后面建立字体目录时会报错),只保留TrueType和OpenType字体,即.ttf和.otf
# 一般地,如果只需要其中特定的中文字体,只需要上传需要的字体即可
rm -r *.fon

# 返回上层目录并打包
cd ..
tar -zcvf winfonts.tar.gz fonts/

# 把压缩文件传到sharelatex容器的root目录下
docker cp winfonts.tar.gz sharelatex:/root
  • 在容器中安装Windows字体
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 进入容器的命令行界面
$ docker exec -it sharelatex bash

# 通过安装wqy字体同时安装xfont工具
$ apt-get install xfonts-wqy

# 进入root目录,解压winfonts.tar.gz,并剪切到系统字体目录下
cd ~
tar -zxvf winfonts.tar.gz
mv winfonts /usr/share/fonts/

# 进入字体目录安装字体
cd /usr/share/fonts/winfonts
mkfontscale
mkfontdir
fc-cache -fv

# 检查确认中文字体安装成功
fc-list :lang=zh-cn
  • 回到ShareLaTeX网站,创建一个新项目,使用CTEX宏集和XeLaTeX编译器,即可生成中文pdf。

其他

  1. 进入数据库:sudo docker exec -it mongo bash
  2. 列出sharelatex的用户:mongoexport -d sharelatex -c users -f email (需要先进入数据库)