mac搭建自己的微服务

这里使用的是laravel框架,基于laravel的组件larvels(laravel+swoole)

LaravelS 基于 Swoole 加速 Laravel/Lumen,常驻内存,内置 HTTP/WebSocket Server,支持 TCP/UDP Server、自定义进程、异步的事件监听、异步任务队列、毫秒级定时任务、平滑 Reload,与 Nginx 配合搭建高可用分布式服务器群,开箱即用。

1、 安装laravel框架(这步直接省略)
2、 直接安装laravelS

composer require "hhxsv5/laravel-s:~3.5.0" -vvv

3、 注册Service Provider
修改文件 config/app.php

 'providers' => [
        Hhxsv5\LaravelS\Illuminate\LaravelSServiceProvider::class,
    ],

4、 发布配置和二进制文件

php artisan laravels publishconfig\laravels.php就是你配置文件

5、 运行

php bin/laravels start

1F999F85-406B-4AD7-8E72-B95CD21F632E.png
这样就算是初步完成启动了,通过config\laravels.php配置的端口通过http请求完成访问

6.将ip发布到nginx并配置一个域名

gzip on;
gzip_min_length 1024;
gzip_comp_level 2;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml application/x-httpd-php image/jpeg image/gif image/png font/ttf font/otf image/svg+xml;
gzip_vary on;
gzip_disable "msie6";
#nginx upstream用于负载均衡
upstream swoole {
    # 通过 IP:Port 连接
    #多服务器负载均衡(没有服务器,拿端口来顶替),模拟多个服务器
    server 127.0.0.1:5200 weight=5 max_fails=3 fail_timeout=5s;#可设置参数请求
    server 127.0.0.1:5201 weight=5 max_fails=3 fail_timeout=5s;#可设置参数请求
    # 通过 UnixSocket Stream 连接,小诀窍:将socket文件放在/dev/shm目录下,可获得更好的性能
    #server unix:/yourpath/laravel-s-test/storage/laravels.sock weight=5 max_fails=3 fail_timeout=30s;
    #server 192.168.1.1:5200 weight=3 max_fails=3 fail_timeout=30s;
    #server 192.168.1.2:5200 backup;
    keepalive 16;
}

server {
    listen       80;
    client_max_body_size 512m;
    server_name  aa.com;
    # root  /Users/huchaoran/Desktop/所有项目/muchTemplate/public;
    autoindex off;
    index index.html index.php;

    location / {
        # try_files $uri $uri/ /index.php?$query_string;
        try_files $uri @laravels;
    }
    # location ~ \.php(.*)$ {
    #       fastcgi_pass   127.0.0.1:9000;
    #        fastcgi_index  index.php;
    #        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
    #        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    #        fastcgi_param  PATH_INFO  $fastcgi_path_info;
    #        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
    #       include        fastcgi_params;
    # }
    # location ~ /\.ht {
    #     deny all;
    # }
    # if (!-e $request_filename) {
    #     rewrite ^/(.*)$ /index.php/$1;
    # }
    location @laravels {
        # proxy_connect_timeout 60s;
        # proxy_send_timeout 60s;
        # proxy_read_timeout 120s;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header Server-Protocol $server_protocol;
        proxy_set_header Server-Name $server_name;
        proxy_set_header Server-Addr $server_addr;
        proxy_set_header Server-Port $server_port;
        access_log  /Users/huchaoran/Desktop/所有项目/muchTemplate/access.log;
        # “swoole”是指上面的upstream定义的swoole
        proxy_pass http://swoole;
    }
}

这里就完成了搭建laravel微服务,后面的我会一步步更新的

💫 评论卡

备案号:粤ICP备18155514号-2