为什么80%的码农都做不了架构师?>>>   

Problem of storage and delivering static content is quiet actual nowadays. Lots of people needs big and reliable storages for storing static images and many other static files and delivering it to end users. Most popular solution still is NFS mounted storage, which is accessible from all front-ends, but this solution has big bottlenecks.

  1. Hard to backup.
  2. Everything relies on NAS.
  3. Statically mounted external storage is needed.

Now lets dig deeper: 

Hard to Backup :Some of you will say that this is not so ! But lets imagine that you have 10TB of small images which your application regularly use and this images are very critical. Standard rsync and or tar could take lots of time and system resources, which is definitely not what we want.

Everything relies on NAS : So what ? We an buy a reliable NAS/SAN with cool RAID(1-10) storage and use it. But if we have a closer look we will see that for having 10TB space with for example 10x1TB 15k RPM SAS drives we will need at least 11x drives + RAID controller. Everything is good so far, but wait what is the price for that. After digging internet shops and price-lists you will see that this is quiet expensive, especial if your data is very critical and you need hot-backup aka second NAS/SAN. Another bottleneck is that in that in this solution you will have to do vertical only scalability. This is expensive and hard to achieve. And at least by order but not by meaning is that you will have to share same IO  device for all. This is truly a problem for large scale deployments.

Statically mounted external storage is needed: This means that all your system will rely on externally mounted device and regardless how reliable is that, it is some king of SPOF.

So combining this all will show that classical shared storage architecture is hard to implement, expensive and has slow performance for large deployments. This may not me a big deal if, you are IT of Bank, and you management has lots of money and very little “imagination”. In this case this article is not for you 

So for everyone else: 

lets summarize what we need:

  1. Reliable storage.
  2. Low latency to access file.
  3. Easy management and backup.
  4. Reliability and fault tolerance.
  5. Easy access and less programming overhead.

After spending lots of time for finding a solution for mentioned problems we found seems ideal solution:

  1. Riak (Will act as storage and deliver files )Four our needs free, community edition is much more than enough
  2. NginX (Will act as reverse proxy and URL filter)

Before starting let’s summarize what these two tools will give us:

Riak: Wonderful, fully clusterized NoSQL server written in Erlang. It works asynchronously, has great performance and easy access via REST, protobuf and lots of other interfaces. It also has built in realtime Search index and MapReduce Implementation. But for now we will use only small par of Riak, aka storage for static files. In this scenario we must look  on several benefits against shared storage solution.

  1. Low latency to access files. (Riak bitcask uses Single Seek to Retrieve any value )
  2. Horizontally scaleable. (Just add more and more cheap servers to the cluster)
  3. Much more throughput (for example 10 servers with 1xGbit por will have total 10 Gbit minus about 10% internal utilization)
  4. No need for expensive Raids, SAN etc

So lets start my favorite part: Installation and configuration of mentioned above. As I’m Debian fan, I will do this on current Stable release Debian 6.0 Squeeze

First you need t download and install Riak. At the moment of writing this article this was the latest version of Riak but before just copy-pasting check out for latest version here: http://basho.com/resources/downloads/.

Download and Install Riak:

# cd /usr/local/src
# wget http://s3.amazonaws.com/downloads.basho.com/riak/CURRENT/debian/6/riak_1.2.1-1_amd64.deb
# dpkg -i riak_1.2.1-1_amd64.deb

Done! Riak is installed. Do not start it for now. Just in case:

# /etc/init.d/riak restart

Now we need to clusterize it and make some configuration changes. By default Riak binds on 127.0.0.1 whic ix not a good idea fo clusters  so change it to internal ip address of server,do not bind Riak on servers public IP is that exist . 

edit /etc/riak/app.config and change:

{pb_ip,   "192.168.235.111" }, and {http, [ {"192.168.235.111", 8098 } ]},

Also make sure you have configured /etc/hosts file and system hostname. Correct /etc/hosts should look something like this: Also make sure you have configured /etc/hosts file and system hostname. Correct /etc/hosts should look something like this:

127.0.0.1 localhost
192.168.235.111 riak1.your-domain.com riak1

Also if you do not have your own internal DNS, you will have to add other nodes to /etc/hosts as well, but better to have DNS.

192.168.235.112 riak2.your-domain.com riak2
192.168.235.113 riak3.your-domain.com riak3
192.168.235.11N riakN.your-domain.com riakN

Also make some changes for storage configuration: format and mount your bid disk to /var/lib/riak:

# mkfs.xfs /dev/sdb1
# mount /dev/sdb1 /mnt
# mv /var/lib/riak/* /mnt/
# umount /mnt
# mount /dev/sdb1 /var/lib/riak
# chown -R riak.riak /var/lib/riak

Or better just create another mount-point and reconfigure Riak to use it

# mount /dev/sdb1 /opt
# mkdir /opt/riak
# chown riak.riak /opt/riak
# mv /var/lib/riak/* /opt/riak

Change paths in /etc/riak/app.config:

{riak_core, [
{ring_state_dir, "/opt/riak/riak/ring"},
...--------...
{bitcask, [{data_root, "/opt/riak/bitcask"} ]},
{eleveldb, [{data_root, "/opt/riak/leveldb"}]},

Also it would be nice to enable Riak console to have nice WUI It is installed by default so all you need is to change userlist from {userlist, [{"user", "pass"} to actual values. and make sure {admin, true} exist. It is also highly recommended to enable HTTPS and user secure link to admin Riak. For that you will need to enable HTTPS at riak_core section and add Certificate and Private key files:

{https, [ {"192.168.235.111", 8069 } ]},{ssl, [{certfile, "/etc/riak/ssl/riak.crt"},{keyfile, "/etc/riak/ssl/riak.pem"}
]},

That's all ! now restart Riak and login to Riak Admin via https://192.168..233.111:8069/admin. also edit /etc.riak/vm.args and change Now restart Riak:

-name riak@127.0.0.1
to
-name riak@riak1.your-domain.com

/etc/init.d/riak restart

Nor we need to more nodes to have redundancy: lets imagine that we have 3 nodes cluster for now. So repeat all steps above on riak2.your-domain.com and riak3.your-domain.com: Now you have 3 separate nodes, now need to join them all to single cluster: Very nice guide to do this is here Shortly you need yo do following: After making apropriate configs on node 2 and 3

riak-admin cluster join riak@riak1.your-domain.com

And only on riak1 node

riak-admin cluster plan
riak-admin cluster commit

Now you have fully clusterized and working Riak installation. to test is do following:

curl -v -X PUT http://192.168.235.111:8098/riak/images/foo.jpg -H "Content-type: image/jpg" --data-binary @./foo.jpg

Full reference to Riak cUrl commands is here Now open http://192.168.235.111:8098/riak/images/foo.jpg with your favorite browser: Just for Fun open all 3 nodes and see same picture: Great we have completed with Riak installation, now  lets install and configure NginX front-end. apt-get install nginx Now edit /etc/nginx/sites-enabled/default and replace content with this:

upstream riak {server 192.168.235.111:8098 fail_timeout=30s;server 192.168.235.112:8098 fail_timeout=30s;server 192.168.235.113:8098 fail_timeout=30s;
}server {listen 80;server_name  your.public.domain;if ( $uri !~ \. ) { return 403; }       # Require URI with file extension if ( $uri !~ ^/.*/.* ) { return 403; }  # Disable access to Riak / if ( $uri ~ ^/.*/.*/.* ) { return 403;} # Disable Link walk MR etc  location / {if ($request_method = GET){proxy_pass http://riak;rewrite ^/(.*) /riak/$1 break;          # Remove /riak from external URL (Hide Riak)}proxy_redirect          off;proxy_next_upstream     error timeout invalid_header http_500;proxy_connect_timeout   2;proxy_set_header        Host            $host;proxy_set_header        X-Real-IP       $remote_addr;proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header        Referer         ""; # Zero up referer or Riak will 403 all requests proxy_hide_header       X-Riak-Vclock;      # Remove Riak specific headersproxy_hide_header       Link;               # Remove Riak specific headers proxy_hide_header       ETag;               # Remove Another Riak header proxy_hide_header       Server;}}

After all this done you can get you image via http://your.public.domain/images/foo.jpg without any Riak specific tags and links. 原文地址: http://netangels.net/knowledge-base/nginx-and-riak/#.Uo3xN9JkP-Z

转载于:https://my.oschina.net/766/blog/210967

NginX and Riak相关推荐

  1. nginx教程全集汇总(ttlsa出品)

    为什么80%的码农都做不了架构师?>>>    nginx教程写了一段时间,无意中发现,nginx相关文章已经达到了近100篇了.觉得很有必要汇总到一起,它是我们运维生存时间的一片心 ...

  2. nginx汇总(z)

    Nginx相关文章 Nginx基础 1.  nginx安装 2.  nginx 编译参数详解 3.  nginx安装配置+清缓存模块安装 4.  nginx+PHP 5.5 5.  nginx配置虚拟 ...

  3. nginx+memcache实现页面缓存应用

    一.前言 nginx的memcached_module模块可以直接从memcached服务器中读取内容后输出,后续的请求不再经过应用程序处理,如php-fpm.django,大大的提升动态页面的速度. ...

  4. 服务器支持http tcp,Nginx配置http和tcp(示例代码)

    最近在弄ejabberd+riak.其实这俩东西配置挺坑的,然后具体这俩货怎么配置,我以后会抽空写出配置的详细过程.对于负载均衡,我知道的现在有Nginx/LVS/HAProxy这三个大仙儿,各自有各 ...

  5. JavaWeb笔记:第07章 MVC |EL |JST |Filter |Listener |JQuery |AJAX |Maven |JSON |Redis |Linux |Nginx

    JavaWeb笔记:第07章 MVC |EL |JST |Filter |Listener |JQuery |AJAX |Maven |JSON |Redis |Linux |Nginx 1. MVC ...

  6. nginx配置http、https访问,nginx指定ssl证书,阿里云腾讯云华为云设置nginx https安全访问

    nginx配置http.https访问 要设置https访问需要从对应的云厂商申请证书,并下载Nginx证书到服务器. 我这里从阿里云申请了免费的域名证书,然后将证书放置在服务器的/etc/ssl/. ...

  7. Web项目使用nginx实现代理端口访问,看这篇就够了

    在搭建服务器的时候,项目部署在tomcat上,要访问项目,则需要加上端口号,如何隐藏端口号来访问呢,这就用到了nginx. nginx可以在docker上安装,也可以在linux上安装,这里我建议使用 ...

  8. nginx介绍及常用功能

    什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务. Apache:重量级的,不支持高并发的服务器.在Apache上运行数以万计的并发访 ...

  9. Nginx搭建负载均衡集群

    (1).实验环境 youxi1 192.168.5.101 负载均衡器 youxi2 192.168.5.102 主机1 youxi3 192.168.5.103 主机2 (2).Nginx负载均衡策 ...

最新文章

  1. R语言使用ggplot2包使用geom_boxplot函数绘制基础分组箱图(输出多个分组)实战
  2. linux 设备管理工具 udev 规则编写
  3. 《java编程思想》学习笔记——复用类
  4. 音频处理五:(音频的FFT计算)
  5. mysql 执行计划 优化_执行计划
  6. Krpano skin_settings解释
  7. Java多线程系列(一):最全面的Java多线程学习概述
  8. mysql 不会联想字段_你有没有被MySQL的这个bug坑过?
  9. ansible之二:模块用法
  10. CSS级联样式表-css选择器
  11. Matlab期货量化交易特征选取,【策略分享】Matlab量化交易策略源码分享
  12. 《计算机网络》简要学习笔记:未完自用
  13. 你要“老婆”不?谷歌程序员20行代码送你一个!
  14. 瑞星杀毒软件 奇虎360杀毒软件 360卫士 百度卫士联手,搞不定弹出广告 恶意广告图标
  15. librdkafka自动源码编译
  16. pc端软件怎么做性能测试,企点PC端性能测试——UI卡顿分析
  17. Asio tcp异步例子
  18. 计算机专用计算器,功率计算器
  19. python利用公式计算_Python利用openpyxl处理Excel文件(公式实例)
  20. Python之Pandas连接详解

热门文章

  1. 推荐14个牛逼的代码编辑网站
  2. pika详解 (一)
  3. Vi(Vim)快捷键
  4. 桌面的计算机打开缓慢,电脑桌面上的文件夹和图标都打开很慢,怎么回事?
  5. TYPEC无协议芯片最高可输出5V3A
  6. 从业务数字化到数字化业务,重新定义CIO|2021全球数字价值峰会
  7. Java编写网络打字游戏
  8. 最优化建模算法理论之Goldstein准则(数学原理及MATLAB实现)
  9. OpenStack-Pike版Ironic安装指导分析-(上)
  10. AWS 服务器登录和配置