1

centOS7安装node+mongoDB+redis+express(开机自启forerver)+nginx+https(Let’s Encrypt)

操作工具用xshell

一、在 centOS 7 安装node.js
参考:centos7安装node

root登录完xshell
1、一般在新服务器创建后,先升级一下centOS:

yum -y update

2.安装gcc g++编译器

yum install gcc-c++

3.安装node

cd /usr/local/src
wget http://nodejs.org/dist/v6.11.0/node-v6.11.0.tar.gz

如提示:-bash: wget: command not found
则:[root@host src]#

yum -y install wget

4.解压

tar -xzvf node-v6.11.0.tar.gz
cd node-v6.11.0
./configure

5.编译源代码,这个步骤花的时间会很长:

make
make install
npm -g install express forever

到这里,node.js 就基本上完成了安装过程,可以通过指令查看node及npm版本:

node -v

npm -v

二、安装mongoDB

参考:mongodb
Mongodb详解

1.切换目录

cd /usr/local/src

2.下载安装包

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.4.tgz

3.解压:

tar -xzvf mongodb-linux-x86_64-rhel62-3.4.4.tgz

4.重命名:

mv mongodb-linux-x86_64-rhel62-3.4.4/ mongodb

5.删除安装包:

rm -rf mongodb-linux-x86_64-rhel62-3.4.4.tgz

6、创建数据库:

cd mongodb
mkdir dbs
touch logs
cd bin
./mongod --dbpath=/usr/local/src/mongodb/dbs/ --logpath=/usr/local/src/mongodb/logs –fork

7、设置开机启动:

vi mongodb.conf
添加以下代码:

port=27017
dbpath=/usr/local/src/mongodb/dbs
logappend=true
fork=true
logpath=/usr/local/src /mongodb/logs
nohttpinterface=true

8、测试:

cd /usr/local/src/mongodb/bin
./mongod -f mongodb.conf

9、开机自动启动mongodb:

vi /etc/rc.d/rc.local
添加下面一行:
/usr/local/src /mongodb/bin/mongod --config /usr/local/src /mongodb/bin/mongodb.conf

三、centos7下安装redis

参考: redis

问题处理

1、切换相应目录,下安装包并解压

cd /usr/local/src/
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxvf redis-3.2.8.tar.gz

2、安装并启动

[root@host src]# cd ./redis-3.2.8

[root@host redis-3.2.8]# make MALLOC=libc
[root@host redis-3.2.8]# cd src
[root@host src]# make install
[root@host src]# ./redis-server

以上启动成功,按ctrl+c退出
3、改成后台启动

[root@host src]# cd ../

[root@host redis-3.2.8]# vi redis.conf
daemonize no 改yes
已改成后台启动
cd ./src
[root@host src]# ps -aux | grep redis
查看进程
[root@host src]# kill -9 723
注:723为实际的进程数
[root@host src]# cd /etc
[root@host etc]# mkdir redis
[root@host etc]# cp /usr/local/src/redis-3.2.8/redis.conf /etc/redis/6379.conf

[root@host etc]# cp /usr/local/src/redis-3.2.8/utils/redis_init_script /etc/init.d/redisd
[root@host etc]# cd /etc/init.d
[root@host init.d]# chkconfig redisd on

报错:service redisd does not support chkconfig

[root@host init.d]# vi redisd
在第一行加入如下两行注释,保存退出
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

改完效果图

redis-server和redis-cli路径改成自己的
如:usr/local/src/redis-3.2.8/src/redis-server
如:usr/local/src/redis-3.2.8/src/redis-cli
再次执行

[root@host init.d]# chkconfig redisd on
[root@host init.d]# service redisd start

报错/var/run/redis_6379.pid exists, process is already running or crashed

[root@host init.d]# redis-server /etc/redis/6379.conf
[root@host init.d]# shutdown -r now
重新连接一下
[root@host ~]# service redisd start

四、centos7 express开机自启forerver
参考 Forever

1、在etc/init.d新建node文件并打开

[root@host bin]# cd /etc/init.d
[root@host init.d]# touch node
[root@host init.d]# vi node

文件内容 为:

#!/bin/bash
#
# node      Start up node server daemon
#
# chkconfig: 345 85 15
# description: Forever for Node.js
#
PATH=/usr/local/bin
DEAMON=/var/www/expresswai/index.js
LOG=/tmp/hosts_log
PID=/tmp/forever.pid

case "$1" in
    start)
        forever start -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID -a $DEAMON
        ;;
    stop)
        forever stop --pidFile $PID $DEAMON
        ;;
    stopall)
        forever stopall --pidFile $PID
        ;;
    restartall)
        forever restartall --pidFile $PID
        ;;
    reload|restart)
        forever restart -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID -a $DEAMON
        ;;
    list)
        forever list
        ;;
    *)
        echo "Usage: /etc.init.d/node {start|stop|restart|reload|stopall|restartall|list}"
        exit 1
        ;;
esac
exit 0

2、配置启动

[root@host init.d]# chkconfig --add node
[root@host init.d]# service node start

以下为另一篇调试中出现的问题解决办法
报错 env: /etc/init.d/nodeForever: Permission denied

[root@host init.d]# chmod a+x /etc/init.d/node
[root@host init.d]# service node start

报错/usr/bin/env: node: No such file or directory

[root@host bin]# ln -s /usr/local/bin/node /usr/bin/node

五、centos7 nginx

参考:安装Nginx

1、下安装包

# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.11.5.tar.gz

2、安装依赖并解压安装

# yum install gcc-c++
# yum install pcre
# yum install pcre-devel
# yum install zlib 
# yum install zlib-devel
# yum install openssl
# yum install openssl-devel

# tar -zxvf nginx-1.11.5.tar.gz
# cd /usr/local/src/nginx-1.11.5/
# ./configure
# make
# make install

默认安装位置为/usr/local/nginx,之前的/usr/local/src/nginx-1.11.5/可以删除掉了
3、配置自启

# cd /lib/systemd/system/
# vim nginx.service

文件内容 :

[Unit]
Description=nginx 
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target

4、启动

# systemctl enable nginx.service

systemctl start nginx.service    启动nginx
systemctl stop nginx.service    结束nginx
systemctl restart nginx.service    重启nginx

六、centos7 https Let’s Encrypt

cd /usr/local/src
yum install git-all
[root@host src]# git clone https://github.com/letsencrypt/letsencrypt
[root@host src]# cd letsencrypt
[root@host letsencrypt]# ./letsencrypt-auto

后台服务要停掉

#  service expresswai stop

设置域名及关联的邮箱

[root@host letsencrypt]# ./letsencrypt-auto certonly --standalone --email 123456789@qq.com -d www.domain.com

文件位置/etc/letsencrypt/live/www.domain.com/privkey.pem

[root@host www.domain.com]# cp /etc/letsencrypt/live/www.domain.com/cert.pem /var/www/expresswai/ssl
[root@host ssl]# cp /etc/letsencrypt/live/www.domain.com/chain.pem /var/www/expresswai/ssl
[root@host ssl]# cp /etc/letsencrypt/live/www.domain.com/fullchain.pem /var/www/expresswai/ssl
[root@host ssl]# cp /etc/letsencrypt/live/www.domain.com/privkey.pem /var/www/expresswai/ssl

kalakalaxyz
123 声望6 粉丝