jackieli123723 / jackieli123723.github.io

✅lilidong 个人博客
9 stars 0 forks source link

centos7 上安装node集成环境 #47

Open jackieli123723 opened 6 years ago

jackieli123723 commented 6 years ago

安装过程

进入home目录

[root@lilidong /home]# ll
total 0
[root@lilidong /home]# ls
[root@lilidong /home]# mkdir worker
[root@lilidong /home]# ll
total 0
drwxr-xr-x 2 root root 6 Jan 30 10:26 worker
[root@lilidong /home]# ll
total 0
[root@lilidong /home/worker]# wget https://npm.taobao.org/mirrors/node/v8.0.0/node-v8.0.0-linux-x64.tar.xz

[root@lilidong /home/worker]# ll
total 11040
drwxrwxr-x 6  500  500      108 May 30  2017 node-v8.0.0-linux-x64
-rw-r--r-- 1 root root 11302412 May 30  2017 node-v8.0.0-linux-x64.tar.xz
[root@lilidong /home/worker]# cd  node-v8.0.0-linux-x64/bin && ls
node  npm
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# node -v
bash: node: command not found
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ./node -v
v8.0.0
//现在是当前目录有node环境
//现在 node 和 npm 还不能全局使用,做个链接
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# pwd
/home/worker/node-v8.0.0-linux-x64/bin
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]#

软连接

 ln -s  /home/worker/node-v8.0.0-linux-x64/bin/node /usr/local/bin/node
 ln -s  /home/worker/node-v8.0.0-linux-x64/bin/npm /usr/local/bin/npm

---
[root@lilidong /usr/local]# cd bin/
[root@lilidong /usr/local/bin]# ll
total 0
lrwxrwxrwx 1 root root 35 Jan 30 10:28 node -> /www/node-v8.0.0-linux-x64/bin/node
lrwxrwxrwx 1 root root 34 Jan 30 10:28 npm -> /www/node-v8.0.0-linux-x64/bin/npm
[root@lilidong /usr/local/bin]# rm -rf node
[root@lilidong /usr/local/bin]# ll
total 0
lrwxrwxrwx 1 root root 34 Jan 30 10:28 npm -> /www/node-v8.0.0-linux-x64/bin/npm
[root@lilidong /usr/local/bin]# rm -rf npm
[root@lilidong /usr/local/bin]# ll
total 0
[root@lilidong /usr/local/bin]#  ln -s  /home/worker/node-v8.0.0-linux-x64/bin/node /usr/local/bin/node
[root@lilidong /usr/local/bin]# ll
total 0
lrwxrwxrwx 1 root root 43 Jan 30 10:35 node -> /home/worker/node-v8.0.0-linux-x64/bin/node
[root@lilidong /usr/local/bin]# ln -s  /home/worker/node-v8.0.0-linux-x64/bin/npm /usr/local/bin/npm
[root@lilidong /usr/local/bin]# ll
total 0
lrwxrwxrwx 1 root root 43 Jan 30 10:35 node -> /home/worker/node-v8.0.0-linux-x64/bin/node
lrwxrwxrwx 1 root root 42 Jan 30 10:35 npm -> /home/worker/node-v8.0.0-linux-x64/bin/npm
[root@lilidong /usr/local/bin]# node -v
v8.0.0
[root@lilidong /usr/local/bin]# npm -v
5.0.0
[root@lilidong /usr/local/bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[root@lilidong /usr/local/bin]#

注意所有node安装的模块都要软连接不然会报错

[root@lilidong /home/worker]# pm2 list
bash: pm2: command not found

解决办法npm 安装的所有模块都要软连接

[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# pwd
/home/worker/node-v8.0.0-linux-x64/bin
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ls -l
total 35328
lrwxrwxrwx 1 root root       27 Jan 30 10:49 n -> ../lib/node_modules/n/bin/n
-rwxrwxr-x 1  500  500 36174728 May 30  2017 node
lrwxrwxrwx 1  500  500       38 May 30  2017 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 root root       31 Jan 30 11:26 pm2 -> ../lib/node_modules/pm2/bin/pm2
lrwxrwxrwx 1 root root       35 Jan 30 11:26 pm2-dev -> ../lib/node_modules/pm2/bin/pm2-dev
lrwxrwxrwx 1 root root       38 Jan 30 11:26 pm2-docker -> ../lib/node_modules/pm2/bin/pm2-docker
lrwxrwxrwx 1 root root       39 Jan 30 11:26 pm2-runtime -> ../lib/node_modules/pm2/bin/pm2-runtime
lrwxrwxrwx 1 root root       33 Jan 30 10:41 rimraf -> ../lib/node_modules/rimraf/bin.js
lrwxrwxrwx 1 root root       35 Jan 30 10:41 ssr -> ../lib/node_modules/ssr/.bin/ssr.js
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ll
total 35328
lrwxrwxrwx 1 root root       27 Jan 30 10:49 n -> ../lib/node_modules/n/bin/n
-rwxrwxr-x 1  500  500 36174728 May 30  2017 node
lrwxrwxrwx 1  500  500       38 May 30  2017 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 root root       31 Jan 30 11:26 pm2 -> ../lib/node_modules/pm2/bin/pm2
lrwxrwxrwx 1 root root       35 Jan 30 11:26 pm2-dev -> ../lib/node_modules/pm2/bin/pm2-dev
lrwxrwxrwx 1 root root       38 Jan 30 11:26 pm2-docker -> ../lib/node_modules/pm2/bin/pm2-docker
lrwxrwxrwx 1 root root       39 Jan 30 11:26 pm2-runtime -> ../lib/node_modules/pm2/bin/pm2-runtime
lrwxrwxrwx 1 root root       33 Jan 30 10:41 rimraf -> ../lib/node_modules/rimraf/bin.js
lrwxrwxrwx 1 root root       35 Jan 30 10:41 ssr -> ../lib/node_modules/ssr/.bin/ssr.js
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# cd node
bash: cd: node: Not a directory
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ln -s  /home/worker/node-v8.0.0-linux-x64/bin/pm2 /usr/local/bin/pm2
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# pm2 list

                        -------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
 _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
  _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
   _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
    _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
     _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
      _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
       _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
        _\///______________\///______________\///__\///////////////__

                          Community Edition

            Production Process Manager for Node.js applications
                     with a built-in Load Balancer.

                Start and Daemonize any application:
                $ pm2 start app.js

                Load Balance 4 instances of api.js:
                $ pm2 start api.js -i 4

                Monitor in production:
                $ pm2 monitor

                Make pm2 auto-boot at server restart:
                $ pm2 startup

                To go further checkout:
                http://pm2.io/

                        -------------

[PM2] Spawning PM2 daemon with pm2_home=/.pm2
[PM2] PM2 Successfully daemonized
┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
└──────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# pm2 -version
2.9.3
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]#

[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ssr -v
bash: ssr: command not found
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ll
total 35328
lrwxrwxrwx 1 root root       27 Jan 30 10:49 n -> ../lib/node_modules/n/bin/n
-rwxrwxr-x 1  500  500 36174728 May 30  2017 node
lrwxrwxrwx 1  500  500       38 May 30  2017 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxrwxrwx 1 root root       31 Jan 30 11:26 pm2 -> ../lib/node_modules/pm2/bin/pm2
lrwxrwxrwx 1 root root       35 Jan 30 11:26 pm2-dev -> ../lib/node_modules/pm2/bin/pm2-dev
lrwxrwxrwx 1 root root       38 Jan 30 11:26 pm2-docker -> ../lib/node_modules/pm2/bin/pm2-docker
lrwxrwxrwx 1 root root       39 Jan 30 11:26 pm2-runtime -> ../lib/node_modules/pm2/bin/pm2-runtime
lrwxrwxrwx 1 root root       33 Jan 30 10:41 rimraf -> ../lib/node_modules/rimraf/bin.js
lrwxrwxrwx 1 root root       35 Jan 30 10:41 ssr -> ../lib/node_modules/ssr/.bin/ssr.js
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ln -s  /home/worker/node-v8.0.0-linux-x64/bin/ssr /usr/local/bin/ssr
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ssr -cp 2010

  Static file server running at

=> http://localhost:2010

^C
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ln -s  /home/worker/node-v8.0.0-linux-x64/bin/rimraf /usr/local/bin/rimraf
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# rimraf -v
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# rimraf -h
Usage: rimraf <path> [<path> ...]

  Deletes all files and folders at "path" recursively.

Options:

  -h, --help     Display this usage info
  -G, --no-glob  Do not expand glob patterns in arguments
  -g, --glob     Expand glob patterns in arguments (default)
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# ln -s  /home/worker/node-v8.0.0-linux-x64/bin/n /usr/local/bin/n
[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# n -v

  Error: invalid version -v

[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# n --h

  Error: invalid version --h

[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# npm list
/home/worker/node-v8.0.0-linux-x64/bin
`-- (empty)

[root@lilidong /home/worker/node-v8.0.0-linux-x64/bin]# n stable

     install : node-v9.4.0
       mkdir : /usr/local/n/versions/node/9.4.0
       fetch : https://nodejs.org/dist/v9.4.0/node-v9.4.0-linux-x64.tar.gz
#################################################                         68.1%

n模块切换node

[root@lilidong /home]# n

[root@lilidong /home]# node -v
v8.1.4
[root@lilidong /home]# npm -v
5.0.3
[root@lilidong /home]# n

[root@lilidong /home]# n 6.0.0

     install : node-v6.0.0
       mkdir : /usr/local/n/versions/node/6.0.0
       fetch : https://nodejs.org/dist/v6.0.0/node-v6.0.0-linux-x64.tar.gz
######################################################################## 100.0%
/usr/local/bin/n: line 263: which: command not found
/usr/local/bin/n: line 263: which: command not found
   installed : v6.0.0

[root@lilidong /home]# node -v
v6.0.0
[root@lilidong /home]# n

[root@lilidong /home]# n 9.2.0

     install : node-v9.2.0
       mkdir : /usr/local/n/versions/node/9.2.0
       fetch : https://nodejs.org/dist/v9.2.0/node-v9.2.0-linux-x64.tar.gz
######################################################################## 100.0%
/usr/local/bin/n: line 263: which: command not found
/usr/local/bin/n: line 263: which: command not found
   installed : v9.2.0

[root@lilidong /home]# node -v
v9.2.0
[root@lilidong /home]# npm -v
5.5.1
[root@lilidong /home]# npx -v
9.6.0
[root@lilidong /home]#

安装git环境

1、下载编译工具

yum -y group install "Development Tools"

2、下载依赖包

yum -y install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel

3、下载 git 最新版本的源代码

wget https://www.kernel.org/pub/software/scm/git/git-2.11.0.tar.gz

4、解压

tar -zxvf git-2.11.0.tar.gz

5、进入目录配置

./configure --prefix=/usr/local/git

6、安装

make && make install

7、配置全局路径(可自行添加)

export PATH="/usr/local/git/bin:$PATH"

source /etc/profile

[root@lilidong /home/worker/git-2.11.0]# cd ../ [root@lilidong /home/worker]# ll total 17148 drwxrwxr-x 22 root root 12288 Jan 31 02:48 git-2.11.0 -rw-r--r-- 1 root root 6234127 Nov 29 2016 git-2.11.0.tar.gz drwxrwxr-x 7 500 500 119 Jan 30 10:41 node-v8.0.0-linux-x64 -rw-r--r-- 1 root root 11302412 May 30 2017 node-v8.0.0-linux-x64.tar.xz drwxr-xr-x 2 root root 6 Jan 30 10:42 website [root@lilidong /home/worker]# cd website/ [root@lilidong /home/worker/website]# ll total 0 [root@lilidong /home/worker/website]# git clone https://github.com/jackieli123723/vue-longyuan-store-front.git Cloning into 'vue-longyuan-store-front'... remote: Counting objects: 1822, done. remote: Compressing objects: 100% (47/47), done. remote: Total 1822 (delta 24), reused 47 (delta 11), pack-reused 1747 Receiving objects: 100% (1822/1822), 24.45 MiB | 747.00 KiB/s, done. Resolving deltas: 100% (912/912), done. [root@lilidong /home/worker/website]# [root@lilidong /home/worker/website]# git -v Unknown option: -v usage: git [--version] [--help] [-c name=value] [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] [] [root@lilidong /home/worker/website]# git --version git version 1.8.3.1 [root@lilidong /home/worker/website]#

npm版本锁定删除后安装node不符合锁定版本

npm WARN tar ENOENT: no such file or directory, lstat '/home/worker/website/vue-longyuan-store-front/node_modules/.staging/vue-resource-715fd265/test/data'
npm WARN tar ENOENT: no such file or directory, lstat '/home/worker/website/vue-longyuan-store-front/node_modules/.staging/vue-resource-715fd265/test/data'
npm WARN tar ENOENT: no such file or directory, lstat '/home/worker/website/vue-longyuan-store-front/node_modules/.staging/vue-resource-715fd265/test/data'
npm WARN tar ENOENT: no such file or directory, open '/home/worker/website/vue-longyuan-store-front/node_modules/.staging/vue-resource-715fd265/test/index.html'
npm WARN The package express is included as both a dev and production dependency.

npm ERR! path /home/worker/website/vue-longyuan-store-front/node_modules/.staging/koa-compress-8b66c0ff/node_modules/bytes
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/home/worker/website/vue-longyuan-store-front/node_modules/.staging/koa-compress-8b66c0ff/node_modules/bytes' -> '/home/worker/website/vue-longyuan-store-front/node_modules/.staging/bytes-ab7eac85'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /.npm/_logs/2018-01-31T02_54_35_390Z-debug.log
[root@lilidong /home/worker/website/vue-longyuan-store-front]# npm -v
5.5.1
[root@lilidong /home/worker/website/vue-longyuan-store-front]# n

[root@lilidong /home/worker/website/vue-longyuan-store-front]# ll
total 3680
-rw-r--r--  1 root root    1044 Jan 31 02:50 README.md
drwxr-xr-x  2 root root      82 Jan 31 02:50 auto-deploy
drwxr-xr-x  2 root root     163 Jan 31 02:50 build
drwxr-xr-x  2 root root      78 Jan 31 02:50 config
drwxr-xr-x  4 root root      30 Jan 31 02:50 crawler
-rw-r--r--  1 root root    4004 Jan 31 02:50 deploy.js
-rw-r--r--  1 root root   12022 Jan 31 02:50 index.html
-rw-r--r--  1 root root    1254 Jan 31 02:50 koa-deploy.js
-rw-r--r--  1 root root    1119 Jan 31 02:50 license
drwxr-xr-x  2 root root      24 Jan 31 02:50 logconfig
drwxr-xr-x  2 root root      64 Jan 31 02:50 mock
drwxr-xr-x  2 root root       6 Jan 31 02:54 node_modules
-rw-r--r--  1 root root  509590 Jan 31 02:50 npm-shrinkwrap.json
-rw-r--r--  1 root root    3653 Jan 31 02:50 package.json
-rw-r--r--  1 root root     549 Jan 31 02:50 pm2.json
drwxr-xr-x  2 root root      56 Jan 31 02:50 route
-rw-r--r--  1 root root      62 Jan 31 02:50 run-build.sh
-rw-r--r--  1 root root    2154 Jan 31 02:50 server.js
drwxr-xr-x 12 root root     171 Jan 31 02:50 src
drwxr-xr-x  3 root root     202 Jan 31 02:50 static
drwxr-xr-x  4 root root      29 Jan 31 02:50 test
-rw-r--r--  1 root root 1497223 Jan 31 02:50 vue-longyuan-mall-aliyun.sql
-rw-r--r--  1 root root 1496064 Jan 31 02:50 vue-longyuan-mall.sql
-rw-r--r--  1 root root  210625 Jan 31 02:50 yarn.lock
[root@lilidong /home/worker/website/vue-longyuan-store-front]# rimraf npm-shrinkwrap.json
[root@lilidong /home/worker/website/vue-longyuan-store-front]# npm install
npm WARN deprecated babel-preset-es2015@6.24.1: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm WARN deprecated isparta-loader@2.0.0: Package is deprecated, use https://github.com/deepsweet/istanbul-instrumenter-loader
npm WARN deprecated nodemailer@2.7.2: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
npm WARN deprecated native-or-bluebird@1.2.0: 'native-or-bluebird' is deprecated. Please use 'any-promise' instead.
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead

安装nginx

安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。

一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

yum install gcc-c++
二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

yum install -y pcre pcre-devel
三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

yum install -y zlib zlib-devel
四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

yum install -y openssl openssl-devel

五、下载包
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

依然是直接命令:

tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
配置
其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置

./configure

编译安装
make && make install
查找安装路径:

whereis nginx

make[1]: Leaving directory `/home/worker/nginx-1.10.1'
[root@lilidong /home/worker/nginx-1.10.1]# whereis nginx
nginx: /usr/local/nginx
[root@lilidong /home/worker/nginx-1.10.1]#

cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

查询nginx进程:

ps aux|grep nginx
重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:

./nginx -s quit
./nginx
2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload

开机自启动
即在rc.local增加启动代码就可以了。

vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:

chmod 755 rc.local

[root@lilidong /usr/local/nginx/conf]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

安装forever

[root@lilidong /home/worker/website/nodejs-getting-started]# npm install forever -g
/usr/local/bin/forever -> /usr/local/lib/node_modules/forever/bin/forever

> fsevents@1.1.3 install /usr/local/lib/node_modules/forever/node_modules/fsevents
> node install

+ forever@0.15.3
added 236 packages in 23.83s

[root@lilidong /home/worker/website/nodejs-getting-started]# forever -v
help:    usage: forever [action] [options] SCRIPT [script-options]
help:
help:    Monitors the script specified in the current process or as a daemon
help:
help:    actions:
help:      start               Start SCRIPT as a daemon
help:      stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
help:      stopall             Stop all running forever scripts
help:      restart             Restart the daemon SCRIPT
help:      restartall          Restart all running forever scripts
help:      list                List all running forever scripts
help:      config              Lists all forever user configuration
help:      set <key> <val>     Sets the specified forever config <key>
help:      clear <key>         Clears the specified forever config <key>
help:      logs                Lists log files for all forever processes
help:      logs <script|index> Tails the logs for <script|index>
help:      columns add <col>   Adds the specified column to the output in `forever list`
help:      columns rm <col>    Removed the specified column from the output in `forever list`
help:      columns set <cols>  Set all columns for the output in `forever list`
help:      columns reset       Resets all columns to defaults for the output in `forever list`
help:      cleanlogs           [CAREFUL] Deletes all historical forever log files
help:
help:    options:
help:      -m  MAX          Only run the specified script MAX times
help:      -l  LOGFILE      Logs the forever output to LOGFILE
help:      -o  OUTFILE      Logs stdout from child script to OUTFILE
help:      -e  ERRFILE      Logs stderr from child script to ERRFILE
help:      -p  PATH         Base path for all forever related files (pid files, etc.)
help:      -c  COMMAND      COMMAND to execute (defaults to node)
help:      -a, --append     Append logs
help:      -f, --fifo       Stream logs to stdout
help:      -n, --number     Number of log lines to print
help:      --pidFile        The pid file
help:      --uid            Process uid, useful as a namespace for processes (must wrap in a string)
help:                       e.g. forever start --uid "production" app.js
help:                           forever stop production
help:      --sourceDir      The source directory for which SCRIPT is relative to
help:      --workingDir     The working directory in which SCRIPT will execute
help:      --minUptime      Minimum uptime (millis) for a script to not be considered "spinning"
help:      --spinSleepTime  Time to wait (millis) between launches of a spinning script.
help:      --colors         --no-colors will disable output coloring
help:      --plain          alias of --no-colors
help:      -d, --debug      Forces forever to log debug output
help:      -v, --verbose    Turns on the verbose messages from Forever
help:      -s, --silent     Run the child script silencing stdout and stderr
help:      -w, --watch      Watch for file changes
help:      --watchDirectory Top-level directory to watch from
help:      --watchIgnore    To ignore pattern when watch is enabled (multiple option is allowed)
help:      -t, --killTree   Kills the entire child process tree on `stop`
help:      --killSignal     Support exit signal customization (default is SIGKILL)
help:                       used for restarting script gracefully e.g. --killSignal=SIGTERM
help:      -h, --help       You're staring at it
help:
help:    [Long Running Process]
help:      The forever process will continue to run outputting log messages to the console.
help:      ex. forever -o out.log -e err.log my-script.js
help:
help:    [Daemon]
help:      The forever process will run as a daemon which will make the target process start
help:      in the background. This is extremely useful for remote starting simple node.js scripts
help:      without using nohup. It is recommended to run start with -o -l, & -e.
help:      ex. forever start -l forever.log -o out.log -e err.log my-daemon.js
help:          forever stop my-daemon.js
help:
[root@lilidong /home/worker/website/nodejs-getting-started]#
[root@lilidong /home/worker/website/nodejs-getting-started]# forever start index.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: index.js
[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    Forever processes running
data:        uid  command             script   forever pid   id logfile            uptime
data:    [0] kH1Z /usr/local/bin/node index.js 23565   23571    /.forever/kH1Z.log 0:0:1:53.367
[root@lilidong /home/worker/website/nodejs-getting-started]#
[root@lilidong /home/worker/website/nodejs-getting-started]# npm install forever-monitor

> fsevents@1.1.3 install /home/worker/website/nodejs-getting-started/node_modules/fsevents
> node install

+ forever-monitor@1.7.1
added 204 packages in 19.483s
[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    Forever processes running
data:        uid  command             script   forever pid   id logfile            uptime
data:    [0] kH1Z /usr/local/bin/node index.js 23565   23571    /.forever/kH1Z.log 0:0:2:56.7
[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    Forever processes running
data:        uid  command             script   forever pid   id logfile            uptime
data:    [0] kH1Z /usr/local/bin/node index.js 23565   23571    /.forever/kH1Z.log 0:0:3:9.375
[root@lilidong /home/worker/website/nodejs-getting-started]# forever stop 0
info:    Forever stopped process:
    uid  command             script   forever pid   id logfile            uptime
[0] kH1Z /usr/local/bin/node index.js 23565   23571    /.forever/kH1Z.log 0:0:3:29.888
[root@lilidong /home/worker/website/nodejs-getting-started]# forever restart 0
error:   Error restarting process: 0
error:   Cannot find forever process: 0
[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    No forever processes running
[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    No forever processes running
[root@lilidong /home/worker/website/nodejs-getting-started]# forever start index.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: index.js
[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    Forever processes running
data:        uid  command             script   forever pid   id logfile            uptime
data:    [0] GkP7 /usr/local/bin/node index.js 23793   23799    /.forever/GkP7.log 0:0:0:7.710
[root@lilidong /home/worker/website/nodejs-getting-started]#

[root@lilidong /home/worker/website/nodejs-getting-started]# forever list
info:    Forever processes running
data:        uid  command             script   forever pid   id logfile            uptime
data:    [0] GkP7 /usr/local/bin/node index.js 23793   23799    /.forever/GkP7.log 0:0:0:7.710
[root@lilidong /home/worker/website/nodejs-getting-started]# pm2 list
┌──────────┬────┬──────┬─────┬─────────┬─────────┬────────┬─────┬────────┬──────┬──────────┐
│ App name │ id │ mode │ pid │ status  │ restart │ uptime │ cpu │ mem    │ user │ watching │
├──────────┼────┼──────┼─────┼─────────┼─────────┼────────┼─────┼────────┼──────┼──────────┤
│ demo     │ 0  │ fork │ 0   │ stopped │ 0       │ 0      │ 0%  │ 0 B    │ root │ disabled │
└──────────┴────┴──────┴─────┴─────────┴─────────┴────────┴─────┴────────┴──────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app
[root@lilidong /home/worker/website/nodejs-getting-started]#
jackieli123723 commented 6 years ago

## docker安装
一、在CentOS7上安装docker篇
1. 查看系统版本: 
查看centos 版本
[root@lilidong /]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@lilidong /]#
[root@lilidong /home/worker/docker]#  uname -r
4.10.6-1.el7.elrepo.x86_64

2. 安装docker 
$ yum install docker 
安装过程中报错自行解决

3.检查是否成功
[root@lilidong /home/worker/docker]# docker version
Client:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-71.git3e8e77d.el7.centos.1.x86_64
 Go version:      go1.8.3
 Git commit:      3e8e77d/1.12.6
 Built:           Tue Jan 30 09:17:00 2018
 OS/Arch:         linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
[root@lilidong /home/worker/docker]#

4.启动docker service docker start