对于想了解Rails3.1,Unicorn和Apache:静态文件的读者,本文将提供新的信息,我们将详细介绍gunicorn静态文件,并且为您提供关于ApacheCassandra和ApacheIgn
对于想了解Rails 3.1,Unicorn和Apache:静态文件的读者,本文将提供新的信息,我们将详细介绍gunicorn 静态文件,并且为您提供关于Apache Cassandra和Apache Ignite:强一致和事务、Capistrano+Nginx+Unicorn 自动部署Rails、Django Gunicorn无法加载静态文件、Django静态文件未加载gunicorn的有价值信息。
本文目录一览:- Rails 3.1,Unicorn和Apache:静态文件(gunicorn 静态文件)
- Apache Cassandra和Apache Ignite:强一致和事务
- Capistrano+Nginx+Unicorn 自动部署Rails
- Django Gunicorn无法加载静态文件
- Django静态文件未加载gunicorn
Rails 3.1,Unicorn和Apache:静态文件(gunicorn 静态文件)
我有Rails 3.1,Unicorn和Apache的设置。 我的Apache设置如下,production.rb看起来像这样 。 我喜欢使用h264stream媒体,但由于Rails提供这些video文件,Apache Mod将无法正常工作。
DocumentRoot /blabla/current/public RewriteEngine On Options FollowSymLinks <Proxy balancer://unicornservers> BalancerMember http://127.0.0.1:4000 </Proxy> # Redirect all non-static requests to rails RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L] ProxyPass / balancer://unicornservers/ ProxyPassReverse / balancer://unicornservers/ ProxyPreserveHost on <Proxy *> Order deny,allow Allow from all </Proxy> XSendFile On XSendFileAllowAbove on
我必须启用serve_static_assets或我无法下载任何静态的东西。 我也有预编译的资产,但它不会有任何区别,因为没有文件可从公共目录,除非Rails(机架我猜)正在做服务。
我应该使用config.action_controller.asset_host还是有什么问题,我的Apacheconfiguration。
Nginx:无法上传文件> 10MB。 客户打算发送太大的身体
在运行Angular 2快速入门时,在Linux上出错或修复NPM lite-server错误
WebDriverError错误:Chrome无法启动:exception退出
独angular兽与Capistrano重新启动不起作用
kgio /独angular兽失败
使用独angular兽将Rails应用程序部署到Opsworks时出错
在代理后面的rails应用httpsredirect?
无法创build用户postgres:angular色“postgres”不存在
configurationNginx使Angular 2快速启动浏览器同步
量angular器30000msec后超时
我有这个问题的帖子 (是的,这也发生在我身上),希望它会有所帮助。
关键是要删除ProxyPass / balancer://unicornservers/ pattern,因为它会覆盖您的Rewrite Rule
这是我的Apache服务器配置。
<VirtualHost *:80> serverName example.org DocumentRoot /dir/of/your/project RewriteEngine On # Redirect all non-static requests to unicorn RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,L] <Proxy balancer://unicornservers> BalancerMember http://127.0.0.1:2007 </Proxy> </VirtualHost>
只需从您的production.rb代码:
# Specifies the header that your server uses for sending files # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'x-accel-redirect' # for Nginx
尝试用“X-Sendfile”标题取消注释行,重新启动您的Unicorn池并重试。
Apache Cassandra和Apache Ignite:强一致和事务
NoSQL数据库,比如Apache Cassandra,是最终一致性系统的典型案例,这种系统的机制比较简单:如果应用在一台主机上触发了数据的变更,那么在某个时间点更新会被传播到所有的副本,换言之,最终一致。
在变更完全同步之前,系统作为一个整体会处于一个不一致的状态。如果从一个未同步的副本中读取变更的数据,更甚者,同时更新数据,谁知道会发生什么呢?
NoSQL的厂商和用户接受了这个机制和行为,因为最终一致给分布式系统带来了高可扩展和高性能,这是事实,如果需要强一致和事务,那么就得考虑传统RDBMS了,但是现在不是这样了!
在前面的文章中,提到即使在分布式数据库中,SQL也可以高效地执行。比如Apache Ignite,不仅仅可以执行简单的SQL操作,还可以容易地对存储于不同主机的数据进行关联,这在十年前是不可能的,但是目前已经成为现代分布式数据库的标配。
再次回到一致性和事务的话题,Ignite可以混合匹配NoSQL的水平扩展和高性能以及RDBMS领域的功能,下面会以Apache Cassandra作为NoSQL数据库的代表,与Ignite作为现代分布式数据库的代表进行比较。
可调一致性和轻量级事务
Cassandra关注于高数据一致性和事务,这不是秘密,因为这是用户的需求。 首先,如果将读写一致性级别配置为ALL,这就获得了最高的一致性。这个模式中,Cassandra会在完成提交日志和所有副本节点内存表的写入之后完成写入操作,相对应的对于读,会在所有副本认可的情况下,才会返回值。这个功能很方便,但是它在保证一致性的前提下,降低了性能,如果需要,可以启用。
其次,这个读写ALL模式没有解决并发更新的问题。如果要更新一个用户账户,如何确保没有其他人干扰呢?事务通常用于解决这样的问题,这时用户可以使用Cassandra的叫做轻量级事务(LWT)的功能。
轻量级事务是为避免单条记录的并发更新而特别设计的。比如,如果两个不同的应用都试图更新一个用户账户,那么LWT会确保只有一个应用成功,而其他的失败。假定第一个应用更早地发起了一个事务,那么就可以像下面这样安全而原子地对年龄进行修改:
UPDATE user_account
SET user_age=35
IF user_id=’Bob Smith’;
但是对于更复杂的操作,比如不同账户间的转账,会怎么样呢?
不幸的是,这超出了Cassandra及其LWT的范围,因为后者限定在单一分区内,而银行账户是可以存储在不同的集群节点上的。
强一致和ACID事务
虽然转账在Cassandra中是个大问题,但是在Ignite中却是个常规操作。 首先,在Ignite中要做到强一致性,需要配置FULL_SYNC同步模式以及为缓存(或者表)开启事务模式,甚至开启FSYNC模式的预写日志来避免整个集群的电源故障。
其次,使用Ignite的事务API,可以对可能存储在不同节点上的账户间进行转账操作:
try (Transaction tx = Ignition.ignite().transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
Account acctA = accounts.get(acctAid);
Account acctB = accounts.get(acctBid);
// Withdraw from accountB.
acctB.update(amount);
// Deposit into accountA.
acctA.update(amount);
// Store updated accounts in the cluster.
accounts.put(acctAid, acctA);
accounts.put(acctBid, acctB);
tx.commit();
}
就是这些,Ignite的ACID事务基于2阶段提交(2PC)的高级版,即使故障,也能保证数据的一致性,参考这个系列文章,可以学习Ignite事务子系统实现的更多细节。
总结
Ignite证明了分布式的ACID事务和强一致是可行的,并且被可以水平扩展和高可用的现代数据库广泛采用,它完全可以根据需要进行配置。看一下有多少金融机构信任Ignite,将其部署进核心应用,你就知道ASF的项目不是徒有虚名。
本文译自Denis Magda的博客。
Capistrano+Nginx+Unicorn 自动部署Rails
配置你的服务器
上传到github
这步需要将你的应用上传到github,在你的github上创建新的repository,然后在你本机代码位置执行下面的命令,初始化git仓库。
git init
git add .
git commit -m"<message>"
git remote add origin git@github.com:<username>/<git repo>.git
git push origin master
安装Capistrano
在你的Gemfile里添加下面的一行。
1
|
gem''capistrano''
|
然后执行
1
|
bundle
|
在你的项目目录里执行
1
|
capify .
|
执行结果
1
2
3
4
|
examination-paper ➤ capify . git:master*
[add] writing''./Capfile''
[add] writing''./config/deploy.rb''
[done] capified!
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
require"bundler/capistrano"
# Define your server here
server"<server>",:web,:app,:db, primary:true
# Set application settings
set:application,"<app_name>"
set:user,"<deployment_user>"# As defined on your server
set:deploy_to,"/home/#{user}/apps/#{application}"# Directoryinwhich the deployment will take place
set:deploy_via,:remote_cache
set:use_sudo,false
set:scm,"git"
set:repository,"git@github.com:<git_user>/#{application}.git"
set:branch,"master"
default_run_options[:pty] =true
ssh_options[:forward_agent] =true
after"deploy","deploy:cleanup"# keep only the last 5 releases
namespace:deploydo
%w[start stop restart].eachdo|command|
desc"#{command} unicorn server"
task command, roles::app, except: {no_release:true}do
run"/etc/init.d/unicorn_#{application} #{command}"# Using unicorn as the app server
end
end
task:setup_config, roles::appdo
sudo"ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo"ln -nfs #{current_path}/config/unicorn_ini.sh /etc/init.d/unicorn_#{application}"
run"mkdir -p #{shared_path}/config"
putFile.read("config/database.yml"),"#{shared_path}/config/database.yml"
puts"Now edit the config files in #{shared_path}."
end
after"deploy:setup","deploy:setup_config"
task:symlink_config, roles::appdo
run"ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after"deploy:finalize_update","deploy:symlink_config"
desc"Make sure local git is in sync with remote."
task:check_revision, roles::webdo
unless`git rev-parseHEAD` == `git rev-parse origin/master`
puts"WARNING: HEAD is not the same as origin/master"
puts"Run `git push` to sync changes."
exit
end
end
before"deploy","deploy:check_revision"
end
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
upstream unicorn {
server unix:/tmp/unicorn.<app_name>.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name <your_servername>;
if($host =''<your_servername>'') {
rewrite ^/(.*)$ http://<your_servername>/$1 permanent;
}
root/home/deployer/apps/<app_name>/current/public;
location ^~/assets/{
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri
@unicorn ;
location
@unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504/500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# Define your root directory
root ="/home/deployer/apps/gifroll/current"
# Define worker directory for Unicorn
working_directory root
# Location of PID file
pid"#{root}/tmp/pids/unicorn.pid"
# Define Log paths
stderr_path"#{root}/log/unicorn.log"
stdout_path"#{root}/log/unicorn.log"
# Listen on a UNIX data socket
listen"/tmp/unicorn.gifroll.sock"
# 16 worker processes for production environment
worker_processes16
# Load rails before forking workers for better worker spawn time
preload_apptrue
# Restart workes hangin'' out for more than 240 secs
timeout240
|
最后
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set-e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/<app_name>/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=<user>
set-u
OLD_PIN="$PID.oldbin"
sig () {
test-s"$PID"&&kill-$1 `cat$PID`
}
oldsig () {
test-s $OLD_PIN &&kill-$1 `cat$OLD_PIN`
}
run () {
if["$(id -un)"="$AS_USER"];then
eval$1
else
su-c"$1"- $AS_USER
fi
}
case"$1"in
start)
sig 0 &&echo>&2"Already running"&&exit0
run"$CMD"
;;
stop)
sig QUIT &&exit0
echo>&2"Not running"
;;
force-stop)
sig TERM &&exit0
echo>&2"Not running"
;;
restart|reload)
sig HUP &&echoreloaded OK &&exit0
echo>&2"Couldn''t reload, starting ''$CMD'' instead"
run"$CMD"
;;
upgrade)
ifsig USR2 &&sleep2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
whiletest-s $OLD_PIN &&test$n -ge0
do
printf''.''&&sleep1 && n=$(( $n - 1 ))
done
echo
iftest$n -lt 0 &&test-s $OLD_PIN
then
echo>&2"$OLD_PIN still exists after $TIMEOUT seconds"
exit1
fi
exit0
fi
echo>&2"Couldn''t upgrade, starting ''$CMD'' instead"
run"$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo>&2"Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
exit1
;;
esac
|
1
|
cap deploy:setup
|
1
|
ssh-add
|
1
|
cap deploy:cold
|
Django Gunicorn无法加载静态文件
我正在尝试使用gunicorn和nginx部署django项目,但我需要一些帮助。当我编码gunicorn
myproject.wsgi:application时,我设法在localhost页面上看到我的网站,但没有任何CSS。为什么gunicorn不将我的CSS文件加载到项目的静态文件夹中?
Guinicorn_start脚本:https : //dpaste.de/TAc4
Gunicorn输出:https
://dpaste.de/C6YX
Django静态文件未加载gunicorn
如何解决Django静态文件未加载gunicorn?
当我使用 python mange.py runserver 运行我的 Django 项目时,它运行良好,没有损坏和 CSS 或 javascript 文件,但是当我尝试使用 gunicorn 时,它无法加载任何静态文件 CSS 或 js 文件显示 404。
这是我的 Django settings.py
PROJECT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)))
LOCALE_PATHS = (os.path.join(PROJECT_DIR,"../locale"),)
RESOURCES_DIR = os.path.join(PROJECT_DIR,"../resources")
FIXTURE_Dirs = (os.path.join(PROJECT_DIR,"../fixtures"),)
TESTFILES_DIR = os.path.join(PROJECT_DIR,"../testfiles")
STATICFILES_Dirs = (
os.path.join(PROJECT_DIR,"../static"),os.path.join(PROJECT_DIR,"../media"),"../node_modules"),"../node_modules/react/umd"),"../node_modules/react-dom/umd"),)
STATIC_ROOT = os.path.join(PROJECT_DIR,"../sitestatic")
STATIC_URL = "/sitestatic/"
COMPRESS_ROOT = os.path.join(PROJECT_DIR,"../sitestatic")
MEDIA_ROOT = os.path.join(PROJECT_DIR,"../media")
MEDIA_URL = "/media/"
我以多种不同的方式配置了我的 Nginx,但它不适用于 gunicorn。
1.
server {
listen 80 default_server;
server_name *.*.*.*;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
autoindex on;
alias /home/ubuntu/myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/myproject.sock;
}
}
location /static/ {
root /home/ubuntu/myproject;
}
location /myproject/static/ {
root /home/ubuntu;
}
location /myproject/static/ {
alias /home/ubuntu;
}
我不明白为什么会这样。我在 myproject/static
中的静态文件夹。
知道为什么我会收到 404 吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
今天的关于Rails 3.1,Unicorn和Apache:静态文件和gunicorn 静态文件的分享已经结束,谢谢您的关注,如果想了解更多关于Apache Cassandra和Apache Ignite:强一致和事务、Capistrano+Nginx+Unicorn 自动部署Rails、Django Gunicorn无法加载静态文件、Django静态文件未加载gunicorn的相关知识,请在本站进行查询。
本文标签: