1. CentOS设置静态IP: 在 /etc/sysconfig/network-scripts 路径找到网卡文件,例如ens33文件。 TYPE=Ethernet DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp0s3 UUID=23b2b3e7-e6d5-4a6d-83b4-f6949392a486 DEVICE=enp0s3 添加以下信息: ONBOOT=yes #开机启动 BOOTPROTO=static #静态IP IPADDR=192.168.1.151 #本机地址 NETMASK=255.255.255.0 #子网掩码 GATEWAY=192.168.1.1 #默认网关 4. CentOS安装MySQL: wget http://repo.mysql.com/mysql57-community-release-el7.rpm rpm -ivh mysql57-community-release-el7.rpm yum install -y mysql-server Systemctl start mysqld Systemctl enable mysqld 查看默认密码: grep 'temporary password' /var/log/mysqld.log 5. VI或VIM编辑文件时设置序列号: :set number 关闭: :set nonumber 6. Docker删除镜像: docker images docker rmi 镜像名字 7. CentOS 7关闭防火墙: systemctl stop firewalld.service systemctl disable firewalld.service 8. CentOS关闭selinux: getenforce setenforce 0 永久关闭selinux: vi /etc/sysconfig/selinux SELINUX=enforcing 改为 SELINUX=disabled 重启服务器 9. CentOS修改主机名以及初始安装常用工具: hostnamectl set-hostname yours yum -y install epel-release && yum -y update && yum -y install wget tar net-tools lsof vim unzip git screen 10. CentOS查询端口及杀进程: netstat -nap kill -9 进程pid 11. CentOS安装PHP7.2: rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y install php72w yum -y install php72w-cli php72w-common php72w-devel php72w-mysql 12. 虚拟机Linux出现Host SMBus问题解决方法: 开机后在选择启动项界面,按上下键暂停启动,按e键进入编辑,在fi下一行,也就是linux16那行末尾,添加rd.break,然后按Ctrl+X进入救援模式。输入以下命令: mount -o remount ,rw /sysroot chroot /sysroot 输入pwd可查看当前所在目录。 cd /etc/modprobe.d vim blacklist.conf 或dccp-blacklist.conf 添加: blacklist i2c_piix4 blacklist intel_powerclamp exit reboot 13. MySQL数据库查看用户和添加新用户: 连接数据库: mysql -u root -p 查看数据库: mysql> show databases; 查看用户: mysql> use mysql; select host,user from mysql.user; 修改用户密码: 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:mysql> set password for root@localhost = password('123'); 创建用户: mysql> create user 'username'@'localhost' identified by 'password'; 删除数据库: mysql> drop database 数据库名; 14. 邮件服务器主机名设置: vi /etc/hosts 添加: 主机ip mail.example.com mail 再执行: echo 'mail' > /etc/hostname hostname -F /etc/hostname 查看主机名: hostname hostname -f 15. CentOS 7 修改系统时区: ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 命令解释: ln 建立链接 -s 表示建立的链接为软链接 -f 表示强制建立,替换原来的链接 /usr/share/zoneinfo/Asia/Shanghai 系统的预置时区文件,这里是亚洲/上海的时区 /etc/localtime 时区文件,可以使用zdump读取文件里的时区: zdump -v /etc/localtime 16. WordPress修改后台登录地址: 将下面的代码添加到当前主题的 functions.php 文件: //保护后台登录 add_action('login_enqueue_scripts','login_protection'); function login_protection(){ if($_GET['word'] != 'press')header('Location: https://lianghg.com/'); } 这样后台登录的唯一地址就是:https://lianghg.com/wp-login.php?word=press,如果不是这个地址,就会自动跳转到https://lianghg.com/ 17. HTML页面跳转(重定向): 以下方式在1秒内只刷新不跳转: 以下方式在1秒内跳转: 18. WordPress后台添加友情链接功能: 将以下代码添加到您当前主题的 functions.php 文件: //开启wordpress友情链接管理 add_filter( 'pre_option_link_manager_enabled', '__return_true' ); 接着在后台出现的链接选项中新建分类目录:友情链接 然后新添加的链接全部放在友情链接分类即可。 20. DD Debian 9: wget --no-check-certificate -O AutoReinstall.sh https://git.io/AutoReinstall.sh && bash AutoReinstall.sh 21. ubuntu 更换国内源: cd /etc/apt/ sudo cp -p sources.list sources.list.bak sudo vi sources.list deb http://mirrors.aliyun.com/ubuntu/ disco main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ disco main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ disco-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ disco-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ disco-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ disco-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ disco-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ disco-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ disco-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ disco-proposed main restricted universe multiverse ubuntu安装kvm: apt install qemu-kvm apt install qemu apt install virt-manager apt install virt-viewer apt install libvirt-bin apt install bridge-utils 打开: vim /etc/apt/sources.list 以Ubuntu 14.04.5 LTS为例,最后的效果如下: deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse ## Not recommended # deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse ubuntu 16.04 配置如下 deb http://mirrors.aliyun.com/ubuntu/ xenial main deb-src http://mirrors.aliyun.com/ubuntu/ xenial main deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe ubuntu 18.04(bionic) 配置如下 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse ubuntu 20.04(focal) 配置如下 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse 22. CentOS 7更换为阿里云源: 1、备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 3、生成缓存 yum makecache 23. CentOS和Ubuntu安装SS以及开机启动SS服务: CentOS: yum install -y python3-setuptools easy_install pip 或者 yum install python3-pip -y pip3 install shadowsocks Ubuntu: apt install python3-gevent python3-pip -y pip3 install shadowsocks apt install python3-m2crypto -y 接着: ssserver -h mkdir /etc/shadowsocks vim /etc/shadowsocks/config.json { "server":"0.0.0.0", "server_port":1095, "local_address":"127.0.0.1", "local_port":1080, "password":"liang123456", "timeout":300, "method":"aes-256-cfb", "fast_open":false, "workers": 1 } ssserver -c /etc/shadowsocks/config.json -d start 如果运行失败,那估计是OpenSSL升级到了1.1.0版本,需要手动修改Python目录下的openssl.py文件: 1、libcrypto.EVP_CIPHER_CTX_cleanup.argtypes = (c_void_p,)修改为: libcrypto.EVP_CIPHER_CTX_reset.argtypes = (c_void_p,) 2、libcrypto.EVP_CIPHER_CTX_cleanup(self._ctx)修改为: libcrypto.EVP_CIPHER_CTX_reset(self._ctx) CentOS开机启动: vim /etc/rc.local ssserver -c /etc/shadowsocks/config.json -d start chmod +x /etc/rc.local 24. MacOS X设置终端使用Socks5 Shadowsocks设置为:PAC自动代理模式 查看shadowsocks偏好设置,找到socks5监听端口。 以zsh作为说明,终端内输入命令: vim ~/.zshrc 添加如下代理配置,设置 proxy list: alias proxy='export all_proxy=socks5://127.0.0.1:1086' alias unproxy='unset all_proxy' :wq保存退出终端继续输入命令: source ~/.zshrc 本质上是添加了两个新的指令别名,设置结束。 使用代理: 使用proxy前终端内先查看下当前的ip地址: curl myip.lianghg.com 会显示当前真实IP地址。 终端内使用proxy命令设置代理: proxy curl myip.lianghg.com 会显示代理IP地址。 如要取消代理,终端内输入: unproxy curl myip.lianghg.com 25. Windows Server安装WSL 以管理员身份打开 PowerShell 并运行: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 具体过程: https://docs.microsoft.com/zh-cn/windows/wsl/install-on-server 26. 卸载WSL、重启WSL 卸载: wslconfig /l # 从列表中选择要卸载的发行版(例如Ubuntu)并键入命令 wslconfig /u Ubuntu 重启: net stop LxssManager net start LxssManager 27. 删除当前目录及子目录下的某一类文件 如要删除 .html结尾的文件: find . -name '*.html' -type f -print -exec rm -rf {} \; 28. CentOS修改内核启动顺序 1、查看现有内核: cat /boot/grub2/grub.cfg | grep menuentry 2、设置默认启动内核: grub2-set-default 'CentOS Linux (5.11.8-1.el7.elrepo.x86_64) 7 (Core)' 3、查看设置: grub2-editenv list 4、重启。 29. 删除CentOS内核 1、查看内核列表: rpm -qa | grep kernel 2、删除内核: rpm -e kernel-ml-5.2.11-1.el7.elrepo.x86_64 或 yum remove kernel-ml-5.2.11-1.el7.elrepo.x86_64 30. 删除宝塔绑定提示 sed -i "s|if (bind_user == 'True') {|if (bind_user == 'REMOVED') {|g" /www/server/panel/BTPanel/static/js/index.js rm -rf /www/server/panel/data/bind.pl 31. CentOS和Ubuntu安装桌面以及远程XRDP CentOS: yum -y install epel-release yum groupinstall "GNOME DESKTOP" -y yum -y install xrdp systemctl start xrdp systemctl enable xrdp Ubuntu: apt update apt install ubuntu-desktop -y或 apt install xubuntu-desktop -y apt install xrdp -y systemctl start xrdp systemctl enable xrdp 32. 修改主机名 Ubuntu: vim /etc/hostname 输入要修改的主机名,保存退出重启。 CentOS: hostnamectl set-hostname 你的主机名 重启。 33. 设置允许root用户登录 sudo -i passwd root 输入新的root密码 vim /etc/ssh/sshd_config # Authentication: PermitRootLogin yes //默认为no,需要开启root用户访问改为yes # Change to no to disable tunnelled clear text passwords PasswordAuthentication yes //默认为no,改为yes开启密码登陆 /etc/init.d/ssh restart