BlankLin

lazy and boring

0%

yum安装过程

  • 安装 EPEL 软件包
    1
    yum install epel-release -y
  • 安装 remi 源
    1
    yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  • 安装 yum 扩展包
    1
    yum -y install yum-utils
  • 启用 remi 仓库
    1
    2
    yum-config-manager --enable remi-php72
    yum update
  • 安装php7.2
    1
    yum install -y php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
  • 设置开机自启
    1
    systemctl enable php72-php-fpm.service

    源码安装

  • 安装系统依赖
    1
    2
    yum install epel-release -y
    yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y
  • 下载源码
    1
    2
    3
    curl -O -L https://github.com/php/php-src/archive/php-7.2.3.tar.gz
    tar -zxvf php-7.2.3.tar.gz
    cd php-src-php-7.2.3
  • 编译安装
    1
    2
    3
    4
    5
    ./buildconf --force
    ./configure --prefix=/usr/local/php --enable-fpm --disable-short-tags --with-openssl --with-pcre-regex --with-pcre-jit --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --with-gd --enable-intl --enable-mbstring --with-mysqli --enable-pcntl --with-pdo-mysql --enable-soap --enable-sockets --with-xmlrpc --enable-zip --with-webp-dir --with-jpeg-dir --with-png-dir
    make clean
    make
    make install
  • php-fpm setup
    1
    2
    3
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
    cp php.ini-development /usr/local/php/etc/php.ini
  • 修改配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    vim /usr/local/php/etc/php.ini
    expose_php = Off
    short_open_tag = ON
    max_execution_time = 300
    max_input_time = 300
    memory_limit = 128M
    post_max_size = 32M
    date.timezone = Asia/Shanghai
    mbstring.func_overload=2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vim /usr/local/php/etc/php-fpm.d/www.conf
listen = /var/run/www/php-cgi.sock
listen.owner = www
listen.group = www
listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = dynamic
listen.backlog = -1
pm.max_children = 180
pm.start_servers = 50
pm.min_spare_servers = 50
pm.max_spare_servers = 180
request_terminate_timeout = 120
request_slowlog_timeout = 50
slowlog = var/log/slow.log
1
2
vim /usr/local/php/etc/php-fpm.conf
pid = /usr/local/php/var/run/php-fpm.pid
  • php加入系统环境
    1
    2
    3
    vim /etc/bashrc
    export PHP_PATH=/usr/local/php
    export PATH=$PHP_PATH/bin:$PATH
  • 启动php-fpm

    1
    /usr/local/php/sbin/php-fpm
  • 修改执行 php-fpm 的权限

    1
    2
    3
    4
    vi /etc/opt/remi/php72/php-fpm.d/www.conf
    # 设置用户和用户组为 nginx
    user = nginx
    group = nginx
  • 路径整理
    1
    /etc/opt/remi/php72

php 5.3.3 以后的php-fpm 不再支持 php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,所以不要再看这种老掉牙的命令了

  • 使用信号控制

    1
    2
    3
    4
    INT, TERM 立刻终止
    QUIT 平滑终止
    USR1 重新打开日志文件
    USR2 平滑重载所有worker进程并重新载入配置和二进制模块
  • 查看php-fpm的master进程

    1
    ps aux | grep php-fpm | grep -v grep

    php-fpm-process

    • 重启php-fpm
      1
      2
      # 最后的一串数字就是master进程的id
      kill -USR2 44551

  • docker安装
    • brew install
      1
      brew install docker
    • Docker Desktop install
      download
  • Dockerfile
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
# 基础镜像
FROM node as build

# 设置工作目录
WORKDIR /app

# 把 `/app/node_modules/.bin` 加到$PATH中
ENV PATH /app/node_modules/.bin:$PATH

# 安装并缓存应用依赖
COPY ./package.json /app/package.json
COPY ./package-lock.json /app/package-lock.json
# 切换npm源
RUN npm config set registry https://registry.npm.taobao.org
# 安装npm包
RUN npm install

# 编译应用
COPY . /app
RUN npm run build

# 删除无用文件
RUN rm -fr /app/src
RUN rm -fr /app/public
RUN rm -fr /app/node_modules

# production environment
FROM nginx
COPY --from=build /app/build /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d
EXPOSE 8082
CMD ["nginx", "-g", "daemon off;"]
```

+ nginx.conf配置

server {

listen 8082;

访问根目录强制到index.html

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

访问v1前缀都反向代理到server端地址

location ~ ^/v1/ {
rewrite ^/(.*)$ /$1 break;
proxy_pass http://server:8081;
}
}

1
+ Makefile

.PHONY: clean build

SHELL := /bin/bash

NAME=aere
VERSION=0.1
MODULE=git.xxx.com/xx/frontend
BUILD_DATE=$(shell date ‘+%Y%m%d’)
BUILD_VERSION=$(shell git log -1 —pretty=format:%h)
REGISTRY=10.xx.xx.17:8001

release:
docker build —no-cache -f Dockerfile -t $(REGISTRY)/$(NAME)/frontend:$(BUILD_DATE)-$(BUILD_VERSION) .
docker tag $(REGISTRY)/$(NAME)/frontend:$(BUILD_DATE)-$(BUILD_VERSION) $(REGISTRY)/$(NAME)/frontend

push:
docker push $(REGISTRY)/$(NAME)/frontend:$(BUILD_DATE)-$(BUILD_VERSION)
docker push $(REGISTRY)/$(NAME)/frontend

1
2
3
+ how to use  

+ 本地开发环境编排容器

make release
make push
1
+ 生产环境运行docker

    # 注意docker run的参数,具体参数定义自行查找
    docker run -it --rm -p 8082:8082 10.xx.xx.17:8001/aere/frontend
1
2

+ 浏览器访问
http://ip:8082 ```
  • 问题与思考
    • npm打包太慢,每次build都得好几分钟,不知道各位有没有好办法进行优化
    • 可以使用docker compose进行编排,就不需要每次在生产环境输入长串命令

nvm:node version manager

  • 安装
    1
    brew install nvm
  • 把nvm加入系统环境
    1
    2
    echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.bash_profile
    source ~/.bash_profile
  • 查看远程版本
    1
    nvm ls-remote
  • 安装指定的版本
    1
    nvm install <version>
  • 安装稳定版本
    1
    nvm install stable
  • 查看本地安装的版本列表
    1
    nvm ls
  • 使用某版本
    1
    nvm use <version>
  • 删除某版本
    1
    nvm uninstall <version>

  • 关闭mysqld
    1
    ps aux | grep mysqld | grep -v grep | awk '{print $2}' | xargs kill -9
  • 修改my.conf
    1
    2
    3
    vim /etc/my.conf
    # 找到[mysqld]这个section,添加skip-grant-tables,意思是忽略所有表的授权
    skip-grant-tables
  • 开启mysqld服务
    1
    mysqld &
  • 进入mysql
    1
    2
    3
    4
    5
    mysql -u root
    mysql> use mysql;
    mysql> update mysql.user set authentication_string=password('new password') where user='root';
    mysql> flush privileges;
    mysql> exit;
  • 撤回skip-grant-tables
    1
    2
    vim /etc/my.conf
    # 找到[mysqld]这个section,注释掉skip-grant-tables
  • 重启mysqld
    1
    2
    ps aux | grep mysqld | grep -v grep | awk '{print $2}' | xargs kill -9
    mysqld &
  • 密码登录mysql
    1
    2
    mysql -uroot -p
    #输入刚配置的新密码

Grafana v6.6.2 (3fa63cfc34)

  • [log]
    1
    2
    3
    # Either "console", "file", "syslog". Default is console and file
    # Use space to separate multiple modes, e.g. "console file"
    mode = console file
  • [paths]
    1
    2
    # Directory where grafana can store logs
    logs = data/log
  • [server]

    1
    2
    3
    4
    # Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
    data = data
    # Log web requests
    router_logging = false
  • docker启动

    1
    2
    3
    4
    5
    6
    7
    8
    sudo docker run -d --name grafana-log   \
    -p 3000:3000 \
    -e GF_LOG_MODE="console file" \
    -e GF_PATHS_LOGS='/var/log/grafana' \
    -e GF_SERVER_ROUTER_LOGGING=true \
    -v /Users/blank/grafana:/var/lib/grafana \
    -v /Users/blank/grafana/log:/var/log/grafana \
    grafana

    如果错误提示:【Failed to start grafana. error: failed to initialize file handler: open /var/log/grafana/grafana.log: permission denied】请配置目录/Users/blank/grafana权限为777

为了让不同的应用有不同的python环境,相互之间隔绝,互相不影响,我们引入virtualenv。

  • 安装virtualenv
    1
    pip install virtualenv
  • 创建虚拟环境
    1
    2
    cd project
    virtualenv -p $(which python) venv
  • 打开虚拟环境
    1
    source venv/bin/activate

    (venv) ~/Documents/code/python/project

  • 在虚拟环境安装模块
    1
    pip install xx
  • 关闭虚拟环境
    1
    deactivate

    ~/Documents/code/python/project

  • 在pycharm配置virtualenv
    pycharm-virtualenv
    pycharm-virtualenv-1
    pycharm-virtualenv-2

ORM(object relational mapping)对象关系映射,用来把对象模型表示的对象映射到基于SQL的关系型数据库结构中去,好处是我们在具体的操作实体对象时,不需要再去和复杂的sql语句打交道,只需要简单的操作实体对象的属性和方法。

  • peewee介绍
    • 优点:
      • Django式的API,使其易用
      • 轻量实现,很容易和任意web框架集成
    • 缺点:
      • 不支持自动化 schema 迁移
      • 多对多查询写起来不直观

具体使用请访问peewee的官方文档

  • 安装peewee
    1
    2
    pip install pymysql
    pip install peewee
  • 自动创建model(库和表已经在mysql创建)
    1
    2
    3
    4
    cd project
    // username是数据库用户名,host是数据库连接地址,database是数据库名
    python -m pwiz -e mysql -u username -H host --password database > model.py
    // 创建成功后会在model.py里看到对应的类名即表名驼峰
  • 新增
    1
    2
    3
    from model import Person
    p = Person(name="xx",age=18)
    p.save()
  • 删除
    1
    2
    3
    4
    5
    p = Person.get(Person.id == 1)
    p.delete_instance() # 返回删除的行数
    // 或者
    query = Person.delete().where(Person.id == 1)
    query.execute() # 返回删除的行数
  • 修改
    1
    2
    query = Person.update(name="yy").where(Person.id == 1)
    query.execute() # 返回修改的行数
  • 查询
    1
    2
    3
    4
    5
    6
    // 单条查询
    query = Person.get(Person.id == 1)
    print(query.name)
    // 多条查询
    for query in Person.select().where(Person.id == 1):
    print(query.name)

https://www.python.org/ftp/python/中选择自己需要的python源码包,我下载的是python3.7.0

  • 下载
    1
    wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
  • 解压
    1
    tar zxvf Python-3.7.0.tgz
  • 安装

    1
    2
    3
    cd Python-3.7.0
    ./configure --prefix=/usr/local/python3
    make && make install

    安装完成没有提示错误便安装成功了

  • 建立软连接

    1
    2
    ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
  • 测试

    1
    python3 --version
  • 卸载python

    1
    2
    3
    sudo rm -fr /usr/local/python3
    sudo rm -fr /usr/bin/python3
    sudo rm -fr /usr/bin/pip3
  • ssl错误

    Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) - skipping

  1. 安装openssl
    1
    yum -y install openssl
  2. 卸载python和pip

  3. 重新安装python

  • 升级pip
    1
    curl https://bootstrap.pypa.io/get-pip.py | python

使用rpm包方式安装mysql

  • 卸载旧rpm包
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    rpm -qa |grep -i mysql
    MySQL-client-5.6.23-1.sles11.x86_64
    MySQL-server-5.6.23-1.sles11.x86_64
    MySQL-shared-5.6.23-1.sles11.x86_64
    MySQL-devel-5.6.23-1.sles11.x86_64
    ————————————————
    // 逐个卸载
    rpm -e --nodeps MySQL-client-5.6.23-1.sles11.x86_64
    rpm -e --nodeps MySQL-server-5.6.23-1.sles11.x86_64
    rpm -e --nodeps MySQL-shared-5.6.23-1.sles11.x86_64
    rpm -e --nodeps MySQL-devel-5.6.23-1.sles11.x86_64
    // 确认卸载完成
    rpm -qa |grep -i mysql
    //my.cnf也可以删了
    rm -fr /etc/my.cnf
    //为空
  • 下载rpm包
    地址1
    地址2
    1
    wget http://repo.mysql.com/mysql57-community-release-fc27.rpm
  • 安装rpm包
    1
    sudo rpm -ivh mysql57-community-release-fc27.rpm
  • 查看yum repo源

    会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo

  • install mysql
    1
    sudo yum install mysql-server
  • 查看mysql安装
    1
    rpm -qa | grep mysql

    rpm -qa | grep mysql-community
    mysql-community-server-5.7.27-2.el7.x86_64
    mysql-community-release-el7-5.noarch
    mysql-community-libs-5.7.27-2.el7.x86_64
    mysql-community-common-57.27-2.el7.x86_64
    mysql-community-devel-5.7.27-2.el7.x86_64
    mysql-community-client-5.7.27-2.el7.x86_64

使用源码安装mysql

  • 获取源码安装包

    1
    wget  https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz
  • 安装系统所需依赖

    1
    yum install -y cmake gcc-c++ gcc ncurses-devel perl-Data-Dumper boost boost-doc boost-devel
  • 创建mysql用户
    1
    2
    3
    4
    useradd mysql  -s /sbin/nologin
    mkdir -pv /usr/local/mysql/mydata
    mkdir -pv /usr/local/mysql/conf
    chown -R mysql:mysql /usr/local/mysql
  • 删除mariadbd的my.cnf文件
    1
    rm -fr /etc/my.cnf
  • 解压源码包并安装
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    tar zxvf mysql-boost-5.7.20.tar.gz

    cmake \
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DMYSQL_DATADIR=/usr/local/mysql/mydata \
    -DSYSCONFDIR=/usr/local/mysql/conf \
    -DMYSQL_USER=mysql \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
    -DMYSQL_TCP_PORT=3306 \
    -DEXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_DEBUG=0 \
    -DMYSQL_MAINTAINER_MODE=0 \
    -DWITH_SSL:STRING=bundled \
    -DWITH_ZLIB:STRING=bundled \
    -DDOWNLOAD_BOOST=1 \
    -DWITH_BOOST=./boost

    make && make install
  • 创建my.cnf
    1
    2
    3
    4
    5
    vim /etc/my.cnf
    # 复制下面内容
    [mysqld]
    datadir=/usr/local/mysql/mydata
    socket=/tmp/mysql.sock
  • 把mysql添加到系统服务并设置开机启动

    1
    2
    3
    4
    5
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    cp /usr/local/mysql/bin/ /usr/bin/
  • 初始化mysql

    1
    2
    3
    4
    //version <5.7
    mysql_install_db
    //version >=5.7
    mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/mydata
  • 修改my.cnf
    1
    2
    3
    4
    5
    6
    vim /etc/my.cnf
    // 在下面制定启动用户是mysql
    [mysqld]
    user=mysql
    datadir=/usr/local/mysql/mydata
    socket=/tmp/mysql.sock
  • 启动mysqld

    1
    2
    3
    4
    mysqld
    // 若未做上一步,则启动时--user=mysql
    # 或者
    service mysqld start
  • 新建软链接

    1
    2
    ln -s /tmp/mysql.sock /usr/local/mysql/mysql.sock
    service mysqld restart
  • 修改mysq.cnf

    1
    2
    3
    4
    [mysqld]
    user=mysql
    datadir=/usr/local/mysql/mydata
    socket=/usr/local/mysql/mysql.sock
  • 修改root用户密码

    1
    2
    3
    4
    5
    6
    mysql -uroot -p
    // 首次登陆密码是空的,直接进入
    use mysql
    update user set password=password('new password') where user='root';
    flush privileges;
    exit;
  • 创建一个远程访问用户
    1
    2
    3
    4
    5
    6
    //创建用户
    create user 'somebody' identified by 'password’;
    //给用户授权
    Grant ALL PRIVILEGES on *.* to somebody@‘%’;
    //刷新
    flush privileges;

  • 安装go
    1
    brew install go
  • 安装nodejs
    1
    2
    3
    brew install nodejs
    # npm切换淘宝源
    npm config set registry https://registry.npm.taobao.org
  • 安装yarn
    1
    npm install -g yarn
  • clone项目
    git项目地址:https://github.com/grafana/grafana
    1
    go get github.com/grafana/grafana

    如果无法get下来,就直接clone 项目后,放到$GOPATH/src/github.com/grafana/grafana

  • 前端环境
    1
    2
    3
    4
    5
    6
    cd $GOPATH/src/github.com/grafana/grafana
    npm install -g node-gyp
    # 安装依赖
    yarn install --pure-lockfile
    # 执行编译
    yarn start

    编译完成后,在public文件夹会看到多了个build文件夹

  • 后端环境
    1
    2
    3
    cd $GOPATH/src/github.com/grafana/grafana
    go run build.go setup
    go run build.go build

    编译完成后,会看到多了个bin文件夹

  • 运行

    1
    bin/grafana-server start
  • 打包

    1
    go run build.go build package
  • 安装

    1
    2
    3
    4
    5
    sudo dpkg -i grafana_xxxx.deb
    // 项目文件
    /usr/share/grafana
    // 配置文件
    /etc/grafana/grafana.ini