centOS7安裝node+mongoDB+redis+express(forerver)+nginx+https

centOS7安裝node+mongoDB+redis+express(開機自啓forerver)+nginx+https(Let’s Encrypt)html

操做工具用xshellnode

1、在 centOS 7 安裝node.js
參考:centos7安裝nodelinux

root登陸完xshell
一、通常在新服務器建立後,先升級一下centOS:nginx

yum -y update

2.安裝gcc g++編譯器c++

yum install gcc-c++

3.安裝nodegit

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]#github

yum -y install wget

4.解壓redis

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

5.編譯源代碼,這個步驟花的時間會很長:mongodb

make
make install
npm -g install express forever

到這裏,node.js 就基本上完成了安裝過程,能夠經過指令查看node及npm版本:shell

node -v

npm -v

2、安裝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

六、建立數據庫:

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

七、設置開機啓動:

vi mongodb.conf
添加如下代碼:

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

八、測試:

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

九、開機自動啓動mongodb:

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

3、centos7下安裝redis

參考: redis

問題處理

一、切換相應目錄,下安裝包並解壓

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

二、安裝並啓動

[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退出
三、改爲後臺啓動

[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

4、centos7 express開機自啓forerver
參考 Forever

一、在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

二、配置啓動

[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

5、centos7 nginx

參考:安裝Nginx

一、下安裝包

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

二、安裝依賴並解壓安裝

# 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/能夠刪除掉了
三、配置自啓

# 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

四、啓動

# systemctl enable nginx.service

systemctl start nginx.service    啓動nginx
systemctl stop nginx.service    結束nginx
systemctl restart nginx.service    重啓nginx

6、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
相關文章
相關標籤/搜索