简体   繁体   English

亚马逊上的Haskell(Yesod)

[英]Haskell (Yesod) on Amazon

I want to deploy a system made in Yesod using Amazon Web Service. 我想使用Amazon Web Service部署Yesod制作的系统。 But can't find a good tutorial or steps on how to do it. 但是找不到一个好的教程或者如何做到的步骤。

Looking for a web host that can handle Haskell says that Amazon EC2 is the best. 寻找可以处理Haskell的Web主机说Amazon EC2是最好的。 But it doesn't tell how to do it or give a link. 但它没有说明如何做或给出一个链接。 Also it has a comment that I can link my S3 to EC2. 它还有一个评论,我可以将我的S3链接到EC2。

I'd suggest you to look at https://github.com/snoyberg/keter/ and Halcyon at https://halcyon.sh/ 我建议你看看https://github.com/snoyberg/keter/和太平在https://halcyon.sh/

They are deployment managers for Haskell web apps. 他们是Haskell Web应用程序的部署管理器。 Keter was written in Haskell and Halcyon shell. Keter是用Haskell和Halcyon shell编写的。

In my opinion keter handles amazon better and halcyon is more for dependencies, initial setup, heroku and digital ocean. 在我看来,keter处理亚马逊更好,而halcyon更多的依赖,初始设置,heroku和数字海洋。 Both are awesome. 两者都很棒。

(UPDATE 25-02-2015) (2015年2月25日更新)

Keter is mentioned at Developing Web Apps with Haskel and Yesod, 2nd Edition, launched this February 2015, ( http://www.yesodweb.com/book/deploying-your-webapp ). Keter在2015年2月推出的使用Haskel和Yesod的第二版开发Web应用程序中提到,( http://www.yesodweb.com/book/deploying-your-webapp )。 I highly recommend it, both the tools and the book. 我强烈推荐它,包括工具和书籍。

Also, I'd recommend heroku if it's just a pet project or something to test on. 此外,如果它只是一个宠物项目或要测试的东西,我会推荐heroku。

Links: 链接:

http://shop.oreilly.com/product/0636920035664.do http://shop.oreilly.com/product/0636920035664.do

http://www.amazon.com/Developing-Apps-Haskell-Yesod-Safety-Driven/dp/1491915595/ref=dp_ob_title_bk http://www.amazon.com/Developing-Apps-Haskell-Yesod-Safety-Driven/dp/1491915595/ref=dp_ob_title_bk

https://github.com/snoyberg/keter/ https://github.com/snoyberg/keter/

https://halcyon.sh/ https://halcyon.sh/

I could use Nginx as a front end server, and use Yesod app as the reverse proxy on EC2/Ubuntu 14.04. 我可以使用Nginx作为前端服务器,并使用Yesod app作为EC2 / Ubuntu 14.04上的反向代理。 I didn't try Keter, as Nginx/Yesod just works fine. 我没有尝试过Keter,因为Nginx / Yesod工作正常。 I assume you already install the Nginx. 我假设你已经安装了Nginx。

Installation of Haskell/Yesod 安装Haskell / Yesod

As the Yesod author comments in http://www.yesodweb.com/page/quickstart , Stackage ( https://www.stackage.org ) is really easy to install dependent libraries, and even Haskell itself. 正如Yesod作者在http://www.yesodweb.com/page/quickstart中所述 ,Stackage( https://www.stackage.org )非常容易安装依赖库,甚至是Haskell本身。 I followed this site ( https://github.com/commercialhaskell/stack/blob/master/doc/install_and_upgrade.md ) to easily install Stack on Ubuntu 14.04. 我按照这个站点( https://github.com/commercialhaskell/stack/blob/master/doc/install_and_upgrade.md )在Ubuntu 14.04上轻松安装Stack。

  1. wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -
  2. echo 'deb http://download.fpcomplete.com/ubuntu/trusty stable main'|sudo tee /etc/apt/sources.list.d/fpco.list
  3. sudo apt-get update && sudo apt-get install stack -y

You can use stack ghci to launch Haskell REPL. 您可以使用stack ghci来启动Haskell REPL。

Create and build Yesod project 创建和构建Yesod项目

  • stack new my-project yesod-sqlite && cd my-project
  • stack install yesod-bin cabal-install --install-ghc
  • stack build

Use swap to benefit more memory 使用swap来获得更多内存

For my EC2 server, I havd only 1G memory not to finish the build, but I could use swap to use more memory - https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 对于我的EC2服务器,我只有1G内存不能完成构建,但我可以使用swap来使用更多内存 - https://www.digitalocean.com/community/tutorials/how-to-add-swap-on- Ubuntu的14-04

  1. sudo fallocate -l 4G /swapfile
  2. sudo chmod 600 /swapfile
  3. sudo mkswap /swapfile
  4. sudo swapon /swapfile

Development test 开发测试

  • stack exec -- yesod devel

You can launch webbrowser to check with http://localhost:3000 . 您可以启动webbrowser以使用http://localhost:3000进行检查。

Deployment 部署

From http://www.yesodweb.com/book/deploying-your-webapp , I need three components to deploy to other machine. http://www.yesodweb.com/book/deploying-your-webapp ,我需要三个组件部署到其他机器。

  1. Your executable. 可执行文件。
  2. The config folder. 配置文件夹。
  3. The static folder. 静态文件夹。

The stack build command gives me the location of the executable: stack build命令为我提供了可执行文件的位置:

my-project-0.0.0: install
Installing library in
/home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/lib/x86_64-linux-ghc-7.10.2/my-project-0.0.0-Khn8lQEgR1HARzYGStlvPe
Installing executable(s) in
/home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/bin
Registering my-project-0.0.0...

The executable is located in /home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/bin . 可执行文件位于/home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/bin I could copy the files (executable, static, and config) in ~/deployment directory to check the Yesod works fine. 我可以复制〜/ deployment目录中的文件(可执行文件,静态文件和配置文件)来检查Yesod工作正常。

This is the directory structure. 这是目录结构。

├── config
│   ├── client_session_key.aes
...
│   └── test-settings.yml
├── my-project
└── static
    ...

Change port number 更改端口号

Change the port number in config/settings.yml 更改config / settings.yml中的端口号

port:           "_env:PORT:3002"
approot:        "_env:APPROOT:http://localhost:3002"

(I'm not sure why) However, to make the settings.yml work, you need to copy the file in current directory, then run the ./my_project settings.yml . (我不知道为什么)但是,要使settings.yml工作,您需要复制当前目录中的文件,然后运行./my_project settings.yml

Check http://localhost:3002 . 检查http://localhost:3002

Setup Nginx server 设置Nginx服务器

This is the conf file for Yesod. 这是Yesod的conf文件。

# the IP(s) on which your node server is running. I chose port 3000.
upstream yesod {
        server 127.0.0.1:3002;
        keepalive 8;
}

# the nginx server instance
server {
        listen 0.0.0.0:80;
        server_name yesod.example.com;
        access_log /var/log/nginx/access_yesod.log;
        error_log /var/log/nginx/error_yesod.log;

        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;

            proxy_pass http://yesod/;
            proxy_redirect off;
        }

        location /excluded {
            return 403;
        } 
}

Copy this file in /etc/nginx/site-enabled (or make symlink from site-available), then relaunch the nginx sudo server nginx restart . 在/ etc / nginx / site-enabled中复制此文件(或从site-available中创建符号链接),然后重新启动nginx sudo server nginx restart

Now, you can access the Yesod app from http://yesod.example.com . 现在,您可以从http://yesod.example.com访问Yesod应用程序。

References 参考

Yesod book has a whole chapter on how to deploy your Yesod app http://www.yesodweb.com/book/deploying-your-webapp Yesod书中有关于如何部署Yesod应用程序的整章, http: //www.yesodweb.com/book/deploying-your-webapp

Amazon is recommended there, so it should work on amazon without any trouble. 亚马逊在那里推荐,所以它应该在亚马逊上工作没有任何麻烦。 If you'll have more specific questions regarding keter -- please post them as new questions then. 如果您对keter有更具体的问题 - 请将其作为新问题发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM