CentOS部署

如何在全新的CentOS系统中完成博客和网站的部署。

ZSH

  1. 安装git:yum -y install git
  2. 安装zsh:yum -y install zsh
  3. 设为默认shell:chsh -s $(which zsh)
  4. sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

安装autojump

  1. git clone git://github.com/joelthelion/autojump.git
  2. cd autojump
  3. ./install.py
  4. 添加[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh.zshrc
  5. 重新连接服务器

安装Shadowsocks

安装

http://shadowsocks.be或者https://teddysun.com/486.html

打开防火墙8989端口

  1. vi /etc/sysconfig/iptables
  2. 添加-A INPUT -p tcp -m state --state NEW -m tcp --dport 8989 -j ACCEPT
  3. service iptables restart

安装LNMP

https://oneinstack.com/install/

Node程序

安装Node

  1. cd /opt
  2. wget https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.xz
  3. xz -d node-v8.9.1-linux-x64.tar.xz
  4. tar -xvf node-v8.9.1-linux-x64.tar
  5. mv node-v8.9.1-linux-x64 node
  6. export PATH=/opt/node/bin:$PATH

安装forever/bower/pm2

npm install -g forever bower pm2

主域名博客

  1. 添加虚拟主机
  2. 参见https://github.com/firekylin/firekylin/wiki/%E5%AE%89%E8%A3%85

配置nginx

  1. vi /usr/local/nginx/conf/vhost/lujq.me.conf
  2. 改为

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    server {
    listen 80;
    server_name lujq.me;
    root /data/wwwroot/lujq.me/www;
    set $node_port 8360;
    index index.js index.html;
    location / {
    proxy_http_version 1.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://127.0.0.1:$node_port$request_uri;
    proxy_redirect off;
    }
    location = /development.js {
    deny all;
    }
    location = /testing.js {
    deny all;
    }
    location = /production.js {
    deny all;
    }
    location ~ /static/ {
    etag on;
    expires max;
    }
    }
  3. service nginx restart

MongoDB

安装

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-linux/

  1. cd /opt/
  2. curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.10.tgz
  3. tar -zxvf mongodb-linux-x86_64-3.4.10.tgz
  4. mv mongodb-linux-x86_64-3.4.10 mongodb

启动

  1. export PATH=/opt/mongodb/bin:$PATH
  2. mkdir -p /data/db
  3. mongod --fork --logpath=/data/db/mongodb.log

恢复备份

把数据库备份解压到/opt/mean目录
mongorestore -d mean /opt/mean

用户权限(可选)

  1. mongo
  2. use admin
    3.
1
2
3
4
5
6
7
db.createUser(
{
user: "golmic",
pwd: "...",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)

4.db.shutdownServer()
5.mongod --auth --fork --logpath=/data/db/mongodb.log

gsm.lujq.me/mafengwo.lujq.me

  1. 修改nginx配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    server {
    listen 80;
    listen [::]:80;
    server_name gsm.lujq.me;
    root /data/gsm.lujq.me;
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:3000;
    }
    error_page 404 /404.html;
    location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    }
    }
  2. service nginx restart重启nginx

  3. 从github上下载文件到相应目录并解压
  4. npm install安装依赖
  5. bower install --allow-root安装前端依赖
  6. forever start server.js

gsm.lujq.me修复

根目录下新建文件vi .bowerrc,添加

1
2
3
{
"directory": "public/lib"
}

语句后bower install --allow-root

二级域名

nginx配置备份

1
2
3
4
5
6
server {
listen 80;
server_name resume.lujq.me;
root /data/wwwroot/lujq.me/resume;
index index.html;
}

Mysql定时备份到Dropbox

安装python3,参见code.lujq.me教程

1.新建~/.my.cnf,写入下列内容:

1
2
3
[mysqldump]
user=root
password=

  1. easy_install pip安装pip
  2. pip install dropbox
  3. https://gist.github.com/golmic/547e54670e1596b903b94a5438c1756b
  4. unzip master.zip

配置crontab

  1. 0 0 * * * source /opt/python3/bin/activate && cd /opt && python upload.py写入golmiccron。
  2. crontab golmiccron