meteor
记一次Meteor项目部署配置,使用 CentOS + Meteor + React + Mongdb + Nginx
node版本与Meteor依赖一致v0.10.43
自定义服务配置比较麻烦,给出配置文件示例。

环境变量配置参数
/etc/profile

1
2
3
4
5
6
7
8
export PATH=/usr/local/mongodb/bin:$PATH
export MONGO_URL=mongodb://localhost:27017/chat
export ROOT_URL=http://chat.haoduoshipin.com
export PORT=9000
export PATH=/home/vagrant/.nvm/v0.10.43/bin:$PATH
export PATH=/usr/pgsql-9.4/bin/:$PATH
export PATH=/usr/bin:$PATH
export PATH=/usr/include/proj_api.h:$PATH

自定义服务:mongod
/etc/init/mongod.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# upstart service file at /etc/init/mongod.conf

# When to start the service
start on started sshd and runlevel [2345]

# When to stop the service
stop on shutdown

# Automatically restart process if crashed
respawn
respawn limit 10 5

script
export PATH=/usr/local/mongodb/bin:/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
exec mongod >> /home/vagrant/logs/mongod.log
end script

自定义服务:chat
/etc/init/chat.conf

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
# upstart service file at /etc/init/chat.conf

# When to start the service
start on started mongod and runlevel [2345]

# When to stop the service
stop on shutdown

# Automatically restart process if crashed
respawn
respawn limit 10 5

script
export PATH=/home/vagrant/.nvm/v0.10.43/bin:/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# set to home directory of the user Meteor will be running as
export PWD=/home/vagrant
export HOME=/home/vagrant
# leave as 127.0.0.1 for security
export BIND_IP=127.0.0.1
# the port nginx is proxying requests to
export PORT=9000
# this allows Meteor to figure out correct IP address of visitors
export HTTP_FORWARDED_COUNT=1
# MongoDB connection string using meteor as database name
export MONGO_URL=mongodb://localhost:27017/chat
# The domain name as configured previously as server_name in nginx
export ROOT_URL=http://chat.haoduoshipin.com
exec node /home/vagrant/chat/bundle/main.js >> /home/vagrant/chat/chat.log
end script

nginx代理配置
/usr/local/nginx/conf/vhost/chat.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {
listen 80;
server_name chat.com;
location / {
proxy_pass http://localhost:9000;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_x_forwarded_host;
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;
}
}

在CentOS6.5中启动自定义服务

1
$ initctl

启动自定义mongdb服务

1
$ sudo initctl start mongod

启动chat服务

1
$ sudo initctl chat mongod

启动nginx服务

1
$ sudo service nginx start

mongdb使用

1
2
3
4
5
6
7
8
9
10
11
12
$ mongo
> show dbs
chat 0.000GB
local 0.000GB
> use chat
switched to db chat
> show collections
users
.
.
.
> db.users.find()

nginx 代理监听端口9000

外部访问地址http://chat.com:8080