1.   安装node

参照node.js官网安装步骤(略)。

2.   安装node模块

shCopy code
  • 1
  • 2
  • 3
npm install express -g npm install express-generator -g npm install pm2 -g
npm install express -g npm install express-generator -g npm install pm2 -g

3.   安装nginx

3.1.  修改nginx源

shCopy code
  • 1
vi /etc/yum.repos.d/nginx.repo
vi /etc/yum.repos.d/nginx.repo

增加如下内容:

iniCopy code
  • 1
  • 2
  • 3
  • 4
  • 5
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1

保存退出,再执行:

shCopy code
  • 1
yum install nginx
yum install nginx

安装完成后执行:

shCopy code
  • 1
service nginx status
service nginx status

查看运行状态。

3.2.  配置域名

shCopy code
  • 1
  • 2
  • 3
cd /etc/nginx/conf.d/ cp default.conf ifuyun.conf vi ifuyun.conf
cd /etc/nginx/conf.d/ cp default.conf ifuyun.conf vi ifuyun.conf

在location段增加:

nginxCopy code
  • 1
proxy_pass http://127.0.0.1:3000;
proxy_pass http://127.0.0.1:3000;

3.3.  启动nginx

shCopy code
  • 1
service nginx start
service nginx start

如果启动失败

  1. 查看日志:
    shCopy code
    • 1
    cat /var/log/nginx/error.log
    cat /var/log/nginx/error.log
  2. 查看进程:
    shCopy code
    • 1
    ps aux|grep nginx
    ps aux|grep nginx
  3. 结束所有进程
    shCopy code
    • 1
    killall -9 nginx
    killall -9 nginx
  4. 重启nginx
    shCopy code
    • 1
    service nginx restart
    service nginx restart
    即可正常启动、访问。

4.   安装mysql

4.1.  增加源

下载RPM-GPG-KEY-mysql,put到/etc/pki/rpm-gpg,然后执行:

shCopy code
  • 1
vi /etc/yum.repos.d/mysql-community.repo
vi /etc/yum.repos.d/mysql-community.repo

输入以下内容:

iniCopy code
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
# Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4.2.  安装

保存退出,执行

shCopy code
  • 1
yum install mysql-community-server
yum install mysql-community-server

安装。

安装成功后,执行:

shCopy code
  • 1
source ifuyun.sql
source ifuyun.sql

导入数据库。

4.3.  遇到的问题

4.3.1.   5.7版本安装后初始密码不为空,且未知,解决方法:

  1. 修改/etc/my.cnf,在[mysqld]下添加一行skip-grant-tables
  2. service mysqld restart后,直接用mysql进入
  3. 执行
    sqlCopy code
    • 1
    • 2
    update mysql.user set authentication_string=password('xxx') where user='xxx' and Host='localhost'; flush privileges;
    update mysql.user set authentication_string=password('xxx') where user='xxx' and Host='localhost'; flush privileges;
  4. /etc/my.cnf还原,重启mysql:service mysqld restart
  5. 执行mysql -u xxx -p进入
  6. 修改密码:
    set password=password('xxx');【必须执行,否则mysqladmin会报错:密码过期】

4.3.2.   mysql5.7的sql_mode问题:

修改/etc/my.cnf

设置sql_mode,去掉ONLY_FULL_GROUP_BY

然后重启mysql生效。

参考:http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

5.   安装redis

5.1.  安装

shCopy code
  • 1
  • 2
  • 3
  • 4
  • 5
wget http://download.redis.io/releases/redis-3.0.6.tar.gz tar -zxvf redis-3.0.6.tar.gz cd redis-3.0.6 make ./utils/install_server.sh
wget http://download.redis.io/releases/redis-3.0.6.tar.gz tar -zxvf redis-3.0.6.tar.gz cd redis-3.0.6 make ./utils/install_server.sh

5.2.  配置redis

shCopy code
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli
Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli

修改redis密码:

shCopy code
  • 1
vi /etc/redis/6379.conf
vi /etc/redis/6379.conf

重启:

shCopy code
  • 1
service redis_6379 stop/start
service redis_6379 stop/start

6.   启用防火墙

6.1.  查看防火墙状态

shCopy code
  • 1
firewall-cmd --state
firewall-cmd --state

6.2.  启用防火墙

shCopy code
  • 1
systemctl start firewalld
systemctl start firewalld

6.3.  增加规则

shCopy code
  • 1
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=80/tcp

6.4.  使规则生效

shCopy code
  • 1
firewall-cmd --reload
firewall-cmd --reload

6.5.  查看是否生效

shCopy code
  • 1
firewall-cmd --zone=public --list-ports
firewall-cmd --zone=public --list-ports

7.   修改DNS解析

不到一个小时即可生效,输入域名,成功。