ShareLaTeX

From PGWiki

ShareLaTeX은 온라인 LaTeX 편집기 서비스 혹은 설치형 소프트웨어를 말한다.

설치

$ git clone https://github.com/sharelatex/sharelatex.git
$ cd sharelatex
$ vim docker-composer.yml

docker-composer.yml 파일의 설정들을 적절히 변경할 필요가 있다.

version: '2'
services:
    sharelatex:
        restart: always
        image: sharelatex/sharelatex
        container_name: sharelatex
        depends_on:
            - mongo
            - redis
        privileged: true
        ports:
            - 8888:80
        links:
            - mongo
            - redis
        volumes:
            - ~/sharelatex_data:/var/lib/sharelatex
            - /var/run/docker.sock:/var/run/docker.sock
            #- /var/clsi/compiles:/var/www/sharelatex/clsi/compiles
        environment:
            SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex
            SHARELATEX_REDIS_HOST: redis
            SHARELATEX_APP_NAME: P.G. ShareLaTeX
...
  • ports : 외부에서 접근 가능하게 할 포트 번호로 변경
  • SHARELATEX_APP_NAME : 웹페이지 접근 시 보여지는 서비스명이므로 적절히 변경


이제 서비스 컨테이너를 구동시켜 보자.

$ sudo docker-compose up
Starting redis
Starting mongo
Recreating sharelatex
Attaching to redis, mongo, sharelatex
redis         | 1:C 23 May 16:14:14.193 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis         | 1:C 23 May 16:14:14.193 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=1, just started
redis         | 1:C 23 May 16:14:14.193 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
mongo         | 2018-05-23T16:14:14.288+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=dd78b5173c22
...
sharelatex    | nothing to migrate
sharelatex    | 
sharelatex    | Done, without errors.
sharelatex    | All migrations finished
sharelatex    | *** Running /etc/rc.local...
sharelatex    | *** Booting runit daemon...
sharelatex    | *** Runit started as PID 94
...

위와 같이 출력된다면 설치와 서비스 시작이 정상적으로 이루어진 것이다.

웹 브라우저를 통해 앞서 지정한 포트 번호로 접근해보면 로그인 페이지가 출력이 된다.

관리자 계정 생성

$ sudo docker exec sharelatex /bin/bash -c "cd /var/www/sharelatex; grunt user:create-admin --email <전자우편 주소>"
Running "user:create-admin" task
Set UV_THREADPOOL_SIZE=16
{"name":"default-sharelatex","hostname":"c6485ab0675e","pid":349,"level":40,"msg":"Email transport and/or parameters not defined. No emails will be sent.","time":"2018-05-23T16:16:53.950Z","v":0}
...

Successfully created potatogim@potatogim.net as an admin user.

Please visit the following URL to set a password for potatogim@potatogim.net and log in:

	http://<IP>/user/password/set?passwordResetToken=...


Done, without errors.

출력되는 주소로 접근하여 관리자 계정 비밀번호를 새로 설정한다.

localhost로 출력되는 경우에는 서버의 IP 주소와 포트 번호로 대체하여 접근하면 된다.

Nginx를 이용한 HTTPS 리버스 프록시 설정

## Redirects all HTTP traffic to the HTTPS host
server {
        server_name   tex.potatogim.net;
        server_tokens off; ## Don't show the nginx version number, a security best practice

        return        301 https://$http_host$request_uri;

        access_log    /var/log/nginx/sharelatex_access.log;
        error_log     /var/log/nginx/sharelatex_error.log;
}

server {
        listen 443 ssl;
        server_name tex.potatogim.net;

        ssl on;
        ssl_certificate     /.../SSL/fullchain.pem;
        ssl_certificate_key /.../SSL/privkey.pem;
        ssl_dhparam         /.../SSL/dhparam.pem;

        ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers   on;

        # used cloudflares ciphers https://github.com/cloudflare/sslconfig/blob/master/conf
        ssl_ciphers                 EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;

        # config to enable HSTS(HTTP Strict Transport Security) https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security
        # to avoid ssl stripping https://en.wikipedia.org/wiki/SSL_stripping#SSL_stripping      
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";

        server_tokens off;

        add_header X-Frame-Options SAMEORIGIN;

        add_header X-Content-Type-Options nosniff;

        client_max_body_size 50M;

        location / {
                proxy_pass http://localhost:8888; # change to whatever host/port the docker container is listening on.
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_read_timeout 3m;
                proxy_send_timeout 3m;

                access_log /var/log/nginx/sharelatex_access.log;
                error_log  /var/log/nginx/sharelatex_error.log;
        }
}

문제 해결

TexLive 2018로 판올림하기

2017 버전까지는 tlmgr로 패키지 업데이트가 가능했으나, 2018로 바뀐 이후에는 다음과 같은 오류가 발생한다.

sudo docker exec sharelatex bash -c 'tlmgr install scheme-full'
tlmgr: Remote repository is newer than local (2017 < 2018)
Cross release updates are only supported with
  update-tlmgr-latest(.sh/.exe) --update
Please see https://tug.org/texlive/upgrade.html for details.

메시지에서 보여지는 웹 페이지에 들어가면 tlmgr 업그레이드 스크립트의 링크가 제공되는데, 이 스크립트를 통해 업그레이드를 수행하자.

$ sudo docker exec sharelatex bash -c 'wget http://mirror.ctan.org/systems/texlive/tlnet/update-tlmgr-latest.sh'
$ sudo docker exec sharelatex bash -c 'chmod +x update-tlmgr-latest.sh'
$ sudo docker exec sharelatex bash -c './update-tlmgr-latest.sh'
Verifying archive integrity... All good.
Uncompressing TeX Live Manager Updater  100%  
./runme.sh: updating in /usr/local/texlive/2017...
./runme.sh: tlmgr version says this is TeX Live 2017
./runme.sh: proceeding with tlmgr update.
./runme.sh: /usr/local/texlive/2017/bin/x86_64-linux//tlmgr including objects: master/tlpkg/tlpobj/texlive.infra.tlpobj master/tlpkg/tlpobj/texlive.infra.x86_64-linux.tlpobj
D:tlmgr:main: ::tldownload_server not defined
D:Using system wget (tested).
D:Using shipped /usr/local/texlive/2017/tlpkg/installer/xz/xzdec.x86_64-linux for xzdec (tested).
D:Using shipped /usr/local/texlive/2017/tlpkg/installer/xz/xz.x86_64-linux for xz (not tested).
./runme.sh: done.

이제 다시 업데이트를 해보자.

$ sudo docker exec sharelatex bash -c 'tlmgr install scheme-full'
tlmgr: package repository http://mirrors.rit.edu/CTAN/systems/texlive/tlnet (verified)
[1/3524, ??:??/??:??] install: 12many [376k]
[2/3524, 00:03/05:42:53] install: 2up [66k]
[3/3524, 00:05/08:06:41] install: Asana-Math [482k]
[4/3524, 00:07/05:25:25] install: ESIEEcv [137k]
[5/3524, 00:10/06:45:00] install: FAQ-en [4971k]
...