- 可以用ssh访问CentOS服务器
- 可以用Sudo或者可以用root账户
- 登录后更新yum包:
yum update
## 使用yum安装Node/NPM ##
--保存nodejs包
curl -sL https://rpm.nodesource.com/setup | bash -
--使用yum安装
yum install -y nodejs
//如果安装失败,那么有可能包未签名导致的,解决方案是在上面的命令后面添加-nogpgcheck
yum install -y nodejs --nogpgcheck
--检查nodejs是否安装成功
# node --version
v0.10.40
# npm --version
1.4.28
## 开始搭建private bower私服 ##
#
*Tips: 和MAVEN私有库一样,如果私服上没有请求的包,服务器会自动转向公共BOWER服务器获取。*
STEP1:安装git和git-daemon
# yum -y install git
# yum install -y git git-daemon
STEP2:安装private-bower
# npm install -g private-bower
STEP3:设置private-bower
# su -
# cd /opt
# mkdir private-bower
# vim myBowerConfig.json
这里如果发现vim没有安装,就请执行如下命令
# yum -y install vim*
配置private-bower
{ "port": 5678, "registryFile": "/opt/private-bower/bowerRepository.json", "timeout": 144000, "public": { "disabled": false, "registry": "http://bower.herokuapp.com/packages", "registryFile": "/opt/private-bower/bowerRepositoryPublic.json", "whitelist": [], "blacklist": [] }, "authentication": { "enabled": false, "key": "password" }, "repositoryCache": { "cachePrivate": true, "git": { "enabled": true, "cacheDirectory": "/opt/private-bower/gitRepoCache", "host": "localhost", "port": 6789, "publicAccessURL" : null, "refreshTimeout": 10 }, "svn": { "enabled": false, "cacheDirectory": "/opt/private-bower/svnRepoCache", "host": "localhost", "port": 7891, "publicAccessURL" : null, "refreshTimeout": 10 } }, "proxySettings" : { "enabled": false, "host": "proxy", "username": "name", "password" : "pass", "port": 8080, "tunnel": false }, "log4js" : { "enabled": true, "configPath" : "/opt/private-bower/log4js.conf.json" } }
编辑log4js.conf
$ vim log4js.conf.json
将以下内容粘贴进去:
{ "appenders": [ { "type": "dateFile", "filename": "private-bower.log", "pattern": "-yyyy-MM-dd", "alwaysIncludePattern": false }, { "type": "console" } ], "replaceConsole": true }
启动private-bower
# cd /opt/private-bower
# private-bower --config ./myBowerConfig.json
## 客户端使用 ##
01) 打开.bowerrc
02) 加入 {"registry":"http://<bow私服ip地址>:5678"}
03) 输入命令bower install jquery 测试使用
## 其他实用命令 ##
01) 清除本地bower缓存
bower cache clean
02) 重启私服
# private-bower --config ./myBowerConfig.json restart
服务配置
安装forever
npm install forever -g
修改启动脚本
#!/bin/bash ### BEGIN INIT INFO # Provides: xiyoulib # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO # chkconfig: 345 88 08 # description: Forever for Node.js DEAMON=/usr/bin/private-bower #这里需要填写你自己的Node项目的启动脚本文件 LOG=/node.js/log/log #可选,日志文件目录 PID=/node.js/pid #必填内容,用于记录forever的进程号 export PATH=$PATH:/usr/bin #在这里指定一下Node的可执行程序安装目录 export NODE_PATH=$NODE_PATH:/usr/lib/node_modules #这里是Node类库的路径 node=node forever=forever case "$1" in start) $forever start -l $LOG --pidFile $PID -a $DEAMON --config /opt/private-bower/myBowerConfig.json ;; stop) $forever stop --pidFile $PID $DEAMON ;; stopall) $forever stopall --pidFile $PID ;; restartall) $forever restartall --pidFile $PID ;; reload|restart) $forever restart -l $LOG --pidFile $PID -a $DEAMON --config /opt/private-bower/myBowerConfig.json ;; list) $forever list ;; *) echo "Usage: /etc.init.d/node {start|stop|restart|reload|stopall|restartall|list}" exit 1 ;; esac
开机启动
chkconfig privateBowerServer on