您的位置:首页 > 大数据 > 人工智能

sails框架项目移植

2016-05-30 10:45 501 查看
一个歪果公司开发的项目,然后要移植。。。但是木有任何文档只有参照生产环境来移植,痛苦的开始。。持续了1周才弄了个mongodb的集群。记录下:

mongo编译安装:

下载软件:




wgethttp://downloads.mongodb.org/src/mongodb-src-r2.6.8.tar.gz
wgethttps://sourceforge.net/projects/scons/files/scons/2.5.0/scons-2.5.0.tar.gz
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
wget https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz




安装编译环境:


sudo yum installcurl-devel expat-devel gettext-devel openssl-devel zlib-devel
gcc perl-ExtUtils-MakeMaker gcc+ gcc-c++




安装scons:


tar -zxvf scons-2.1.0.alpha.20101125.tar.gz
cd scons-2.1.0.alpha.20101125
python setup.py install


安装pcre:


tar -zxvf pcre-7.4.tar.gz
cd pcre-7.4
./configure --enable-utf8  
make && make install 



安装 SpiderMonkey:


tar -zxvf js-1.7.0.tar.gz
cd js/src 

export CFLAGS="-DJS_C_STRINGS_ARE_UTF8" 
make -f Makefile.ref
JS_DIST=/usr make -f Makefile.ref export


安装boost:


yum -y install boost boost-devel 


安装mongodb:




tar -zxvf mongodb-src-r2.6.8.tar.gz
cd mongodb-src-r2.6.8
scons all
scons --prefix=/usr/local/mongodb -ngodb-src-r2.6.8


生产环境是四台机器:
3台机器:3个数据库和三个sails框架的应用程序,一台机器:nginx轮询和日志采集


主机 
IP
端口信息
Server1
192.168.100.130
mongod rs1:27017

mongs1:30000

Rsyslog:540
Server2
192.168.100.131
mongod rs2:27017

mongs2:30000

Rsyslog:540
Server3
192.168.100.132
mongod rs3:27017

mongs3:30000

Rsyslog:540
Server4
192.168.100.133
Nginx:80
Rsyslog:540
ntp


三台机器的mongo都完成了安装,然后配置集群(生产上是四个分片四个副本集,但是本人感觉那么多分片和副本集根本没用上,在加上也没弄明白,所以缩减到一个分片一个副本集)


mongo集群搭建:
首先,在130,131,133上创建文件夹(*代表1,2,3)

         mkdir-p /mnt/lib/mongodb.rs*
         mkdir-p /mnt/lib/mongod-configdb
 

 

分别在三台机器上无验证启动mongo

cd /usr/local/mongodb/bin/

         ./mongod--replSet rs1 --port 27017 --dbpath /mnt/lib/mongodb.rs1 --syslog --syslogFacilitylocal1& --keyFile /root/mongodb.key &
 

         ./mongod--replSet rs1 --port 27017 --dbpath /mnt/lib/mongodb.rs2 --syslog--syslogFacility local1& --keyFile /root/mongodb.key &
 

         ./mongod--replSet rs1 --port 27017 --dbpath /mnt/lib/mongodb.rs3 --syslog--syslogFacility local1& --keyFile /root/mongodb.key &
 

 

启动正常后连接其中一台mongo

./mongo

 

执行

rsconf={_id:"rs1",members:[{_id:0,host:"192.168.100.130:27017"},{_id:1,host:"192.168.100.131:27017"},{_id:2,host:"192.168.100.132:27017"}]}
 

rs.initiate(rsconf)
 

三台机器分别执行启动配置命令

sudo ./mongod --configsvr --dbpath/mnt/lib/mongod-configdb --port 20000 --syslog --syslogFacility local2--keyFile /root/mongodb.key &
 
 
sudo ./mongos --syslog --syslogFacility local3 --configdb192.168.100.130:20000,192.168.100.131:20000,192.168.100.132:20000 --port 30000--keyFile /root/mongodb.key &
<
4000
u> [/u]
 

 

 

执行命令登录

./mongo 192.168.100.130:30000/admin
 
 
创建副本集
db.runCommand({addshard:"rs1/192.168.100.130:27017,192.168.100.131:27017,192.168.100.132:27017",name:"s1"});  
 

 

 

创建用户

 
use admin
 
db.createUser({user:"admin",pwd:"admin",roles:[{"role":"userAdminAnyDatabase","db":"admin"}]})
 
db.createUser({user:"root",pwd:"root",roles:[{"role":"root","db":"admin"}]})


集群就完成了,可以用rs.status()查看下集群配置
rs1:SECONDARY> rs.status()

{

"set" : "rs1",

"date" : ISODate("2016-05-30T02:28:27.441Z"),

"myState" : 2,

"term" : NumberLong(9),

"syncingTo" : "192.168.100.131:27017",

"heartbeatIntervalMillis" : NumberLong(2000),

"members" : [

{

"_id" : 0,

"name" : "192.168.100.130:27017",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 242459,

"optime" : {

"ts" : Timestamp(1464572049, 8),

"t" : NumberLong(9)

},

"optimeDate" : ISODate("2016-05-30T01:34:09Z"),

"syncingTo" : "192.168.100.131:27017",

"configVersion" : 3,

"self" : true

},

{

"_id" : 1,

"name" : "192.168.100.131:27017",

"health" : 1,

"state" : 1,

"stateStr" : "PRIMARY",

"uptime" : 242433,

"optime" : {

"ts" : Timestamp(1464572049, 8),

"t" : NumberLong(9)

},

"optimeDate" : ISODate("2016-05-30T01:34:09Z"),

"lastHeartbeat" : ISODate("2016-05-30T02:28:25.935Z"),

"lastHeartbeatRecv" : ISODate("2016-05-30T02:28:25.644Z"),

"pingMs" : NumberLong(0),

"electionTime" : Timestamp(1464332879, 1),

"electionDate" : ISODate("2016-05-27T07:07:59Z"),

"configVersion" : 3

},

{

"_id" : 2,

"name" : "192.168.100.132:27017",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 242428,

"optime" : {

"ts" : Timestamp(1464572049, 8),

"t" : NumberLong(9)

},

"optimeDate" : ISODate("2016-05-30T01:34:09Z"),

"lastHeartbeat" : ISODate("2016-05-30T02:28:26.083Z"),

"lastHeartbeatRecv" : ISODate("2016-05-30T02:28:27.184Z"),

"pingMs" : NumberLong(0),

"syncingTo" : "192.168.100.130:27017",

"configVersion" : 3

}

],

"ok" : 1

}



mongo数据备份还原:
./mongodump -h IP --port27017 -u
user-p passwd -database-o /root/


./mongorestore -h IP--port 30000 -d
database --drop /root/xxxx/


 





安装应用程序环境:

 
node编译安装:
上传node-v0.12.7.tar.gz到服务器根目录
tar –zxvf node-v0.12.7.tar.gz
cdnode-v0.12.7
./configure
make
make install
cp /usr/local/bin/node /usr/sbin/



sails安装:
npm -g install sails


rsyslog客户端配置文件修改:


[root@nodejstest1 bin]# cat /etc/rsyslog.conf

#  /etc/rsyslog.conf    Configuration file for rsyslog.

#

#            For more information see

#            /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html

#

#  Default logging rules can be found in /etc/rsyslog.d/50-default.conf

#################

#### MODULES ####

#################

$ModLoad imuxsock # provides support for local system logging

$ModLoad imklog   # provides kernel logging support

#$ModLoad immark  # provides --MARK-- message capability

# provides UDP syslog reception

$ModLoad imudp

$UDPServerRun 514

# provides TCP syslog reception

#$ModLoad imtcp

#$InputTCPServerRun 514

###########################

#### GLOBAL DIRECTIVES ####

###########################

#

# Use traditional timestamp format.

# To enable high precision timestamps, comment out the following line.

#

$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Filter duplicated messages

$RepeatedMsgReduction on

#

# Set the default permissions for all log files.

#

$FileOwner syslog

$FileGroup adm

$FileCreateMode 0640

$DirCreateMode 0755

$Umask 0022

$PrivDropToUser syslog

$PrivDropToGroup syslog

# ### begin forwarding rule ###

# The statement between the begin ... end define a SINGLE forwarding

# rule. They belong together, do NOT split them. If you create multiple

# forwarding rules, duplicate the whole block!

# Remote Logging (we use TCP for reliable delivery)

#

# An on-disk queue is created for this action. If the remote host is

# down, messages are spooled to disk and sent when it is up again.

$WorkDirectory /var/lib/rsyslog # where to place spool files

$ActionQueueFileName fwdRule1 # unique name prefix for spool files

$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)

$ActionQueueSaveOnShutdown on # save messages to disk on shutdown

$ActionQueueType LinkedList   # run asynchronously

$ActionResumeRetryCount -1    # infinite retries if host is down

# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional

local0.* @@192.168.100.133:514

local1.* @@192.168.100.133:514

local2.* @@192.168.100.133:514

local3.* @@192.168.100.133:514

# ### end of the forwarding rule ###

#

# Include all config files in /etc/rsyslog.d/

#

$IncludeConfig /etc/rsyslog.d/*.conf


[root@nodejstest1 rsyslog.d]# cat /etc/rsyslog.d/20-ufw.conf
# Log kernel generated UFW log messages to file

:msg,contains,"[UFW " /var/log/ufw.log

# Uncomment the following to stop logging anything that matches the last rule.

# Doing this will stop logging kernel generated UFW log messages to the file

# normally containing kern.* messages (eg, /var/log/kern.log)

#& ~


[root@nodejstest1 rsyslog.d]# cat /etc/rsyslog.d/50-default.conf
#  Default rules for rsyslog.

#

#            For more information see rsyslog.conf(5) and /etc/rsyslog.conf

#

# First some standard log files.  Log by facility.

#

auth,authpriv.*            /var/log/auth.log

*.*;auth,authpriv.none        -/var/log/syslog

#cron.*                /var/log/cron.log

#daemon.*            -/var/log/daemon.log

kern.*                -/var/log/kern.log

#lpr.*                -/var/log/lpr.log

mail.*                -/var/log/mail.log

#user.*                -/var/log/user.log

#

# Logging for the mail system.  Split it up so that

# it is easy to write scripts to parse these files.

#

#mail.info            -/var/log/mail.info

#mail.warn            -/var/log/mail.warn

mail.err            /var/log/mail.err

#

# Logging for INN news system.

#

news.crit            /var/log/news/news.crit

news.err            /var/log/news/news.err

news.notice            -/var/log/news/news.notice

#

# Some "catch-all" log files.

#

#*.=debug;\

#    auth,authpriv.none;\

#    news.none;mail.none    -/var/log/debug

#*.=info;*.=notice;*.=warn;\

#    auth,authpriv.none;\

#    cron,daemon.none;\

#    mail,news.none        -/var/log/messages

#

# Emergencies are sent to everybody logged in.

#

*.emerg                                :omusrmsg:*

#

# I like to have messages displayed on the console, but only on a virtual

# console I usually leave idle.

#

#daemon,mail.*;\

#    news.=crit;news.=err;news.=notice;\

#    *.=debug;*.=info;\

#    *.=notice;*.=warn    /dev/tty8

# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,

# you must invoke `xconsole' with the `-file' option:

#

#    $ xconsole -file /dev/xconsole [...]

#

# NOTE: adjust the list below, or you'll go crazy if you have a reasonably

#      busy site..

#

daemon.*;mail.*;\

    news.err;\

    *.=debug;*.=info;\

    *.=notice;*.=warn    |/dev/xconsole



然后上传应用,使用脚本启动。


rsyslog服务端配置文件修改:
[root@nodejstest4 ~]# cat /etc/rsyslog.conf
# rsyslog v5 configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html

# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####

$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)

$ModLoad imklog   # provides kernel logging support (previously done by rklogd)

#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception

$ModLoad imudp

$UDPServerRun 514

# Provides TCP syslog reception

$ModLoad imtcp

$InputTCPServerRun 514

#### GLOBAL DIRECTIVES ####

# Use default timestamp format

$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,

# not useful and an extreme performance hit

#$ActionFileEnableSync on

# Filter duplicated messages

$RepeatedMsgReduction on

$template DynFileS,"/mnt/log/%$NOW%/mongos.log"

$template DynFileD,"/mnt/log/%$NOW%/mongod.log"

$template DynFileC,"/mnt/log/%$NOW%/mongod-config.log"

$template DynFileE,"/mnt/log/%$NOW%/eduapi.log"

#### RULES ####

# Log all kernel messages to the console.

# Logging much else clutters up the screen.

# kern.*                                                 /dev/console

# Log anything (except mail) of level info or higher.

# Don't log private authentication messages!

#*.info;mail.none;authpriv.none;cron.none                /var/log/messages

# The authpriv file has restricted access.

#authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.

#mail.*                                                  -/var/log/maillog

# Log cron stuff

#cron.*                                                  /var/log/cron

# Everybody gets emergency messages

#*.emerg                                                 *

# Save news errors of level crit and higher in a special file.

#uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log

#local7.*                                                /var/log/boot.log

#local0.*                                                /mnt/log/eduapi.log

local0.*                                                 -?DynFileE

#local1.*                                                /mnt/log/mongod.log

local1.*                                                 -?DynFileD

#local2.*                                                /mnt/log/mongod-config.log

local2.*                                                 -?DynFileC

#local3.*                                                /mnt/log/mongos.log

local3.*                                                 -?DynFileS

# ### begin forwarding rule ###

# The statement between the begin ... end define a SINGLE forwarding

# rule. They belong together, do NOT split them. If you create multiple

# forwarding rules, duplicate the whole block!

# Remote Logging (we use TCP for reliable delivery)

#

# An on-disk queue is created for this action. If the remote host is

# down, messages are spooled to disk and sent when it is up again.

#$WorkDirectory /var/lib/rsyslog # where to place spool files

#$ActionQueueFileName fwdRule1 # unique name prefix for spool files

#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)

#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown

#$ActionQueueType LinkedList   # run asynchronously

#$ActionResumeRetryCount -1    # infinite retries if host is down

# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional

#*.* @@remote-host:514

# ### end of the forwarding rule ###

# Finally include all config files in /etc/rsyslog.d. This allows overrides

# of the default configuration above.

$IncludeConfig /etc/rsyslog.d/*.conf



[root@nodejstest4 ~]# cat /etc/rsyslog.d/20-ufw.conf
# Log kernel generated UFW log messages to file

:msg,contains,"[UFW " /var/log/ufw.log

# Uncomment the following to stop logging anything that matches the last rule.

# Doing this will stop logging kernel generated UFW log messages to the file

# normally containing kern.* messages (eg, /var/log/kern.log)

#& ~


[root@nodejstest4 ~]# cat /etc/rsyslog.d/50-default.
b2e2
conf
#  Default rules for rsyslog.

#

#            For more information see rsyslog.conf(5) and /etc/rsyslog.conf

#

# First some standard log files.  Log by facility.

#

auth,authpriv.*            /var/log/auth.log

*.*;auth,authpriv.none        -/var/log/syslog

#cron.*                /var/log/cron.log

#daemon.*            -/var/log/daemon.log

kern.*                -/var/log/kern.log

#lpr.*                -/var/log/lpr.log

mail.*                -/var/log/mail.log

#user.*                -/var/log/user.log

#

# Logging for the mail system.  Split it up so that

# it is easy to write scripts to parse these files.

#

#mail.info            -/var/log/mail.info

#mail.warn            -/var/log/mail.warn

mail.err            /var/log/mail.err

#

# Logging for INN news system.

#

news.crit            /var/log/news/news.crit

news.err            /var/log/news/news.err

news.notice            -/var/log/news/news.notice

#

# Some "catch-all" log files.

#

#*.=debug;\

#    auth,authpriv.none;\

#    news.none;mail.none    -/var/log/debug

#*.=info;*.=notice;*.=warn;\

#    auth,authpriv.none;\

#    cron,daemon.none;\

#    mail,news.none        -/var/log/messages

#

# Emergencies are sent to everybody logged in.

#

*.emerg                                :omusrmsg:*

#

# I like to have messages displayed on the console, but only on a virtual

# console I usually leave idle.

#

#daemon,mail.*;\

#    news.=crit;news.=err;news.=notice;\

#    *.=debug;*.=info;\

#    *.=notice;*.=warn    /dev/tty8

# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,

# you must invoke `xconsole' with the `-file' option:

#

#    $ xconsole -file /dev/xconsole [...]

#

# NOTE: adjust the list below, or you'll go crazy if you have a reasonably

#      busy site..

#

daemon.*;mail.*;\

    news.err;\

    *.=debug;*.=info;\

    *.=notice;*.=warn    |/dev/xconsole



nginx服务端配置文件:
[root@nodejstest4 ~]# cat /usr/local/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;

    upstream qhfzProxy {

        server 192.168.100.130:80;

        server 192.168.100.131:80;

    server 192.168.100.132:80;

    }

    server {

        listen       80;

        server_name  test2.edu.com.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

              proxy_pass http://qhfzProxy;
            

        }

        #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   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;
        #}

        # 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;

        #}

    }

    # 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;

    #    }

    #}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: