Pkold

linux nginx

nginx 反向代理

nginx 反向代理

nginx.cfg

user www www;
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections 65535;
}
http {
    include mime.types;
    default_type application/octet-stream;
    include /usr/local/nginx/conf/reverse-proxy.conf;
    sendfile on;
    keepalive_timeout 65;
    gzip on;
    client_max_body_size 50m; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户
    client_body_buffer_size 256k;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间(代理连接超时)
    proxy_read_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时)
    proxy_send_timeout 300s;
    proxy_buffer_size 64k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
    proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
    proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
    proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
    proxy_ignore_client_abort on; #不允许代理端主动关闭连接
    server {
        listen 80;
        server_name localhost;
        location / {
            root html;
            index index.html index.htm;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}

映射不同端口

server
{
    listen 80;
    server_name xxx123.tk;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.10.38:3000;
    }
    access_log logs/xxx123.tk_access.log;
}

server
{
    listen 80;
    server_name xxx456.tk;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.10.40:80;
    }
    access_log logs/xxx456.tk_access.log;
}

负载均衡

upstream monitor_server {
    server 192.168.0.131:80;
        server 192.168.0.132:80;
}

server
{
    listen 80;
    server_name nagios.xxx123.tk;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://monitor_server;
    }
    access_log logs/nagios.xxx123.tk_access.log;
}

真实ip地址

log_format access '$HTTP_X_REAL_IP - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $HTTP_X_Forwarded_For';

access_log logs/access.log access;
linux nginx tcp

nginx-tcp代理

nginx-tcp代理

编译的时侯加上 --with-stream
stream 
{
    upstream cloudsocket 
    {
    hash $remote_addr consistent;
    server 10.x.xx.14:1831 weight=5 max_fails=3 fail_timeout=30s;
    }
server 
    {
    listen 8081;
    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass cloudsocket;
    }
}




官方负载均衡的案例
worker_processes auto;

error_log /var/log/nginx/error.log info;

events {
    worker_connections  1024;
}

stream {
    upstream backend {
        hash $remote_addr consistent;

        server backend1.example.com:12345 weight=5;
        server 127.0.0.1:12345            max_fails=3 fail_timeout=30s;
        server unix:/tmp/backend3;
    }

    upstream dns {
       server 192.168.0.1:53535;
       server dns.example.com:53;
    }

    server {
        listen 12345;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass backend;
    }

    server {
        listen 127.0.0.1:53 udp;
        proxy_responses 1;
        proxy_timeout 20s;
        proxy_pass dns;
    }

    server {
        listen [::1]:12345;
        proxy_pass unix:/tmp/stream.socket;
    }
}
linux node path python user

nodejs安装

nodejs安装

linux 下nodejs安装

一直再用nvm配置nodejs 很好用

有人说解压配置环境变量就可以

试了一下

确实 有个好处。。安装 -g 的时候 再也不用sudo了

export NODE=/home/free/bin/node
export PATH=$PATH:$NODE/bin:$NODE/lib/node_modules/npm/bin/node-gyp-bins

设置一下淘宝源

npm config set registry https://registry.npm.taobao.org 
esp esp8266 nodemcu

nodemcu的hello world

nodemcu的hello world

已经刷好了nodemcu

function Init_oled(sda,scl,sla)

   i2c.setup(0, sda, scl, i2c.SLOW)
   disp = u8g.ssd1306_128x32_i2c(sla)

end

function  First_Screen()

   disp:firstPage()
 repeat
   disp:drawBox(10,10,10,10)
 until disp:nextPage() == false

end

Init_oled(2,1,0x3c)
First_Screen()
boom kill linux oom

linux oom-killer机制

linux oom-killer机制 linux内存不足会把程序kill掉

linux内存不足会把程序kill掉

为了保护重要进程不被oom-killer掉,我们可以:

echo -17 > /proc/<pid>/oom_adj,-17表示禁用OOM

我们也可以对把整个系统的OOM给禁用掉:

    sysctl -w vm.panic_on_oom=1

    sysctl -p
linux phalcon php

php的c扩展框架 phalcon 的简单使用

php的c扩展框架 phalcon 的简单使用

Phalcon 是开源、全功能栈、使用 C 扩展编写、针对高性能优化的php框架

生成控制器

 phalcon create-controller --name index2

基本配置

[database]
adapter  = Mysql
host     = "127.0.0.1:port"
username = "root"
password = "root"
dbname   = "tests"

[phalcon]
controllersDir = "../app/controllers/"
modelsDir      = "../app/models/"
viewsDir       = "../app/views/"
baseUri        = "/store/"

生成模型

phalcon model products
  • --name=s Table name 表名
  • --schema=s Name of the schema. [optional] schema名
  • --namespace=s Model’s namespace [optional] 模型命名空间
  • --get-set Attributes will be protected and have setters/getters. [optional] 设置字段访问属性为私有 并添加setters/getters方法
  • --extends=s Model extends the class name supplied [optional] 指定扩展类名
  • --excludefields=l Excludes fields defined in a comma separated list [optional]
  • --doc Helps to improve code completion on IDEs [optional] 辅助IDE的自动完成功能
  • --directory=s Base path on which project will be created [optional] 项目的根目录
  • --force Rewrite the model. [optional] 重写模型
  • --trace Shows the trace of the framework in case of exception. [optional] 出错时显示框架trace信息
  • --mapcolumn Get some code for map columns. [optional] 生成字映射的代码
  • --abstract Abstract Model [optional] 抽象模型

生成简单的curd

phalcon scaffold --table-name products

开启webtools

phalcon webtools enable/disable(开启关闭)

ide自动补全

文档

none

php的c扩展框架 phalcon

None

Phalcon 是开源、全功能栈、使用 C 扩展编写、针对高性能优化的php框架

安装

git clone git://github.com/phalcon/cphalcon.git

cd cphalcon/build

sudo ./install
# 报错的话  看提示补齐依赖

然后引入so文件

extension=phalcon.so

安装命令行工具

git clone https://github.com/phalcon/phalcon-devtools 

在.bashrc文件中给phalcon-devtools中的phalcon.php一个别名

alias phalcon='/home/xxx/phalcon-devtools/phalcon.php'

运行命令

source .bashrc

使用构建工具 构建简单的项目工程

phalcon create-project store

致此。一个简单的helloworld就出来了

php url

php的c扩展框架 phalcon 修复url的bug

php的c扩展框架 phalcon 修复url的bug

php的c扩展框架 phalcon 修复url的bug

Phalcon 是开源、全功能栈、使用 C 扩展编写、针对高性能优化的php框架

默认生成的url会重复

修改

app->config->config.php

defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');

return new \Phalcon\Config([
    'database' => [
        'adapter'     => 'Mysql',
        'host'        => 'localhost:3309',
        'username'    => 'root',
        'password'    => 'root',
        'dbname'      => 'test',
        'charset'     => 'utf8',
    ],
    'application' => [
        'appDir'         => APP_PATH . '/',
        'controllersDir' => APP_PATH . '/controllers/',
        'modelsDir'      => APP_PATH . '/models/',
        'migrationsDir'  => APP_PATH . '/migrations/',
        'viewsDir'       => APP_PATH . '/views/',
        'pluginsDir'     => APP_PATH . '/plugins/',
        'libraryDir'     => APP_PATH . '/library/',
        'cacheDir'       => BASE_PATH . '/cache/',
        'baseUri'        => '/', //这修改成/根  就可以了
    ]
]);
linux mysql pg postgresql 数据库

postgresql安装

postgresql安装

pgsql/bin/initdb -D /usr/local/pgsql/data
local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
local/pgsql/bin/createdb test
local/pgsql/bin/psql test

账户设置

创建用户
CREATE USER davide WITH PASSWORD 'jw8s0F4';
改密码
ALTER ROLE davide WITH PASSWORD 'hu8jmn3';
让一个角色能够创建其他角色和新的数据库:
ALTER ROLE miriam CREATEROLE CREATEDB;
linux node nodejs py python

linux 下python 安装

linux 下python 安装

``` ./configure --prefix=/home/free/usr/bin/python

make -j8

make install

然后

nano .bashrc

export PYTHON=/home/free/bin/python export PATH=$PYTHON/bin:$PATH

要把$PATH放在最后面 ```