Giter Site home page Giter Site logo

blog's Introduction

Blog

用hexo生成的博客,这里是源码。部署的在博客。

点此访问

总体体验尚可,细节尚有不足,不去深究

blog's People

Contributors

czzonet avatar

Watchers

 avatar  avatar

blog's Issues

nginx部署node

upstream node {
server 127.0.0.1:3003;
keepalive 64;
}

server {
listen 80;
server_name localhost;

location / {
    root /var/www/html/dist;
    try_files $uri $uri/ @router;
    index index.html;
}

error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
}
location @router {
    rewrite ^.*$ /index.html last;
}

location /api {
    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 Connection "";
    proxy_pass http://node; 
}

}

github常用和特有的md语法

md语法

特有的,选简单好用的就行
最讨厌搞什么lint语法建议,搞得既复杂又不易阅读。
这里记录了一些改进

一级标题
=
二级标题
-
[tab]单行文字
>缩进
一些表情
:shipit:
:sparkles:
:-1:
:+1:
:clap:

References

  1. emoji list

项目部署指南

综合项目部署

Part 1: 部署vue前端项目

先讲手动流程,过一遍。

打开源代码,编译出部署文件。

yarn build

打包dist文件夹

tar zcvf dist.tar.gz ./dist
mv ./dist.tar.gz /d

上传dist压缩文件

scp /d/dist.tar.gz [email protected]:~/uploads

下面转到服务端执行
假设已经成功登陆服务端

cd uploads
chmod 644 ./dist.tar.gz
cd /var/www/html/
mv ~/uploads/dist.tar.gz ./
rm -rf ./dist/*  # 注意这里是覆盖升级,如果第一次初始化请建立dist文件夹并一定分配nginx读取权限!
tar zxvf ./dist.tar.gz # 此处默认合并解压的dist文件夹

Part 2: 部署node后端项目

后端先不着急用PM2进行进程驻留,先使用命令行模式,运行测试,并观察日志输出有无异常。
特别的,这里会先带参数运行一次,进行数据库的重置。

cd 
mkdir back
cd back
git clone [email protected]:czzonet/firefly-backv2.git
cd firefly-back-v2
yarn # 安装依赖包
DB_DROP=true node ./bin/www # 进行表重建的试运行
# 如果正常 关闭程序
yarn global add pm2
pm2 -v
pm2 start ./bin/www
pm2 show www

Part 3: 迁移数据库

使用postgresql数据库,是感觉比较高级吧,但是同时坑也比较多。
还想用的原因,大概是可以支持json,而且字符编码也不去关心,至于之后的高级用法--函数过程,就给以后留下进阶使用吧。
坑就是许多配置不同,连登陆都诡异的不像同一个星球的东西,而且orm抽象层sequelize又是一个坑。orz。

回到正题,首先安装psql11.

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# update add install
sudo apt update
sudo apt install postgresql
# check version
psql --version

建立数据库和密码

sudo -u postgres psql
\password
create database f_pro;
\l  # 查看所有数据库

数据库迁移可能会有点坑,导入导出会报错,有点虚。
正好这次有自己解析数据文件的接口,就不去直接操作数据库了。

Part 4: 配置nginx转发

转发的关键在于对前端单页面需要完整转发给前端路由,对后端请求(/api)转发到上传流对应后端node进行处理。

cd /etc/nginx/site-avaliable
sudo vi vue
upstream node {
server 127.0.0.1:3003;
keepalive 64;
}

server {
listen 80;
server_name localhost;

location / {
    root /var/www/html/dist;
    try_files $uri $uri/ @router;
    index index.html;
}

error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
}
location @router {
    rewrite ^.*$ /index.html last;
}

location /api {
    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 Connection "";
    proxy_pass http://node; 
}
}

Extra: 一些使用的其他小知识

curl 发送post请求触发

curl -d "id=9" localhost

git使用别名来快捷输入命令

git 别名

以前写过,这里再存一份。

常用

其实常用的也就git commit,checkout,现在基本都是VS code里直接点点,重复敲命令不合适的。

方法

使用git config --global -e或者编辑~/.gitconfig文件,加入:

[alias]
    st = status
    co = checkout
    br = branch
    mg = merge
    ci = commit 
    md = commit --amend
    dt = difftool
    mt = mergetool
    last = log -1 HEAD
    cf = config
    line = log --oneline
    latest = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) [%(committername)]'

    ls = log --pretty=format:\"%C(yellow)%h %C(blue)%ad %C(red)%d %C(reset)%s %C(green)[%cn]\" --decorate --date=short
    hist = log --pretty=format:\"%C(yellow)%h %C(red)%d %C(reset)%s %C(green)[%an] %C(blue)%ad\" --topo-order --graph --date=short
    type = cat-file -t
    dump = cat-file -p

git打标签

语法

  • git tag:查看所有标签
  • git tag -a v1.0.0 -m 'message':打标签,是不是很像commit?
  • git push origin --tags:推送标签,是的,不会自动推送
  • git show v1.0.0:查看具体标签

心得

用久了git,倒也明白了怎么运作的,还是一个链表,分支名即指针变量名,至于标签,大概类似,不过好像特别的可以归到release里面去。

参考

gitbook里都有,虽然有,但是在这里摘抄一下,更有针对性和方便,也是极好。

git徽章

How about some badges?

使用现成的在线的徽章库就可以了

自定义语法如下:

![](https://img.shields.io/badge/<your title here>-<content>-<color>.svg)

注意

由于是网址传递,有些字符需要url转义,如%用%25表示。

例子

![](https://img.shields.io/badge/building-passing-brightgreen.svg)

常用

color
| | |

![](https://img.shields.io/badge/color-brightgreen-brightgreen.svg)
![](https://img.shields.io/badge/color-red-red.svg)
![](https://img.shields.io/badge/color-blue-blue.svg)
![](https://img.shields.io/badge/color-lighrgrey-lightgrey.svg)

build
|

![](https://img.shields.io/badge/building-passing-brightgreen.svg)
![](https://img.shields.io/badge/building-failing-red.svg)

codecov

![](https://img.shields.io/badge/codecov-80%25-brightgreen.svg)

md文件插入的图片的存储

引用图片

图文并茂才是一个好的文档,而md里插入图片也是 简单。
但是,存储图片就是一个很难的问题了。
下面有几个存储的办法

图床

免费的 连腾讯云都有几个G,但这安全性,说不订哪天就抽风了。

issue

GitHub的issue里是可以自动上传图片的

项目

直接加一个文件夹存储也是必要的
关键就是地址了
经过分析,地址按如下规则构建:

  • 绝对地址
    https://github.com/<your name>/<your repository>/raw/<branch>/<file path and name>
  • 相对地址
    就只要简单的输入图片的相对路径和文件名就可以了,非常方便。

总结

最后还是项目里直接建立一个文档文件夹好了,毕竟文件随项目走。

MySQL数据库配置编码为utf8bm4

MySQL数据库编码

又用到MySQL数据库,意外发现查询时编码有了问题,后来一看原来还没配置。
安装数据库太简单,只要傻瓜式apt install mysql就可以了,都忘了去配置。
改编码很简单,找到配置文件/etc/mysql/my.cnf,输入以下内容:

[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

然后sudo service mysql restart重启服务就ok了。
可以查询一下SHOW VARIABLES WHERE Variable_name LIKE 'character%' OR Variable_name LIKE 'collation%';,最后的结果是这样的:

设置好以后,建数据库和表的时候就不要担心了。
注意:没有涉及到已有表和数据库的编码转化,请查询其他资料。

nodejs使用apt在Ubuntu16.04的安装

node

安装

一直用推荐的nvm安装,但是最近在dockers里安装的时候,就不太好成功,因为有一步需要重开命令行,但在又Dockerfile的构建中,这一步一直不能实现。
最后,使用了apt安装的方法:
bash

#Ubuntu 安装node10
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash  - 
sudo apt-get install -y nodejs

Dockerfile: remove sudo

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt update\
&& apt install -y nodejs

References

  1. Install node

VS code调试与debug模块

注意事项:

这里提出关键两点:

  1. 不要使用VS code内部的debugger输出,支持并不完善,你需要一个Linux的tty,git bash就不错(其实就是mingW64 引用)
  2. 配置详解:
    • env:传递debug模块需要显示的日志命名空间名称
    • console:启用集成的命令行,可以配置为git bash
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Service",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}\\bin\\www",
      "timeout": 5000,
      "env": {
        "DEBUG": "*",
        "PORT": "6002"
      },
      "console":"integratedTerminal"
    }
  ]
}

git的ss代理设置

git代理

问题

下载速度几乎没有,原来是用路由器来管理代理的,后来由于并不易于使用,就不再使用了。
考虑到浏览器控制代理来浏览网页。给git专门设置代理是最好了。最后只需要两行配置即可。

git config --global https.proxy 'socks5://127.0.0.1:1080'
git config --global http.proxy 'socks5://127.0.0.1:1080'

总结

一开始也不理解,还想用nginx代理一下,设置专门的对git域名。后来发现是sock代理,而不是http啥的。

自动部署

持续集成与自动部署指南——Jenkins & Dockers

网络问题是非常关键的,如果某个阶段掉了链子,可能要做好填坑的准备。因为你只是使用别人的系统,如果出现网络异常的非正常使用,那可能很难正常工作了。
为此也进行了不少的填坑:换软件源,使用yarn。白白添加了许多难度。
即使这样,还可能出现莫名的状况,请在排查的时候要把网络因素也考虑在内。

Part 1: Docker的安装

安装社区版CE,Ubuntu和Windows都可以,注意需要win10和hype-v,与wmware虚拟机是冲突的,请做好选择。
win中也需要在设置里面勾选共享卷,否则无法使用数据卷。
只能使用power shell。
还有路径也要小心,不过还可以了。

Part 2: Jenkins的安装

需要一个主镜像和其他三个镜像。

docker image pull jenkinsci/blueocean
docker image pull ubuntu:16.04
cd ~/myubuntu-v4keys
docker build -t myubuntu:v4keys
cd ~/myubuntu-v5yarn
docker build -t myubuntu:v5yarn

后面两个是自己用dockerfile构建的,功能是提供yarn和ssh登陆部署功能。

Part 3: 启动Jenkins

docker run \
  --rm\
  -d\
  -u root \
  -p 7654:8080 \
  -v ~/jenkins_data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkinsci/blueocean

Part 4: 备份

docker run --rm -c c:/b:/back -v jenkins-data:/ci -u root -it ubuntu:16.04

找到keys基础配置即可。

Extra : 其他小知识

文件夹授权,递归子项

sudo chmod -R red:red ./*

查看文件大小 单位自动适应

du -h a.txt

回归github:私人仓库开始免费

远程仓库

不能免费仓库一直是一种遗憾,试过国外的,后来用国内的腾讯云,阿里云。但是有很令人心烦的认证机制,就很奇怪,大概涉及到钱,甚至还有推销电话*扰

rails部署

安装包

bundle install

必要的密钥生成

注意:步骤

  1. 生成并拷贝密钥rails secret
  2. 建立config/secrets.yml
production:
  secret_key_base: <parse your secrets here>
  1. 生成一对凭证和master.key,注意删除的时候要一起删除
    EDITOR=vim bin/rails credentials:edit

迁移数据库

rake db:setup RAILS_ENV=production

yarn是预编译所需

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
#预编译
bundle exec rake assets:precompile RAILS_ENV=production

安装passenger

sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
sudo apt-get install -y nginx-extras passenger

配置nginx

Add 'include /etc/nginx/passenger.conf;' to http block.
sudo vim /etc/nginx/nginx.conf

配置passenger块

sudo rm /etc/nginx/sites-enabled/default
sudo vim /etc/nginx/sites-available/club
Add:(改项目路径)
server {
listen 80 default;
server_name example.com; # 这里填写你真实域名
root /var/www/example.com/current/public; # 改为项目路径
passenger_enabled on;
}
sudo ln -s /etc/nginx/sites-available/club /etc/nginx/sites-enabled/club
sudo service nginx restart

check

sudo /usr/sbin/passenger-memory-stats

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.