防火墙相关
查看防火墙:
chkconfig iptables --list # centos 6
firewall-cmd --state # centos 7
永久关闭防火墙:
chkconfig iptables off # centos 6
# centos 7
systemctl stop firewalld.service # 停止防火墙
systemctl disable firewalld.service # 禁止开机启动
Debain 系列默认没有开启和安装防火墙
SSH 免密:
SSH 免密登录
在 .ssh 目录下输入如下命令然后回车四次
ssh-keygen -t rsa
使用
ssh-copy-id hostName
把生成的公钥复制到需要免密登录的服务器上
配置了免密的服务器注意要把公钥复制给自己一份, 免密登录自己.
主机名
修改主机名:
vim /etc/sysconfig/network CentOS/RedHat
vim /etc/hostname Ubantu/Debain
Hosts 文件
修改 host 映射
vim /etc/hosts
远程拷贝
远程拷贝:
scp localDir/localFile root@hostName:/remoteDir/remoteFile
时间相关:
date 查看当前系统时间
date -s 2009-05-07 修改日期,将日期设定成2009年5月7日
date -s 20:18:00 修改时间,将时间设定成下午8点18分0秒
clock -w 同步BIOS时钟,强制把系统时间写入CMOS
查看并卸载自带JDK
针对 CentOS 和 红帽发行版本:
rpm -qa | grep java
yum -y remove JDKVersion
针对 Ubuntu 和 Debain 发行版本:
sudo apt-get remove openjdk*
查看系统版本
lsb_release -a
即可列出所有版本信息:
安装 SSH 服务
apt install openssh-server openssh-client
启动:
/etc/init.d/ssh start
添加开机启动:
update-rc.d ssh enable
修改 /etc/ssh/sshd_config 配置允许 root 登录, 添加
PermitRootLogin yes
修改完 /etc/ssh/sshd_config 后需要重启 ssh 服务:
service sshd restart
SELinux 相关:
查看状态:
sestatus
关闭 SELinux:
vim /etc/selinux/config
将其设置为 disabled
系统升级:
CentOS , RedHat 系列:
sudo yum clean all
sudo yum update
Ubuntu, Debian 系列:
安装 htop:
CentOS ,RedHat:
先安装依赖
yum -y install epel-release
再安装 htop
yum -y install htop
Ubuntu, Debian:
暂无尝试, 鄙人用的 Debian 自带 htop
安装 iftop 网络监控
CentOS, RedHat
yum install epel-release
yum install iftop
Ubuntu, Debian:
apt install iftop
更换 yum 源
Centos , RHEL
先备份:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
后更换:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
最后生成缓存使其生效:
yum makecache
Ubuntu, Debian
暂无尝试
树莓派 Debian 10:
详情
nohup 后台运行
nohup command > outPut.log 2>&1 &
后台运行, 并把日志重定向到 outPut.log, 其中 2>&1 的含义为把标准错误输出也定向到标准输出, 最后一个 & 标识后台运行.
查看 mysql 状态:
如果添加了 mysqld 的服务的话,
service mysqld status
查看 mysqld 服务的开机启动情况:
chkconfig --list
关闭 mysqld 开机启动:
chkconfig --level 345 mysqld off
时间同步
同步某一个时间服务器
service ntpd status
ntpd cn.ntp.org.cn # cn.ntp.org.cn 是一个时间服务器