2020年7月

  • 安装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也不再飙高了

  • 回退一个版本, 会删除本地最后一个版本(危险操作, 慎用)
git reset HEAD~1 && git reset --hard
  • 如果此刻再次执行git pull后, 会重新下载到最新的状态
  • 查看第N个提交的hash值, 当前值为1
vv=1;
git_hashcode=`git log -n $vv --pretty=format:"%H"`
v2=0;
for line in $git_hashcode
do
    declare -i v2=$v2+1;
    if [ "$v2" -eq "$vv" ]
    then
        echo $line;
    fi
done
  • 代理执行命令
git clone --config http.proxy="http://user:password@agent.com:1234"  https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

  • 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;

  • 安装 zsh 软件包和 git
CentOS: yum -y install zsh git
Ubuntu:  sudo apt -y install zsh git
  • 克隆 oh-my-zsh
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
  • 复制 .zshrc,修改命令提示符样式
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
ZSH_THEME="ys"
  • 修改 shell 类型
chsh -s /bin/zsh
[root@localhost ~]# chsh -s /bin/zsh
bash: chsh: 未找到命令
[root@localhost ~]# dnf -q provides '*/chsh'
util-linux-user-2.32.1-22.el8.x86_64 : libuser based util-linux utilities
仓库        :base
匹配来源:
文件名    :/etc/pam.d/chsh
文件名    :/usr/bin/chsh
文件名    :/usr/share/bash-completion/completions/chsh

通过上诉内容可以判断出, 软件包在util-linux-user中, 执行下面的安装就顺利安装好了
[root@localhost ~]# dnf install util-linux-user -y
[root@localhost ~]# chsh -s /bin/zsh
正在更改 root 的 shell。
shell 已更改。

注意: xshell客户端复制SSH渠道依旧是看到的依旧是原样, 需要重新连接就是zsh的shell了

# 如果需要改回去
➜  ~ bash
[root@localhost ~]# chsh -s /bin/bash
正在更改 root 的 shell。
shell 已更改
[root@localhost ~]# chsh -s /bin/bash
  • 如果不想修改, 可以通过执行zsh进入
[root@localhost ~]# zsh
➜  ~ 
  • 测试一下
➜  ~ lll
zsh: command not found: lll
修改配置
vi ~/.zshrc
添加下面内容
function lll(){
    (ls -la)
}
重载配置
source ~/.zshrc
执行自定义命令测试
➜  ~ lll
总用量 15128
dr-xr-x---.  8 root root    4096 7月   8 00:22 .
dr-xr-xr-x. 19 root root     250 7月   7 21:39 ..
...
  • 常用docker方法
function docker-exec() {
    (docker-compose exec $* bash)
    }
#重启docker 容器 修改yml文件后重载
function docker-reload() {
  (docker-compose down && docker-compose up -d $*)
}
#启动docker
function docker-start() {
  (docker-compose start $*)
}
#重启docker
function docker-restart() {
  (docker-compose restart $*)
}
#移除当前docker
function docker-remove(){
  (docker-compose down $*)
}
#构建启动docker
function docker-up() {
  (docker-compose up -d $* )
}
function docker-log() {
  (docker-compose logs $* )
}
#删除当前容器
function docker-rm(){
   (docker stop $1 | docker rm $1)
}
function docker-into(){
    (docker exec -it $* /bin/bash)
}