分类 linux 下的文章

  • 安装 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)
}

测试环境, centos8下通过yum install nginx安装的nginx, php7.3

  • 查询nginx配置, 获取可以执行脚本的目录
[root@localhost ~]# cat /etc/nginx/nginx.conf

...
root         /usr/share/nginx/html;
可以找到我们可以执行的默认目录为 /usr/share/nginx/html
  • 测试完结的目录文件状态
[root@localhost ~]# cd /usr/share/nginx/html
[root@localhost html]# ll -la
总用量 44
drwxr-xr-x. 2 root root   173 7月   6 12:00 .
drwxr-xr-x. 4 root root    33 7月   6 00:55 ..
-rw-r--r--. 1 root root  3971 10月  7 2019 404.html
-rw-r--r--. 1 root root  4020 10月  7 2019 50x.html
-rw-r--r--. 1 root root  4057 10月  7 2019 index.html
-rw-r--r--. 1 root root   368 10月  7 2019 nginx-logo.png
-rw-r--r--. 1 root root  4148 10月  7 2019 poweredby.png
-rw-r--r--. 1 root root   497 7月   6 03:25 publish_code.php
-rw-r--r--. 1 root root 12288 7月   6 03:26 .publish_code.php.swp
-rwxrwxrwx. 1 root root    20 7月   6 03:18 test_shell.sh
  • 编写用于发布的php脚本
[root@localhost html]# vim publish_code.php 
<?php
$cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
$cmd = str_replace(["../","./","/"],"",$cmd);
if(!$cmd) {
    die('参数不能为空');
}
echo $cmd;
echo "<pre>";
system('sh /usr/share/nginx/html/' . $cmd . '.sh', $status);
echo '</pre>';

if($status) {
    echo "成功";
} else {
    echo "失败";
}
  • 编写用于测试的shell脚本
[root@localhost html]# vim test_shell.sh 
#!/bin/bash
ls -la
  • 赋予脚本执行权限
chmod 777 test_shell.sh
  • 浏览器访问测试
[root@localhost html]# curl http://127.0.0.1/publish_code.php?cmd=test_shell
test_shell<pre>total 44
drwxr-xr-x. 2 root root   173 Jul  6 12:00 .
drwxr-xr-x. 4 root root    33 Jul  6 00:55 ..
-rw-r--r--. 1 root root 12288 Jul  6 03:26 .publish_code.php.swp
-rw-r--r--. 1 root root  3971 Oct  7  2019 404.html
-rw-r--r--. 1 root root  4020 Oct  7  2019 50x.html
-rw-r--r--. 1 root root  4057 Oct  7  2019 index.html
-rw-r--r--. 1 root root   368 Oct  7  2019 nginx-logo.png
-rw-r--r--. 1 root root  4148 Oct  7  2019 poweredby.png
-rw-r--r--. 1 root root   497 Jul  6 03:25 publish_code.php
-rwxrwxrwx. 1 root root    20 Jul  6 03:18 test_shell.sh
</pre>执行成功

  • 首先安装 EPEL 源:
yum install epel-release
  • 安装Remi存储库
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
  • 更新系统默认的php模块
dnf module reset php  #重置php模块
dnf module enable php:remi-7.3  #默认设置为remi-7.3版本
  • 安装php7.3及一些常用模块
yum -y install php php-mysqlnd php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-zip
  • 安装完成
[root@localhost yum.repos.d]# php -v
PHP 7.3.19 (cli) (built: Jun  9 2020 08:06:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.19, Copyright (c) 1999-2018, by Zend Technologies
  • 配置php.ini
vim /etc/php.ini

  • yum install 软件说不存在
安装Remi存储库
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
  • 安装htop
centos7
yum install epel-release -y
yum install htop -y

centos6
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
yum install htop -y

  • 查看指定端口的占用情况
➜  ~ lsof -i:8100
COMMAND   PID  USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
nginx    9622 nginx   10u  IPv4   1411667      0t0  TCP *:xprint-server (LISTEN)
nginx    9623 nginx   10u  IPv4   1411667      0t0  TCP *:xprint-server (LISTEN)
nginx    9624 nginx   10u  IPv4   1411667      0t0  TCP *:xprint-server (LISTEN)
  • 查看所有端口的占用情况
[root@localhost ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      894/sshd            
tcp6       0      0 :::80                   :::*                    LISTEN      2105/docker-proxy   
tcp6       0      0 :::22                   :::*                    LISTEN      894/sshd