# Overleaf搭建

## Overleaf简介

overleaf是一个在线latax写论文的神器，不用配置本地环境，浏览器访问即可实时编译，而且其提供多人协作功能，但是官网具有诸多限制，例如空间等，且安全性等因素不能保证，所幸其已在github进行开源，我们可以在自己的服务器通过docker进行部署。

## Docker安装

有关docker的入门可以参考[阮一峰先生的博文](http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html)。这里笔者参考[docker官网安装教程](https://docs.docker.com/engine/install/)尝试了在ubuntu 18,ubuntu 20,macos上进行了分别部署，均未遇到坑，在此不再赘述。

可以通过以下命令查看是否安装成功：

```
docker version
```

## Overleaf安装

1. 拉取最新的overleaf服务器版本

   ```
   docker pull sharelatex/sharelatex
   ```
2. 在用户目录`~`下，新建以下文件夹

   ```
   mkdir ~/sharelatex/ ~/sharelatex/sharelatex_data/ ~/sharelatex/mongo_data/ ~/sharelatex/redis_data/
   ```
3. 下载`docker-compose.yml`文件到`~/sharelatex/`文件夹下

   ```
   curl -O https://raw.githubusercontent.com/sharelatex/sharelatex/master/docker-compose.yml
   ```
4. 修改`docker-compose.yml`配置文件

   ```
   # 避免端口重复,默认80端口，但是笔者的80端口开放给了apache，因此这里修改为5000
   # 端口号:80
   ports:
       - 5000:80

   # 修改本地挂载目录
   volumes:
       ~/sharelatex/sharelatex_data:/var/lib/sharelatex

   # 添加升级texlive需要的环境变量，主要是添加2018目录到2017前面，目的是为了防止后面安装完整版texlive时出现错误
   # 【这里原博主有写，但是我添加以后好像并没有什么效果，不添加也是可以的】
   environment:
       - PATH: /usr/localsbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/2018/bin/x86_64-linux:/usr/local/texlive/2017/bin/x86_64-linux

   # 下面选项设置ShareLaTeX的显示样式
   SHARELATEX_APP_NAME: Our ShareLaTeX
   SHARELATEX_NAV_TITLE: Our ShareLaTeX Instance
   SHARELATEX_HEADER_IMAGE_URL: http://somewhere.com/mylogo.png
   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"} ]'

   # 修改mongo和redis的本地挂载目录
   # mongo
   volumes:
       ~/sharelatex/mongo_data:/data/db
   # redis
   volumes:
       ~/sharelatex/redis_data:/data
   ```

   这里附上我的[docker-compose.yml文件](https://app.gitbook.com/s/-M8EdP159RyjUv9qUZIH/docker-compose.yml)
5. 进入`~/sharelatex`启动`docker-compose.yml`

   ```
   docker-compose up -d
   ```
6. 由于默认安装的是最小版本 TeXLive，如果要安装完整包，执行

   ```
   docker exec sharelatex tlmgr install scheme-full
   ```
7. 第一次启动镜像后，浏览器访问 `localhost:port/launchpad` 页面设置管理员账号
8. 客户机可以在浏览器通过ip:port访问


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://junbin.gitbook.io/studynotes/overleaf-da-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
