YEditor 开源在线编辑器环境搭建

开源库地址:https://github.com/litttley/editor.sh

功能流程图:

+--------------+
|    CLIENT    +----------------+
+------+-------+                |
       |                        |
       |                        |
       |                        |
       |                        |
       |                        |
+------v-------+        +-------v-------+                  +-----------------+
|              |        |               |                  |                 |
|  API SERVER  |        |  ROOM SERVER  +------------------>  RUNNER SERVER  |
|              |        |               |                  |                 |
+------+-------+        +-------+-------+                  +--------+--------+
       |                        |                                   |
       |                        |                                   |
       |                        |                                   |
       |                        |                                   |
       +------+                 |                                   |
              |                 |                                   |
              |                 |                                   |
        +-----v------+          |                        +----------v----------+
        |            |          |                        |                     |
        |  DATABASE  <----------+                        |  DOCKER CONTAINERS  |
        |            |                                   |                     |
        +------------+                                   +---------------------+

CLIENT (yeditor_client):实现单页面应用程序Angular(注:前端页面程序)。

API SERVER (yeditor):负责login,authorization和business logic(注:github第三方权登录)。

ROOM SERVER (yeditor):负责room在会员之间主持实时,同步编辑操作和终端操作。

RUNNER SERVER (yrunner-go):无状态服务器,用于在隔离环境中运行命令和交互式shell。

YSCRIPT (yscript):每个docker镜像的入口点,为运行任何语言提供统一的界面(启动各种语言的image)。

项目目录:
在这里插入图片描述

启动客户端(yeditor_client)

进行 yeditor_client 使用npm build 构建, npm run serve 运行,Angular的构建方法可自行百度

构建容器(containers)

containers 是生成支持语言docker image映像
支持语言:

bash
c
csharp
cpp
clojure
coffeescript
crystal
elixir
erlang
fsharp
go
haskell
java
javascript
kotlin
markdown
mysql
ocaml
objc
php
perl
perl6
plaintext
postgres
python2
python3
r
ruby
rust
scala
swift
typescript
vb

构建容器

cd containers && make build && cd ..

构建完查看



[root@iZwz9938t1plpjxsy3riqdZ ~]# sudo docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
yscript/typescript     latest              06c31d524359        24 hours ago        972MB
yscript/swift          latest              f0edc8e50262        24 hours ago        1.36GB
yscript/scala          latest              2701de152970        24 hours ago        519MB
yscript/rust           latest              ff23eaafff1d        24 hours ago        1.7GB
yscript/ruby           latest              088a667d65d3        24 hours ago        879MB
yscript/r              latest              c01dcdc5add1        24 hours ago        652MB
yscript/python3        latest              2b7b806b913e        24 hours ago        938MB
yscript/python2        latest              04c750a106d9        24 hours ago        923MB
yscript/postgres       latest              2f5f52a05fb2        24 hours ago        321MB
yscript/php            latest              8b8cdd146a47        24 hours ago        376MB
yscript/perl6          latest              c1a46fc7c1bc        24 hours ago        378MB
yscript/perl           latest              fa6b15df894b        24 hours ago        917MB
yscript/ocaml          latest              36f939b33f54        24 hours ago        866MB
yscript/mysql          latest              41ef888c0859        24 hours ago        358MB
yscript/mono           latest              6c3fc4897ec0        24 hours ago        661MB
yscript/markdown       latest              bfdf512e0ea6        24 hours ago        951MB
yscript/lua            latest              a263c7db0f17        24 hours ago        125MB
yscript/kotlin         latest              dc8f4105331e        24 hours ago        659MB
yscript/julia          latest              aa256805afdb        24 hours ago        459MB
yscript/javascript     latest              0308f13d514f        24 hours ago        915MB
yscript/java           latest              9a56fddea54b        24 hours ago        497MB
yscript/haskell        latest              9bc8a743f450        24 hours ago        1.27GB
yscript/groovy         latest              079c62604929        24 hours ago        256MB
yscript/golang         latest              604fc6a424ad        24 hours ago        801MB
yscript/gnustep        latest              18d6567c28c2        24 hours ago        1.32GB
yscript/erlang         latest              06c992d577f6        24 hours ago        1.08GB
yscript/elixir         latest              f5d880d24124        24 hours ago        1.09GB
yscript/crystal        latest              c41a7809052f        24 hours ago        549MB
yscript/coffeescript   latest              282944338291        24 hours ago        917MB
yscript/clojure        latest              b1ff431680de        24 hours ago        516MB
yscript/clang          latest              d3652ffbb00e        24 hours ago        813MB
yscript/bash           latest              9efd0c37d2ed        24 hours ago        97.8MB
yscript/assembly       latest              fcc7426dd26d        24 hours ago        142MB
node                   latest              451b716593e5        26 hours ago        906MB
elixir                 latest              539c2703fa83        27 hours ago        1.08GB
mariadb                latest              56089178535f        28 hours ago        349MB
erlang                 latest              a141ff219642        2 days ago          1.07GB
clojure                latest              02ab427e5819        4 days ago          507MB
groovy                 latest              6f05384cdb19        5 days ago          247MB
php                    latest              a62c67056b4c        5 days ago          367MB
zenika/kotlin          latest              4de8137b8834        5 days ago          650MB
openjdk                8                   4a0a42e87cf3        7 days ago          488MB
perl                   latest              2c0b349829f1        8 days ago          889MB
rust                   latest              ebbccec464d9        13 days ago         1.7GB
haskell                latest              59a6b912e873        2 weeks ago         1.26GB
julia                  latest              5962892f8ae5        2 weeks ago         450MB
swift                  latest              e8afdee6e52d        3 weeks ago         1.35GB
ubuntu                 19.04               9b17fc7d6848        3 weeks ago         75.4MB
golang                 latest              7ced090ee82e        4 weeks ago         774MB
ruby                   latest              682cc2f5b383        4 weeks ago         870MB
python                 2                   3c01ed1c16af        4 weeks ago         914MB
mono                   latest              831a16f6ca10        4 weeks ago         652MB
python                 latest              a4cc999cf2aa        4 weeks ago         929MB
r-base                 latest              fd2d644d699f        4 weeks ago         643MB
crystallang/crystal    latest              6f2fddfb9e97        7 weeks ago         541MB
rakudo-star            latest              3bcffcb4f7c2        7 weeks ago         369MB
postgres               latest              9c116111eb08        2 months ago        312MB
rsmmr/clang            latest              8a1150587378        2 months ago        804MB
ubuntu                 latest              94e814e2efa8        2 months ago        88.9MB
hello-world            latest              fce289e99eb9        5 months ago        1.84kB
ocaml/ocaml            latest              08012650cedf        18 months ago       857MB
[root@iZwz9938t1plpjxsy3riqdZ ~]# 

配置yeditor服务

1.数据库为postgres ,用docker构建,具体方法自行百度;
安装deisel客户端依赖

cargo install diesel_cli

2.数据库迁移

.evn 文件

DATABASE_URL=postgres://postgres:root@localhost:5432/yeditor
GITHUB_CLIENT_ID=####
GITHUB_CLIENT_SECRET=#####

新建数据库名为yeditor

迁移:

cd yeditor && cargo run -- --migration && cd 

github第三方授权

打开 setting/Developer settings 面板下的Oauth Apps
在这里插入图片描述
添写配置如下
在这里插入图片描述

生成 Client ID 和Client Sec
ret 在这里插入图片描述
将生成的id对应添到.env文件配置中

运行

方式一:

[root@iZwz9938t1plpjxsy3riqdZ yeditor]# cargo run --release
    Finished release [optimized] target(s) in 0.33s
     Running `target/release/yeditor`

方式二:
后台运行

sudo nohup ./target/release/yeditor &

注运行端口为4000

配置yrunner-go服务

启动

方式一:

# start RUNNER SERVER
cd yrunner-go && go build -o bin/yrunner && ./bin/yrunner service --config config.yaml --debug

方式二:

cd yrunner-go && go build -o bin/yrunner#编译
sudo nohup ./bin/yrunner service --config config.yaml   &#运行

运行端口为4500

nginx服务配置

nginx安装 :https://www.runoob.com/linux/nginx-install-setup.html
nginx.conf文件配置
/usr/local/webserver/nginx/conf/nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       4300;
        server_name  0.0.0.0;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/webserver/nginx/html;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/webserver/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        location /graphql {
            proxy_pass   http://0.0.0.0:4000;
        }
		
		location /playground {
            proxy_pass   http://0.0.0.0:4000;
        }

		
		location ^~ /realtime {
            proxy_pass   http://0.0.0.0:4000;
        

        proxy_redirect    off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
		}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
		
		
		     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                root  /usr/local/webserver/nginx/html;
                if (-f $request_filename) {
                expires 1d;
                break;
                }
        }
    
        location ~ .*\.(js|css)$
                {
                root /usr/local/webserver/nginx/html;
                if (-f $request_filename) {
                expires 1d;
                break;
        }
} 
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

相关运行命令:
Nginx 启动命令如下:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx

检查配置文件nginx.conf的正确性命令:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值