Linux basic knowledge points for php programmers

Recent review and summary of basic knowledge points of linux

I have recently adjusted the structure of the problem, so I will use a lot of linux-related knowledge and do a little knowledge summary

batch kill process

ps -ef|grep 'process keywords'|awk '{print $2}'|xargs kill -9

  • awk extract PID
  • xargs passes the argument list piecewise to the attached command
linux disk management
1. df-查看磁盘总体使用情况(-h 根据需要展示大小单位)
2. (待) du-查看文件占用磁盘大小( --max-depth=1 用来确定搜索深度 )
3. (待)fdisk,空间管理工具,可以对挂载的磁盘进行分区和格式
4. 最后使用mount挂载到对应的文件目录入口:`mount 分区 入口路径`
Under linux, compile and install php7.3
1. 下载源码
2. 解压:`tar -zvxf 源码压缩包`,cd 进入解压缩目录
3. 开始编译前配置与检测:`./configure --prefix=安装目录 --with-插件 `, 常用插件参考文档地址:[12月工作日志](http://note.youdao.com/noteshare?id=9b0630eb352fd416f89fe0f906e25860)
4. 如果检测有异常,对应安装相应的依赖即可
5. 万年不变编译二连开始:make && make install
6. 编译好以后,辅助完善步骤:
    1. 配置文件:`cp 解压目录/php.ini-product 安装目录/定义配置文件目录`;
    2. php-fpm,php-fpm.conf,php-fpm.d/www.conf,找到安装目录中bin文件夹下,找到对应的php-fpm.bak备份文件,复制一份生成对应文件(cp命令,一般可以新建到安装目录的sbin目录下), 安装目录/etc/目录下可以找到对应配置文件
    3. 其他的辅助项目:php-fpm建立快捷命令,自启动服务注册等等
Under linux, compile and install swoole
1. 下载源码
2. 进入源码目录,使用phpize命令(用于准备扩展库的编译环境,生成configure命令指令文件,一般在 `php根目录/bin/phpize`)
3. 此时源码目录中,会有configure文件,使用`./configure --with-php-config=PHP根目录/bin/php-config`指定你需要安装的php版本
4. 有错误的情况下,按照指示,安装好相关依赖(依赖源码编译,一般也是三联,cmake生成make指令文件,然后make && make install)。
5. 然后,编译二连:`make && make install`
6. 等待一定时间,编译后,找到php.ini, 开启扩展:添加 `extension=swoole.so`
7. 检查是否生效:`php -m|grep swoole`
Linux background running command
1. 使用 ==&== 字符:`command1 >> command1.log 2>&1 &`, 此时如果不关闭shell窗口,命令会一直在后台运行(其中2>&1是错误与正常的日志全部写入前面指定的文件)
2. 使用nohup+指令+&,后台运行并且忽略shell窗口信号:`nohup command1 >> command1.log 2>&1 &`;
3. (待查) 其他
Linux self-start management
  1. nginx service starts automatically

    • Use under centos 7.0
    1. To /etc/init.d/, establish the instruction file of the relevant self-starting service, refer to the work log in December
    2. chkconfig --add nginx
    3. chkconfig nginx on
    • For centos 7 and above, you can use systemctl to easily create services
    1. /usr/lib/systemd/system/nginx.servicecreate file first
    2. nginx.service file content, refer to https://www.cnblogs.com/piscesLoveCc/p/5867900.html :
    [Unit]
    Description=nginx
    After=network.target
      
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
      
    [Install]
    WantedBy=multi-user.target
    
    1. Description of file content:
    [Unit]:服务的说明
    Description:描述服务
    After:描述服务类别
    [Service]服务运行参数的设置
    Type=forking是后台运行的形式
    ExecStart为服务的具体运行命令(指令文件路径按自己系统的路径,这里只是参考)
    ExecReload为重启命令
    ExecStop为停止命令
    PrivateTmp=True表示给服务分配独立的临时空间
    注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
    [Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
    
    
    1. Overload systemctl configuration:systemctl daemon-reload
    2. Save the file and set it to start automatically at boot:systemctl enable nginx.service
    3. The corresponding command issystemctl start/stop/reload nginx.service
  2. php-fpm service starts automatically

    For centos7 and above, use systemctl for configuration services
    1. Open the pid file of php-fpm: modify the php-fpm.conf file (generally in the php installation directory /etc/php-fpm.conf), open the php-fpm.pid file path, and generally remove the pid = /var/run/php-fpm.pidprevious ;number.
    2. Create a file:/usr/lib/systemd/system/php-fpm.service
    3. document content:
    [Unit]
    Description=php-fpm
    After=syslog.target network.target
      
    [Service]
    Type=forking
    PIDFile=/var/run/php-fpm.pid
    ExecStart=/usr/local/php/sbin/php-fpm
    ExecReload=/bin/kill -USR2 $MAINPID
    ExecStop=/bin/kill -9 $MAINPID
    PrivateTmp=true
      
    [Install]
    WantedBy=multi-user.target
    
    1. Overload systemctl configuration:systemctl daemon-reload
    2. Save the file and set it to start automatically at boot:systemctl enable php-fpm.service
    3. Corresponding to use the command:systemctl start/stop/reload php-fpm.service
  3. Custom command autostart

    1. To use /etc/rc.d/rc.localthe file (need to increase the running permission chmod +x rc.local), you only need to add the steps that need to be self-started in the file.

Guess you like

Origin blog.csdn.net/qinmin1/article/details/103541585