分类 linux 下的文章

假设访问页面地址为: http://www.abc.com/test.jsp

www.abc.com 域名解析到ip: 192.168.0.1 则curl访问方式为如下:

curl -H "Host:www.abc.com"  "http://192.168.0.1/test.jsp"
  • 实际测试http协议没问题, https协议就像下面一样了
[root@localhost ~]# curl -H "Host:wx.jiayuanshu.net"  "https://139.224.18.242"
curl: (60) Issuer certificate is invalid.
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
  • 解决办法, https时使用 --resolve 方法去实现
curl -H "Host:wx.jiayuanshu.net"  "http://139.224.18.242"
curl --resolve 139.224.18.242:443 "https://wx.jiayuanshu.net"

  • 安装EPEL源
yum install epel-release -y
  • 安装 REMI 源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
  • 安装 Yum 源管理工具
yum install -y yum-utils
  • 安装 PHP7.3
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll
  • 查看php版本
[root@xgblog ~]# php73 -v
PHP 7.3.20 (cli) (built: Jul  7 2020 07:53:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.20, Copyright (c) 1999-2018, by Zend Technologies
  • 加个软链, 方便自己
[root@xgblog bin]# which php73
/usr/bin/php73
打开到 /usr/bin/ 目录, ls -la 可以判断实际指向到/opt/remi/php73/root/usr/bin/php
# 创建软链
ln -s /opt/remi/php73/root/usr/bin/php /usr/bin/php
[root@xgblog bin]# php -v
PHP 7.3.20 (cli) (built: Jul  7 2020 07:53:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.20, Copyright (c) 1999-2018, by Zend Technologies
  • 重启php服务
systemctl restart php73-php-fpm
  • 确定9000端口被打开
[root@localhost ~]# netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN 
  • 编辑nginx配置文件, 参考下面的编辑方式
vim /etc/nginx/nginx.conf
>
server {
    listen       80;
    server_name  abc.de.com;
    root   /var/www/html;
    index  index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    access_log /dev/null;
    error_log  /dev/null;
    

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

# 下面的内容拷贝到对应的位置
    location ~ \.php {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;

        fastcgi_split_path_info  ^(.+\.php)(/.*)$;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include        fastcgi.conf;
    }
}
  • 设置php服务开机自启动
systemctl enable php73-php-fpm

# 更多php相关操作
systemctl restart php73-php-fpm #重启
systemctl start php73-php-fpm #启动
systemctl stop php73-php-fpm #关闭
systemctl status php73-php-fpm #检查状态

  • 通过top命令发现cpu消耗高的应用
top - 23:23:45 up 132 days,  3:18,  1 user,  load average: 2.50, 2.62, 2.67
Tasks: 455 total,   3 running, 452 sleeping,   0 stopped,   0 zombie
%Cpu(s): 22.5 us, 31.5 sy,  0.0 ni, 45.8 id,  0.2 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 15990752 total,   325208 free, 12212132 used,  3453412 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  2644488 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                                                                                  
 3945 root      20   0  108124  23420   3756 R 100.0  0.1   1:13.90 php                                                                                                                                                                                                      
 4056 root      20   0  108756  22204   3548 R 100.0  0.1   1:05.99 php     
  • 使用proc进入程序使用的数据目录
/proc/3945/cwd
  • 通过配置的env文件得出这个是一个消息推送的微服务
然后重启这个容器, 就好了, cpu也不再飙高了

  • demo1, 支持待空格的文件拷贝, 不支持目录拷贝
#!/bin/bash
mkdir old_version

copy_from=`pwd`;
copy_to=`pwd`/old_version/;
for file in $copy_from/*;
    do
        cp -rfavx "$file" "$copy_to";
    done
# cp -rf "/home/bash/testgit/git1/111 - 副本 (5).txt" "/home/bash/testgit/git1/old_version/"
# exit;