nginx unit安装

avatar 2022年8月7日18:04:08 评论 257 次浏览

1 创建repo文件

在文件夹 /etc/yum.repos.d/ 下创建 unit.repo文件

[root@wulaoer.org ~]# vim /etc/yum.repos.d/unit.repo
[unit]

name=unit repo
baseurl=http://packages.nginx.org/unit/centos/7/$basearch/
gpgcheck=0
enabled=1

命令开始

[root@wulaoer.org ~]# cd /etc/yum.repos.d/
[root@wulaoer.org ~]# vi unit.repo
[输入i进入编辑模式。将内容复制进去,按esc退出,输入:wq保存内容。]
[root@wulaoer.org ~]# yum -y install unit 
[按y安装]

命令结束

2 安装php

[root@wulaoer.org ~]# yum -y install unit-php

安装 python

[root@wulaoer.org ~]# yum -y install unit-python

安装go

[root@wulaoer.org ~]# yum -y install unit-go

安装全部

[root@wulaoer.org ~]# yum install unit-php unit-python unit-go unit-perl unit-devel unit-jsc-common unit-jsc8 unit-jsc11

[目前好像只支持安装这些东西]

3 启动unit

[root@wulaoer.org ~]# service unit start

对应的关闭unit

[root@wulaoer.org ~]# service unit stop

4 配置php应用

[root@wulaoer.org ~]# mkdir -p /home/wwwroot/blogs/scripts

在 /etc/unit/ 目录下新建一个start.json文件 (这个文件可以建立在任何位置)

{

     "listeners": {
    
         "*:8300": {
    
             "application": "blogs"
    
         }
    
     },
    
     "applications": {
    
         "blogs": {
    
             "type": "php",
    
              "workers": 20,
    
              "root": "/home/wwwroot/blogs/scripts",
    
              "index": "index.php"
    
         }
    
     }

}

配置说明

listeners:设置监听端口和对应的应用

*:8300:端口8300对应的应用是blogs应用。

applications:应用配置

blogs:blogs应用配置,类型(type)为php应用,workers可能是工作线程(20个),root:php程序所在文件夹(/www/blogs/scripts),index为首页文件(index.php)

[root@wulaoer.org ~]# systemctl enable unit.service
[root@wulaoer.org ~]# systemctl restart unit.service
[root@wulaoer.org ~]# systemctl stop unit.service
[root@wulaoer.org ~]# systemctl disable unit.service
Removed symlink /etc/systemd/system/multi-user.target.wants/unit.service.
[root@wulaoer.org ~]# systemctl start unit.service

5 启动 php应用

在文件夹下 /www/blogs/scripts 创建 index.php 文件。

curl -X PUT -d @/etc/unit/start.json  \
       --unix-socket /var/run/unit/control.sock http://localhost/config/



<?
    echo("www.wulaoer.org is php")
?>



[root@wulaoer.org unit]# /usr/sbin/unitd --control 127.0.0.1:8300
2020/03/19 14:53:22 [info] 9411#9411 unit started
[root@localhost unit]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1212/master         
tcp        0      0 127.0.0.1:8300          0.0.0.0:*               LISTEN      9412/unitd          
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1073/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1212/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1073/sshd
avatar
  • 未经博主允许,禁止转载本博客任何内容,如需转载请留言,谢谢合作!!!
  • 转载注明:nginx unit安装 | 吴老二

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: