centOS7安装node+mongoDB+redis+express(bootself-startforerver)+nginx+https(Let'sEncrypt)操作工具使用xshell1.centOS7安装node.js参考:centos7安装noderoot并登陆xshell1.通常在新服务器上创建最后,先升级centOS:yum-yupdate2。安装gccg++编译器yuminstallgcc-c++3。安装nodecd/usr/local/srcwgethttp://nodejs.org/dist/v6.11.0/node-v6.11.0.tar.gz如果提示:-bash:wget:commandnotfoundthen:[root@hostsrc]#yum-y安装wget4。解压tar-xzvfnode-v6.11.0.tar.gzcdnode-v6。11.0./配置5。编译源码,这一步会花很长时间:makemakeinstallnpm-ginstallexpressforever至此,node.js的安装过程基本完成,可以通过命令查看node和npm的版本:node-vnpm-v2.安装mongoDB参考:mongodbMongodb详解1.切换目录cd/usr/local/src2.下载安装包wgethttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4。4.tgz3。解压:tar-xzvfmongodb-linux-x86_64-rhel62-3.4.4.tgz4。重命名:mvmongodb-linux-x86_64-rhel62-3.4.4/mongodb5。删除安装包:rm-rfmongodb-linux-x86_64-rhel62-3.4.4.tgz6。创建数据库:cdmongodbmkdirdbstouchlogscdbin./mongod--dbpath=/usr/local/src/mongodb/dbs/--logpath=/usr/local/src/mongodb/logs–fork7.设置启动:在vimongodb.conf中添加如下代码:port=27017dbpath=/usr/local/src/mongodb/dbslogappend=truefork=truelogpath=/usr/local/src/mongodb/logsnohttpinterface=true8、测试:cd/usr/local/src/mongodb/bin./mongod-fmongodb.conf9、开机自动启动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/wgethttp://download.redis.io/releases/redis-3.2.8.tar.gztar-zxvfredis-3.2.8.tar.gz2,安装并启动[root@主机源]#cd./redis-3.2.8[root@hostredis-3.2.8]#makeMALLOC=libc[root@hostredis-3.2.8]#cdsrc[root@hostsrc]#makeinstall[root@hostsrc]#./redis-server以上启动成功,按ctrl+c退出3、改为后台启动[root@hostsrc]#cd../[root@hostredis-3.2.8]#viredis.confdaemonizenochangeyes改为后台启动cd./src[root@hostsrc]#ps-aux|grepredis查看进程[root@hostsrc]#kill-9723注:723为实际进程数[root@hostsrc]#cd/etc[root@hostetc]#mkdirredis[root@hostetc]#cp/usr/local/src/redis-3.2.8/redis.conf/etc/redis/6379.conf[root@hostetc]#cp/usr/local/src/redis-3.2.8/utils/redis_init_script/etc/init.d/redisd[root@hostetc]#cd/etc/init.d[root@hostinit.d]#chkconfigredisdonerror:serviceredisddoesnotsupportchkconfig[root@hostinit.d]#viredisd在第一行添加下面两行lineComment,saveandexit#chkconfig:23459010#描述:Redis是一个持久化的键值数据库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@hostinit.d]#chkconfigredisdon[root@hostinit.d]#serviceredisd启动报错/var/run/redis_6379.pidexists,processalreadyrunningorcrashed[root@hostinit.d]#redis-server/etc/redis/6379.conf[root@hostinit.d]#shutdown-rnowreconnect[root@host~]#serviceredisdstart4.Forerver指foreverforcentos7express自动开机1.在etc/init.d新建节点文件,打开[root@hostbin]#cd/etc/init.d[root@hostinit.d]#touchnode[root@hostinit.d]#vi节点文件内容:#!/bin/bash##node启动节点服务器守护进程##chkconfig:3458515#描述:ForeverforNode.js#PATH=/usr/local/binDEAMON=/var/www/expresswai/index.jsLOG=/tmp/hosts_logPID=/tmp/forever.pidcase"$1"instart)foreverstart-l$LOG/forever.log-o$LOG/forever_out.log-e$LOG/forever_err.log--pidFile$PID-a$DEAMON;;停止)永远停止--pidFile$PID$DEAMON;;stopall)foreverstopall--pidFile$PID;;restartall)永远restartall--pidFile$PID;;重新加载重启)永远重启-l$LOG/forever.log-o$LOG/forever_out.log-e$LOG/forever_err.log--pidFile$PID-a$DEAMON;;名单)永远名单;;*)echo"Usage:/etc.init.d/node{start|stop|restart|reload|stopall|restartall|list}"exit1;;esacexit02,配置启动[root@hostinit.d]#chkconfig--addnode[root@hostinit.d]#servicenodestart方法报错env:/etc/init.d/nodeForever:Permissiondenied[root@hostinit.d]#chmoda+x/etc/init.d/node[root@hostinit.d]#服务节点启动错误/usr/bin/env:node:Nosuchfileordirectory[root@hostbin]#ln-s/usr/local/bin/node/usr/bin/node5.centos7nginx参考:安装Nginx1,下载安装包#cd/usr/local/src#wgethttp://nginx.org/download/nginx-1.11.5.tar.gz2,安装依赖并解压安装#yuminstallgcc-c++#yuminstallpcre#yuminstallpcre-devel#yuminstallzlib#yuminstallzlib-devel#yuminstallopenssl#yuminstallopenssl-devel#tar-zxvfnginx-1.11.5.tar.gz#cd/usr/local/src/nginx-1.11.5/#./configure#make#makeinstall默认安装位置是/usr/local/nginx,之前的/usr/local/src/nginx-1.11.5/可以删除3.配置自启动#cd/lib/systemd/system/#vimnginx.service文件内容:[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginxreloadExecStop=/usr/local/nginx/sbin/nginxquitPrivateTmp=true[Install]WantedBy=multi-user.target4,start#systemctl启用nginx.servicessystemctlstartnginx.servicestartnginxsystemctlstopnginx.serviceendnginxsystemctlrestartnginx.servicerestartnginx六、centos7httpsLet'sEncryptcd/usr/local/srcyuminstallgit-all[root@hostsrc]#gitclonehttps://github。com/letsencrypt/letsencrypt[root@hostsrc]#cdletsencrypt[root@hostletsencrypt]#./letsencrypt-auto后台服务停止#serviceexpresswaistopsetdomainnameandassociatedmailbox[root@hostletsencrypt]#./letsencrypt-autocertonly--standalone--email123456789@qq.com-dwww.domain.com文件位置/etc/letsencrypt/live/www.domain.com/privkey.pem[root@hostwww.domain.com]#cp/etc/letsencrypt/live/www.domain.com/cert.pem/var/www/expresswai/ssl[root@hostssl]#cp/etc/letsencrypt/live/www.domain.com/chain.pem/var/www/expresswai/ssl[root@hostssl]#cp/etc/letsencrypt/live/www.domain.com/fullchain.pem/var/www/expresswai/ssl[root@hostssl]#cp/etc/letsencrypt/live/www.domain.com/privkey.pem/var/www/expresswai/ssl
