CentOS7中文目录换成英文目录
安装中文版的CentOS7之后,root目录和home目录下会出现中文的路径名,如“桌面”、“文档”、“图片”、“公共的”、“下载”、“音乐”、“视频”等目录,转换方法如下:
修改/etc/locale.conf文件内容如下:
cat /etc/locale.conf
LANG="en_US.UTF-8"
空杯心态,勿忘初心;但行好事,莫问前程。
安装中文版的CentOS7之后,root目录和home目录下会出现中文的路径名,如“桌面”、“文档”、“图片”、“公共的”、“下载”、“音乐”、“视频”等目录,转换方法如下:
修改/etc/locale.conf文件内容如下:
cat /etc/locale.conf
LANG="en_US.UTF-8"
lsof: list open files
可以列出被进程所打开的文件的信息。被打开的文件可以是
1.普通文件
2.目录
3.网络文件系统的文件
4.字符设备文件
5.(函数)共享库
6.管道,命名管道
7.符号链接
8.底层的socket字流,网络socket,unix域名socket
9.在linux里面,大部分的东西都是被当做文件的…
lsof常用使用说明:
1.列出所有打开的文件:
lsof
备注: 如果不加任何参数,就会打开所有被打开的文件,建议加上一下参数来具体定位
2. 查看谁正在使用某个文件
lsof /filepath/file
3.递归查看某个目录的文件信息
lsof +D /filepath/filepath2/
备注: 使用了+D,对应目录下的所有子目录和文件都会被列出
4. 比使用+D选项,遍历查看某个目录的所有文件信息 的方法
lsof | grep ‘/filepath/filepath2/’
5. 列出某个用户打开的文件信息
lsof -u username
备注: -u 选项,u其实是user的缩写
6. 列出某个程序所打开的文件信息
lsof -c mysql
备注: -c 选项将会列出所有以mysql开头的程序的文件,其实你也可以写成 lsof | grep mysql, 但是第一种方法明显比第二种方法要少打几个字符了
7. 列出多个程序多打开的文件信息
lsof -c mysql -c apache
8. 列出某个用户以及某个程序所打开的文件信息
lsof -u test -c mysql
9. 列出除了某个用户外的被打开的文件信息
lsof -u ^root
备注:^这个符号在用户名之前,将会把是root用户打开的进程不让显示
10. 通过某个进程号显示该进行打开的文件
lsof -p 1
11. 列出多个进程号对应的文件信息
lsof -p 123,456,789
12. 列出除了某个进程号,其他进程号所打开的文件信息
lsof -p ^1
13 . 列出所有的网络连接
lsof -i
14. 列出所有tcp 网络连接信息
lsof -i tcp
15. 列出所有udp网络连接信息
lsof -i udp
16. 列出谁在使用某个端口
lsof -i :3306
17. 列出谁在使用某个特定的udp端口
lsof -i udp:55
特定的tcp端口
lsof -i tcp:80
18. 列出某个用户的所有活跃的网络端口
lsof -a -u test -i
19. 列出所有网络文件系统
lsof -N
20.域名socket文件
lsof -u
21.某个用户组所打开的文件信息
lsof -g 5555
22. 根据文件描述列出对应的文件信息
lsof -d description(like 2)
23.根据文件描述范围列出文件信息
lsof -d 2-3
24. 列出COMMAND列中包含字符串" sshd",且文件描符的类型为txt的文件信息
lsof -c sshd -a -d txt
25.列出被进程号为1234的进程所打开的所有IPV4 network files
lsof -i 4 -a -p 1234
26. 列出目前连接主机peida.linux上端口为:20,21,22,25,53,80相关的所有文件信息,且每隔3秒不断的执行
lsof -i @peida.linux:20,21,22,25,53,80 -r 3
history:
# echo > .bash_history //清除保存的用户操作历史记录
# history -cw //清除所有历史
设置不保存history:修改/etc/profile将HISTSIZE=1000改成0或1
echo > /var/log/wtmp //清除用户登录记录
echo > /var/log/btmp //清除尝试登录记录
echo > /var/log/lastlog //清除最近登录信息
echo > /var/log/secure //登录信息
echo > /var/log/messages
echo > /var/log/syslog //记录系统日志的服务
echo > /var/log/xferlog
echo > /var/log/auth.log
echo > /var/log/user.log
cat /dev/null > /var/adm/sylog
cat /dev/null > /var/log/maillog
cat /dev/null > /var/log/openwebmail.log
cat /dev/null > /var/log/mail.info
echo > /var/run/utmp
释放内存缓存
内存缓存分 Page Cache 和 Buffer Cache。前者从硬盘读取的文件缓存,譬如 find 查找文件首次速度慢,而后就变快了。后者是 slab 分配器中的对象(Dentry 缓存、Inode 缓存)。为避免清除缓存引发可能的内存 Buffer 数据丢失,清除前先运行 sync 命令使数据写到硬盘。
同时清除两种类型缓存。如要选择性清除替换其中数字,1 表示 Page Cache,2表示 Buffer Cache。
sync && echo 3 > /proc/sys/vm/drop_caches
用 free -h 命令检查运行前后的内存 buff/cache 用量,available 表示剩余可用容量。
可以 crontab -e 添加定时释放内存缓存任务。例如每天凌晨 4 点运行一次。
0 4 * * * sync && echo 3 > /proc/sys/vm/drop_caches
CentOS7默认带的ssh版本是7.4p1存在远程代码执行漏洞,需升级至当前最新版OpenSSH_8.3解决,查看当前版本信息:
[root@c7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@c7 ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
快速升级步骤如下:
安装基础组件:
yum install gcc gcc-c++ openssl-devel autoconf automake zlib zlib-devel pcre-devel pam-devel rpm-build pam-devel telnet -y
卸载系统老版本openssh,备份配置文件
rpm -e --nodeps $(rpm -qa | grep openssh)
cp -r /etc/ssh/ /tmp/ssh
cd /etc/ssh/
rm /etc/ssh/* -rf
CentOS7的OpenSSL软件版本比较低,查看默认版本:
[root@c7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@c7 ~]# openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
升级到OpenSSL 1.1.1h最新版本步骤如下:
安装基础组件:
yum install gcc gcc-c++ autoconf automake zlib zlib-devel pcre-devel -y
下载解压编译安装openssl 可到官网查看最新版本
wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar xvf openssl-1.1.1i.tar.gz
./config shared --openssldir=/usr/local/openssl --prefix=/usr/local/openssl
make
make install
ngx_http_upstream_check_module模块可以为Tengine提供主动式后端服务器健康检查的功能。
该模块在Tengine-1.4.0版本以前没有默认开启,它可以在配置编译选项的时候开启:
--add-module=modules/ngx_http_upstream_check_module
编辑nginx.conf
http {
upstream cluster1 {
# simple round-robin
server 192.168.30.116:80;
#server 192.168.0.2:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
upstream cluster2 {
# simple round-robin
server 192.168.30.113:80;
server 192.168.30.114:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_keepalive_requests 100;
check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
location /1 {
proxy_pass http://cluster1;
}
location /2 {
proxy_pass http://cluster2;
}
location /status {
check_status;
access_log off;
allow SOME.IP.ADD.RESS;
deny all;
}
}
}
指令后面的参数意义是:
interval:向后端发送的健康检查包的间隔。
fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。
rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。
timeout: 后端健康请求的超时时间。
default_down: 设定初始时服务器的状态,如果是true,就说明默认是down的,如果是false,就是up的。默认值是true,也就是一开始服务器认为是不可用,要等健康检查包达到一定成功次数以后才会被认为是健康的。
type:健康检查包的类型,现在支持以下多种类型
tcp:简单的tcp连接,如果连接成功,就说明后端正常。
ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。
http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。
mysql: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。
ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。
port: 指定后端服务器的检查端口。你可以指定不同于真实服务的后端服务器的端口,比如后端提供的是443端口的应用,你可以去检查80端口的状态来判断后端健康状况。默认是0,表示跟后端server提供真实服务的端口一样。该选项出现于Tengine-1.4.0。
check_http_send http_packet:
该指令可以配置http健康检查包发送的请求内容。为了减少传输数据量,推荐采用"HEAD"方法。
当采用长连接进行健康检查时,需在该指令中添加keep-alive请求头,如:"HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"。 同时,在采用"GET"方法的情况下,请求uri的size不宜过大,确保可以在1个interval内传输完成,否则会被健康检查模块视为后端服务器或网络异常。
check_http_expect_alive: 该指令指定HTTP回复的成功状态,默认认为2XX和3XX的状态是健康的。
check_status:
显示服务器的健康状态页面。该指令需要在http块中配置。
在Tengine-1.4.0以后,你可以配置显示页面的格式。支持的格式有: html、csv、 json。默认类型是html。
你也可以通过请求的参数来指定格式,假设‘/status’是你状态页面的URL, format参数改变页面的格式,比如:
/status?format=html
/status?format=csv
/status?format=jsonfan
via:
http://tengine.taobao.org/document_cn/http_upstream_check_cn.html
Tengine是由淘宝网发起的Web服务器项目。它在Nginx 的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网 ,天猫商城 等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。
官网地址:http://tengine.taobao.org
步骤如下:
安装相关依赖包:
yum install gcc openssl-devel openssl openssl-devel -y
cd /opt
wget https://zlib.net/fossils/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make
make install
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar xvf pcre-8.44.tar.gz
cd pcre-8.42
./configure --prefix=/usr/local/pcre --libdir=/usr/local/lib/pcre --includedir=/usr/local/include/pcre
make
make install
安装Tengine,最新版本的Tegine可从官网 http://tengine.taobao.org 获取,使用nginx用户运行Tengine
rootkit是linux系统下常见一种木马后门程序,通过替换系统文件来达到隐藏和入侵的目的,攻击能力极强;
linux下容易被替换系统程序有login ls ps ifconfig du find nestat 等文件,其中login是最经常被替换的;因为linux登录,无论远程还是本地,都必须要启动/bin/login来收集并核对用户的账号和密码;系统管理员修改密码,攻击者还是可以登录系统的;
安装步骤初始需要的组件:
yum install wget gcc-c++ glibc-static -y
下载安装包:
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.md5
校验安装包:
md5sum -c chkrootkit.md5
chkrootkit.tar.gz: OK
CORS是一个W3C标准,全称是跨域资源共享(Cross-origin resource sharing)。它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制。
当前几乎所有的浏览器(Internet Explorer 8+, Firefox 3.5+, Safari 4+和 Chrome 3+)都可通过名为跨域资源共享(Cross-Origin Resource Sharing)的协议支持AJAX跨域调用。
Chrome,Firefox,Opera,Safari都使用的是XMLHttpRequest2对象,IE使用XDomainRequest。
简单来说就是跨域的目标服务器要返回一系列的Headers,通过这些Headers来控制是否同意跨域。跨域资源共享(CORS)也是未来的跨域问题的标准解决方案。
将老域名后导流到新域名:
需要将之前用的www.a.com域名的流量全部跳转到www.b.com
实现效果:比如访问 www.a.com/news/123.html自动跳到www.b.com/news/123.html
使用Nginx的rewrite命令实现:
server {
listen 80;
server_name www.a.com;
rewrite ^/(.*)$ http://www.b.com/$1 permanent;
其他配置省略...
}
curl是命令行下的网络传输客户端工具,支持包Http、Ftp在内的常见网络协议,支持代理,支持Https、证书,支持各种Http方法,在各发行版的Linux和Windows都支持,而且linux默认自带。其底层的C库libcurl也被很多脚本语言包括PHP(cURL)、Perl(Net::Curl,WWW::Curl)、Python(PyCurl)等打包成模块调用,可直接用于Web客户端编程,编写网络爬虫或者其他Web自动工具;
CentOS7默认的版本比较低7.29,在某些业务场景下需要升级,步骤如下:
1、创建repo文件
vim /etc/yum.repos.d/city-fan.repo
[CityFan]
name=City Fan Repo
baseurl=http://www.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch/
enabled=1
gpgcheck=0
或者直接安装libcurl源:
rpm -ivh http://mirror.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-2-1.rhel7.noarch.rpm
需要将/etc/yum.repos.d/city-fan.org.repo文件中的:enabled=0改为enabled=1
2、升级到最新稳定版本:
yum clean all
yum install epel-release -y #安装epel源
yum upgrade libcurl curl -y
3、查看版本号:
[root@fabrictest /]# curl -V
curl 7.69.1 (x86_64-redhat-linux-gnu) libcurl/7.69.1 NSS/3.44 zlib/1.2.7 libpsl/0.7.0 (+libicu/50.1.2) libssh2/1.9.0 nghttp2/1.31.1
Release-Date: 2020-03-11
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL UnixSockets
[root@fabrictest /]#
已经升级为最新版本了,当然也可以下载源码,编译安装,curl官网下载地址https://curl.haxx.se/download.html
curl更多用法参考:
https://www.ruanyifeng.com/blog/2019/09/curl-reference.html
http://www.ruanyifeng.com/blog/2011/09/curl.html
执行docker rmi $(docker images -aq)时出现:
Error response from daemon: conflict: unable to delete b023f9be0651 (must be forced) - image is referenced in multiple repositories
Error response from daemon: conflict: unable to delete b023f9be0651 (must be forced) - image is referenced in multiple repositories
Error response from daemon: conflict: unable to delete b023f9be0651 (must be forced) - image is referenced in multiple repositories
Error response from daemon: conflict: unable to delete 82098abb1a17 (must be forced) - image is referenced in multiple repositories
Error response from daemon: conflict: unable to delete c8b4909d8d46 (must be forced) - image is referenced in multiple repositories
Error response from daemon: conflict: unable to delete c8b4909d8d46 (must be forced) - image is referenced in multiple repositories
使用docker images ls查看发现相同的Image ID有两个不同的Tag,删除时须指定使用仓库加Tag才能删除,直接用IMAGE ID因为重复故不能删除;
docker rmi hyperledger/fabric-peer:latest
docker rmi hyperledger/xxxx:2.0.1
CentOS安装完毕后,默认的yum源是国外的,国内访问速度慢,需要切换为国内的源,这里选用的是阿里云的源,主要是因为镜像比较全,切换方法如下:
切换基本源为阿里云源:
先备份在切换:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
修改为外网地址
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
第三方源介绍:
EPEL是专门为RHEL、CentOS等Linux发行版提供额外rpm包的。很多os中没有或比较旧的rpm,在epel仓库中可以找到;
IUS只为RHEL和CentOS这两个发行版提供较新版本的rpm包。如果在os或epel找不到某个软件的新版rpm,软件官方又只提供源代码包的时候,可以来ius源中找,几乎都能找到。例如haproxy,在CentOS 6的epel中只有1.5版本的,但ius中却提供了1.6和1.7版本。
IUS源的站点根目录:https://dl.iuscommunity.org/pub/ius/。
IUS提供4个分支的rpm包:stable、archive、development和testing
Remi源中的软件几乎都是最新稳定版本;
安装第三方源epel
yum install -y epel-release
如果不能安装成功可以直接安装rpm包:
CentOS/RHEL 6
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
CentOS/RHEL 7
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
安装IUS仓库
CentOS 6
rpm -Uvh https://centos6.iuscommunity.org/ius-release.rpm
CentOS 7
rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm
安装REMI仓库:
CentOS/RHEL 6
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
CentOS/RHEL 7
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
最后修改/etc/yum.repos.d目录下的epel.repo、ius.repo、remi.repo文件中的第三方镜像地址为阿里云地址:
如下所示:
epel.repo
cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
ius.repo
[root@fabric yum.repos.d]# cat ius.repo
[ius]
name = IUS for Enterprise Linux 7 - $basearch
baseurl = https://mirrors.aliyun.com/ius/7/$basearch/
enabled = 1
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7
[ius-debuginfo]
name = IUS for Enterprise Linux 7 - $basearch - Debug
baseurl = https://mirrors.aliyun.com/ius/7/$basearch/debug/
enabled = 0
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7
[ius-source]
name = IUS for Enterprise Linux 7 - Source
baseurl = https://mirrors.aliyun.com/ius/7/src/
enabled = 0
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7
remi.repo
[root@fabric yum.repos.d]# cat remi.repo
# Repository: https://mirrors.aliyun.com/remi/
# Blog: http://blog.remirepo.net/
# Forum: http://forum.remirepo.net/
[remi]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch
#baseurl=https://mirrors.aliyun.com/remi/enterprise/7/remi/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror
mirrorlist=https://mirrors.aliyun.com/remi/enterprise/7/remi/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php55]
name=Remi's PHP 5.5 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=https://mirrors.aliyun.com/remi/enterprise/7/php55/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/php55/httpsmirror
mirrorlist=https://mirrors.aliyun.com/remi/enterprise/7/php55/mirror
# NOTICE: common dependencies are in "remi-safe"
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=https://mirrors.aliyun.com/remi/enterprise/7/php56/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/php56/httpsmirror
mirrorlist=https://mirrors.aliyun.com/remi/enterprise/7/php56/mirror
# NOTICE: common dependencies are in "remi-safe"
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-test]
name=Remi's test RPM repository for Enterprise Linux 7 - $basearch
#baseurl=https://mirrors.aliyun.com/remi/enterprise/7/test/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/test/mirror
mirrorlist=https://mirrors.aliyun.com/remi/enterprise/7/test/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-debuginfo]
name=Remi's RPM repository for Enterprise Linux 7 - $basearch - debuginfo
baseurl=https://mirrors.aliyun.com/remi/enterprise/7/debug-remi/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php55-debuginfo]
name=Remi's PHP 5.5 RPM repository for Enterprise Linux 7 - $basearch - debuginfo
baseurl=https://mirrors.aliyun.com/remi/enterprise/7/debug-php55/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php56-debuginfo]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 7 - $basearch - debuginfo
baseurl=https://mirrors.aliyun.com/remi/enterprise/7/debug-php56/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-test-debuginfo]
name=Remi's test RPM repository for Enterprise Linux 7 - $basearch - debuginfo
baseurl=https://mirrors.aliyun.com/remi/enterprise/7/debug-test/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
清空yum缓存
yum clean all
查看yum软件仓库列表
yum repolist
生成缓存
yum makecache
CentOS7.7默认gcc4.8版本比较低,在安装Python3.8、MySQL 8.0版本(8.0.16以上版本是C++14标准,需gcc 5.3以上版本)时不能安装,如果需要升级gcc至4.8或更高版本,建议直接采用安装SCL源之后安装devtoolset-6(devtoolset-6目前gcc版本为6.3),因为devtoolset-4及之前的版本都已经结束支持,只能通过其他方法安装;
采用CentOS的一个第三方库SCL(软件选集),SCL可以在不覆盖原系统软件包的情况下安装新的软件包与老软件包共存并且可以使用scl命令切换,不过也有个缺点就是只支持64位的。
确定当前gcc版本,执行命令:
gcc --version
gcc4.8快速升级方法如下:
1、安装scl源:
yum install centos-release-scl scl-utils-build -y
2、列出scl可用源:
yum list all --enablerepo='centos-sclo-rh' | grep "devtoolset-"
3、安装8版本的gcc、gcc-c++、gdb工具链(toolchian):(要哪个版本的就把命令中的数字8改成你要的主版本号就可以了。这样升级到的是最新的版本。例如8升级到的是8.3.1而不是8.2。)
yum install devtoolset-8-toolchain -y
scl enable devtoolset-8 bash #启动gcc8
gcc --version #查看版本号
[root@devops ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
通过scl命令启动gcc,这个只是暂时的,当你的shell关闭后或者重启就会恢复原来的版本,要想一直使用升级后的版本可以使用如下命令:
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
一台CentOS6.10机器忽然ping不通192.168.255.1网关,能ping通192.168.255.2的DNS服务器和同网段机器,192.168.254、10.254.254.x段的机器不通,公网也可以ping通;
后反复测试发现重启网络服务以后正常,当然重启机器也正常,但是20分钟以后故障会浮现,该机器已经运行180多天,一直很正常,重启后继续检查,步骤如下:
[root@hongsin-monitor ~]# dmesg | grep eth0
e1000 0000:02:00.0: eth0: (PCI:66MHz:32-bit) 00:50:56:be:17:a9
e1000 0000:02:00.0: eth0: Intel(R) PRO/1000 Network Connection
e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
eth0: no IPv6 routers present
e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
ADDRCONF(NETDEV_UP): eth0: link is not ready
ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
eth0: no IPv6 routers present
有网卡报错,继续检查
[root@hongsin-monitor ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:be:17:a9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
查看网卡配置文件
[root@hongsin-monitor ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:50:56:BE:17:A9
TYPE=Ethernet
UUID=690f4b51-36b8-405c-9d40-4f4d5bbfeaeb
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.255.209
NETMASK=255.255.255.0
GATEWAY=192.168.255.1
DNS1=192.168.255.2
将ifcfg-eth0文件中HWADDR地址修改成和70-persistent-net.rules文件中一致,为方便测试,直接重启机器,网关正常
20分钟后故障出现问题依旧;
最后定位到是vm网络里面有机器中病毒发起了arp攻击,解决如下:
获取正确的网关MAC地址后,使用网关IP到MAC的静态绑定
arp -s 192.168.255.1 00:00:5e:00:01:01
发送ARP包到网关
arping -U -I eth1 -s 192.168.255.209 192.168.255.1
恢复正常,当然最后还得找出发生ARP请求的机器进行处理。
清除登陆系统成功的记录
[root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信息
[root@localhost root]# last //此时即查不到用户登录信息
清除登陆系统失败的记录
[root@localhost root]# echo > /var/log/btmp //此文件默认打开时乱码,可查到登陆失败信息
[root@localhost root]# lastb //查不到登陆失败信息
清除历史执行命令
[root@localhost root]# history -c //清空历史执行命令
[root@localhost root]# echo > ./.bash_history //或清空用户目录下的这个文件即可
导入空历史记录
[root@localhost root]# vi /root/history //新建记录文件
[root@localhost root]# history -c //清除记录
[root@localhost root]# history -r /root/history.txt //导入记录
[root@localhost root]# history //查询导入结果
名词解释:
PV(Physical Volume) - 物理卷
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备
VG(Volume Group) - 卷组
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组
LV(Logical Volume) - 逻辑卷
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组
创建LVM步骤
添加新硬盘;
给新硬盘创建分区;
创建PV;
创建VG;
创建LV;
格式化LV;
挂载LV到指定目录;
在AWS上创建LVM步骤如下:
1、先在控制台上添加存储;
2、查看添加的硬盘,
[root@hongsinvm ~]# fdisk -l
Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/nvme0n1: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c7ec9
Device Boot Start End Blocks Id System
/dev/nvme0n1p1 * 2048 2099199 1048576 83 Linux
/dev/nvme0n1p2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
创建lvm 8e分区:
[root@hongsinvm ~]# fdisk /dev/nvme1n1
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x56ce9c54.
Command (m for help): o
Building a new DOS disklabel with disk identifier 0x98e04e99.
Command (m for help): p
Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x98e04e99
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-943718399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-943718399, default 943718399):
Using default value 943718399
Partition 1 of type Linux and of size 450 GiB is set
Command (m for help): p
Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x98e04e99
Device Boot Start End Blocks Id System
/dev/nvme1n1p1 2048 943718399 471858176 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/nvme1n1: 483.2 GB, 483183820800 bytes, 943718400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x98e04e99
Device Boot Start End Blocks Id System
/dev/nvme1n1p1 2048 943718399 471858176 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
重新读取分区
partprobe
创建PV
[root@hongsinvm ~]# pvcreate /dev/nvme1n1p1
Physical volume "/dev/nvme1n1p1" successfully created.
创建VG
[root@hongsinvm ~]# vgcreate datavg /dev/nvme1n1p1
Volume group "datavg" successfully created
创建LV
[root@hongsinvm ~]# lvcreate -l 100%free -n datalv datavg
Logical volume "datalv" created.
格式化LV
[root@hongsinvm ~]# mkfs.ext4 /dev/datavg/datalv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
29491200 inodes, 117963776 blocks
5898188 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2267021312
3600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
创建分区并挂载
[root@hongsinvm ~]# mkdir /data
[root@hongsinvm ~]# mount /dev/datavg/datalv /data/
[root@hongsinvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 17M 16G 1% /run
pfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.9G 16G 12% /
/dev/nvme0n1p1 1014M 265M 750M 27% /boot
tmpfs 3.1G 0 3.1G 0% /run/user/0
/dev/mapper/datavg-datalv 443G 73M 421G 1% /data
加入开机启动
[root@hongsinvm ~]# blkid
/dev/mapper/centos-root: UUID="2489f74a-946e-452a-bf62-1a1890668844" TYPE="xfs"
/dev/nvme0n1p2: UUID="c6AGGx-gtd0-N6XE-5qP2-phqY-V4Hr-BurxpM" TYPE="LVM2_member"
/dev/nvme0n1p1: UUID="75eb43ef-927b-4b24-af8e-bfc46bd0c2c2" TYPE="xfs"
/dev/mapper/centos-swap: UUID="9424b55f-2eb2-4156-b6ea-8d4bacf27d02" TYPE="swap"
/dev/nvme1n1p1: UUID="D0fh8n-ezI3-2Ork-bdAY-d0mE-R8eC-DrtDSy" TYPE="LVM2_member"
/dev/mapper/datavg-datalv: UUID="35c5eb3d-a7a0-4365-9ab9-91e1069c1d65" TYPE="ext4"
/dev/nvme1n1: PTTYPE="dos"
/dev/nvme0n1: PTTYPE="dos"
[root@hongsinvm ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Aug 13 06:35:13 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=75eb43ef-927b-4b24-af8e-bfc46bd0c2c2 /boot xfs defaults 0 0
UUID=35c5eb3d-a7a0-4365-9ab9-91e1069c1d65 /data ext4 defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
"/etc/fstab" 12L, 458C written
[root@hongsinvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 17M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.9G 16G 12% /
/dev/nvme0n1p1 1014M 265M 750M 27% /boot
tmpfs 3.1G 0 3.1G 0% /run/user/0
/dev/mapper/datavg-datalv 443G 73M 421G 1% /data
在 CentOS 7 中,引入了一个新的服务,Firewalld,一个信任级别的概念来管理与之相关联的连接与接口,支持 ipv4 与 ipv6,并支持网桥,采用 firewall-cmd (command) 或 firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则,并实时生效而无需重启服务。
安装firewalld:
yum install firewalld
如果需要图形界面的话,则再安装
yum install firewall-config
firewalld 存放配置文件有两个目录,/usr/lib/firewalld 和 /etc/firewalld,前者存放了一些默认的文件,后者主要是存放用户自定义的数据,所以我们添加的service或者rule都在后者下面进行。
server 文件夹存储服务数据,就是一组定义好的规则。
zones 存储区域规则
firewalld.conf 默认配置文件,可以设置默认使用的区域,默认区域为 public,对应 zones目录下的 public.xml
在执行命令时,如果没有带 --permanent 参数表示配置立即生效,但是不会对该配置进行存储,相当于重启服务器就会丢失。如果带上则会将配置存储到配置文件,,但是这种仅仅是将配置存储到文件,却并不会实时生效,需要执行 firewall-cmd --reload 命令重载配置才会生效。
一、常见命令:
启动, 停止, 重启firewalld
1、停止
systemctl stop firewalld.service
2、启动
systemctl start firewalld.service
3、重启
systemctl restart firewalld.service
4、查看状态:
systemctl status firewalld
5、禁止firewall开机启动
systemctl disable firewalld
6、设置开机启用防火墙:
systemctl enable firewalld.service
7、查看服务是否开机启动:
systemctl is-enabled firewalld.service
8、查看已启动的服务列表:
systemctl list-unit-files|grep enabled
9、查看启动失败的服务列表:
systemctl --failed
二、查看firewall规则与状态
1. 查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
firewall-cmd --state
2. 查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略)
firewall-cmd --list-all
3. 查看所有的防火墙策略(即显示/etc/firewalld/zones/下的所有策略)
firewall-cmd --list-all-zones
4. 重新加载配置文件
firewall-cmd --reload
三、配置firewalld-cmd
查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
四、设置firewall规则
1、对外暴露8000端口
firewall-cmd --permanent --add-port=8000/tcp
2、mysql服务的3306端口只允许192.168.1.1/24网段的服务器能访问
#添加规则
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.1/24" port protocol="tcp" port="3306" accept"
#reload使生效
firewall-cmd --reload
3、端口转发,将到本机的3306端口的访问转发到192.168.1.1服务器的3306端口
# 开启伪装IP
firewall-cmd --permanent --add-masquerade
# 配置端口转发
firewall-cmd --permanent --add-forward-port=port=3306:proto=tcp:toaddr=192.168.1.2:toport=13306
因为在/usr/lib/firewalld/services/中事先定义了ssh.xml的相应的规则
注意:如果不开启伪装IP,端口转发会失败;其次,要确保源服务器上的端口(3306)和目标服务器上的端口(13306)是开启的。
4、添加(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=80/tcp --permanent
5、重新载入(修改规则后使其生效)
firewall-cmd --reload
6、查看
firewall-cmd --zone= public --query-port=80/tcp
7、删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
8、开放指定端口(只允许指定IP访问)以“只允许192.168.1.1的主机连接3306端口”为例
firewall-cmd --add-rich-rule="rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="3306" accept" --permanent
firewall-cmd --reload
移除规则(只允许指定IP访问的端口)
以“移除只允许192.168.1.1的主机连接3306端口”为例
firewall-cmd --remove-rich-rule="rule family="ipv4" source address="192.168.1.1" port protocol="tcp" port="3306" accept" --permanent
firewall-cmd --reload
9、移除默认的ssh服务
移除默认的ssh服务前,先确认是否已经额外开放了22端口,否则会导致无法使用ssh远程连接。
firewall-cmd --add-rich-rule="rule family="ipv4" source address="192.168.255.55" port protocol="tcp" port="22" accept" --permanent #允许192.168.255.55的IP链接22端口
firewall-cmd --remove-service=ssh --permanent #移除默认的ssh服务
firewall-cmd --reload
10、其他常用命令
IP封禁
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.222' reject"
查看版本:firewall-cmd --version
查看帮助: firewall-cmd --help
查看状态: firewall-cmd --state
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
应急命令
firewall-cmd --panic-on # 拒绝所有流量,远程连接会立即断开,只有本地能登陆
firewall-cmd --panic-off # 取消应急模式,但需要重启firewalld后才可以远程ssh
firewall-cmd --query-panic # 查看是否为应急模式
via:
https://www.cnblogs.com/stulzq/p/9808504.html
https://www.cnblogs.com/straycats/p/10714257.html
https://www.cnblogs.com/tben/p/12144835.html
文件传输协议(File Transfer Protocol,FTP)是用于在网络上进行文件传输的一套标准协议,它工作在 OSI 模型的第七层, TCP 模型的第四层,即应用层,使用TCP传输而不是UDP,客户在和服务器建立连接前要经过一个“三次握手”的过程,保证客户与服务器之间的连接是可靠的, 而且是面向连接为数据传输提供可靠保证。
FTP服务一般运行在20和21两个端口。端口20用于在客户端和服务器之间传输数据流,而端口21用于传输控制流,并且是命令通向ftp服务器的进口。当数据通过数据流传输时,控制流处于空闲状态。而当控制流空闲很长时间后,客户端的防火墙会将其会话置为超时,这样当大量数据通过防火墙时,会产生一些问题。此时,虽然文件可以成功的传输,但因为控制会话,会被防火墙断开;传输会产生一些错误。
CentOS下安装:
yum install ftp -y
FileZilla客户端下载地址:https://filezilla-project.org/download.php?type=client
常见参数如下:
1. 连接ftp服务器
格式:ftp [hostname| ip-address]
a)在linux命令行下输入:
ftp 192.168.1.1
b)服务器询问你用户名和密码,分别输入用户名和相应密码,待认证通过即可。
2.列出文件列表以及切换目录
这部分其实和linux并无区别,分别是ls,和cd
列出目录列表 ls
切换当前目录 cd dir
3. 下载文件
下载文件通常用get和mget这两条命令。
a) get
格式:get [remote-file] [local-file]
将文件从远端主机中传送至本地主机中。
如要获取远程服务器上/usr/your/1.htm,则
ftp> get /usr/your/1.htm 1.htm
b) mget
格式:mget [remote-files]
从远端主机接收一批文件至本地主机。
如要获取服务器上/usr/your/下的所有文件,则
ftp> cd /usr/your/
ftp> mget *.*
此时每下载一个文件,都会有提示。如果要除掉提示,则在mget *.* 命令前先执行:prompt off
注意:文件都下载到了linux主机的当前目录下。比如,在 /usr/my下运行的ftp命令,则文件都下载到了/usr/my下。
c) 显示下载进度
默认情况下,下载是没有进度的,也就是说,只能瞎等着,啥也看不见。
ftp> hash
再进行传输,就能够显示下载进度了,以#号显示
4.上传文件
a) put
格式:put local-file [remote-file]
将本地一个文件传送至远端主机中。
如要把本地的1.htm传送到远端主机/usr/your,并改名为2.htm
ftp> put 1.htm /usr/your/2.htm
b) mput
格式:mput local-files
将本地主机中一批文件传送至远端主机。
如要把本地当前目录下所有html文件上传到服务器/usr/your/ 下
ftp> cd /usr/your
ftp> mput *.htm
注意:上传文件都来自于主机的当前目录下。比如,在 /usr/my下运行的ftp命令,则只有在/usr/my下的文件linux才会上传到服务器/usr/your 下。
5. 断开连接
bye:中断与服务器的连接。
ftp> bye
6.改变传输模式
ftp的传输模式有ascii模式和二进制模式
直接输入ascii则设置传输模式为ascii模式
ftp> ascii
直接输入binary则设置传输模式为binary模式
ftp> binary
该命令的语法格式如下所示:
ftp [-v] [-d] [–i] [-n] [-g] [-k realm] [-x] [-u] [host]
ftp命令主要选项说明
选项 说明
-d 启动调试模式
-u 关闭自动认证
-e 不记录历史指令
-i 关闭交互模式
-x 在成功认证之后,协商密钥
-n 关闭自动登录功能
-p 传输文件模式为被动模式
-v 程序运行时,显示详细的处理信息
-k realm 使用Kerberos v4认证时,从realm中得到信息
host FTP服务器的主机名/IP地址
在客户端访问FTP时,如果没有在命令行给出服务器的主机名或IP,则客户端将出现“ftp>”提示符,等待用户输入ftp内部命令
常见ftp内部命令及其说明
内部命令 说明
ls 显示服务器上的目录
get 从服务器下载指定文件到客户端
put 从客户端传送指定文件到服务器
open 连接ftp服务器
quit 断开连接并退出ftp服务器
cd directory 改变服务器的当前目录为directory
lcd directory 改变本地的当前目录为directory
bye 退出ftp命令状态
ascii 设置文件传输方式为ASCII模式
binary 设置文件传输方式为二进制模式
! 执行本地主机命令
cd 切换远端ftp服务器上的目录
cdup 上一层目录
close 在不结束ftp进程的情况下,关闭与ftp服务器的连接
delete 删除远端ftp服务器上的文件
get 下载
hash 显示#表示下载进度
mdelete 删除文件,模糊匹配
mget 下载文件,模糊匹配
mput 上传文件,模糊匹配
mkdir 在远端ftp服务器上,建立文件夹
newer 下载时,检测是不是新文件
prompt 关闭交互模式
put 上传
pwd 显示当前目录
FTP的命令行格式为:ftp -v -d -i -n -g [主机名],其中
-v显示远程服务器的所有响应信息;
-n限制ftp的自动登录,即不使用;
.n etrc文件;
-d使用调试方式;
-g取消全局文件名。
ftp使用的内部命令如下(中括号表示可选项):
1.![cmd[args]]:在本地机中执行交互shell,exit回到ftp环境,如:!ls*.zip.
2.$ macro-ame[args]:执行宏定义macro-name.
3.account[password]:提供登录远程系统成功后访问系统资源所需的补充口令。
4.append local-file[remote-file]:将本地文件追加到远程系统主机,若未指定远程系统文件名,则使用本地文件名。
5.ascii:使用ascii类型传输方式。
6.bell:每个命令执行完毕后计算机响铃一次。
7.bin:使用二进制文件传输方式。
8.bye:退出ftp会话过程。
9.case:在使用mget时,将远程主机文件名中的大写转为小写字母。
10.cd remote-dir:进入远程主机目录。
11.cdup:进入远程主机目录的父目录。
12.chmod mode file-name:将远程主机文件file-name的存取方式设置为mode,如:chmod 777 a.out。
13.close:中断与远程服务器的ftp会话(与open对应)。
14.cr:使用asscii方式传输文件时,将回车换行转换为回行。
15.delete remote-file:删除远程主机文件。
16.debug[debug-value]:设置调试方式,显示发送至远程主机的每条命令,如:deb up 3,若设为0,表示取消debug。
17.dir[remote-dir][local-file]:显示远程主机目录,并将结果存入本地文件local-file。
18.disconnection:同close。
19.form format:将文件传输方式设置为format,缺省为file方式。
20.get remote-file[local-file]:将远程主机的文件remote-file传至本地硬盘的local-file。
21.glob:设置mdelete,mget,mput的文件名扩展,缺省时不扩展文件名,同命令行的-g参数。
22.hash:每传输1024字节,显示一个hash符号(#)。
23.help[cmd]:显示ftp内部命令cmd的帮助信息,如:help get。
24.idle[seconds]:将远程服务器的休眠计时器设为[seconds]秒。
25.image:设置二进制传输方式(同binary)。
26.lcd[dir]:将本地工作目录切换至dir。
27.ls[remote-dir][local-file]:显示远程目录remote-dir,并存入本地文件local-file。
28.macdef macro-name:定义一个宏,遇到macdef下的空行时,宏定义结束。
29.mdelete[remote-file]:删除远程主机文件。
30.mdir remote-files local-file:与dir类似,但可指定多个远程文件,如:mdir *.o.*.zipoutfile
31.mget remote-files:传输多个远程文件。
32.mkdir dir-name:在远程主机中建一目录。
33.mls remote-file local-file:同nlist,但可指定多个文件名。
34.mode[modename]:将文件传输方式设置为modename,缺省为stream方式。
35.modtime file-name:显示远程主机文件的最后修改时间。
36.mput local-file:将多个文件传输至远程主机。
37.newer file-name:如果远程机中file-name的修改时间比本地硬盘同名文件的时间更近,则重传该文件。
38.nlist[remote-dir][local-file]:显示远程主机目录的文件清单,并存入本地硬盘的local-file。
39.nmap[inpattern outpattern]:设置文件名映射机制,使得文件传输时,文件中的某些字符相互转换,如:nmap $1.$2.$3[$1,$2].[$2,$3],则传输文件a1.a2.a3时,文件名变为a1,a2。该命令特别适用于远程主机为非UNIX机的情况。
40.ntrans[inchars[outchars]]:设置文件名字符的翻译机制,如ntrans 1R,则文件名LLL将变为RRR。
41.open host[port]:建立指定ftp服务器连接,可指定连接端口。
42.passive:进入被动传输方式。
43.prompt:设置多个文件传输时的交互提示。
44.proxy ftp-cmd:在次要控制连接中,执行一条ftp命令,该命令允许连接两个ftp服务器,以在两个服务器间传输文件。第一条ftp命令必须为open,以首先建立两个服务器间的连接。
45.put local-file[remote-file]:将本地文件local-file传送至远程主机。
46.pwd:显示远程主机的当前工作目录。
47.quit:同bye,退出ftp会话。
48.quote arg1,arg2…:将参数逐字发至远程ftp服务器,如:quote syst.
49.recv remote-file[local-file]:同get。
50.reget remote-file[local-file]:类似于get,但若local-file存在,则从上次传输中断处续传。
51.rhelp[cmd-name]:请求获得远程主机的帮助。
52.rstatus[file-name]:若未指定文件名,则显示远程主机的状态,否则显示文件状态。
53.rename[from][to]:更改远程主机文件名。
54.reset:清除回答队列。
55.restart marker:从指定的标志marker处,重新开始get或put,如:restart 130。
56.rmdir dir-name:删除远程主机目录。
57.runique:设置文件名唯一性存储,若文件存在,则在原文件后加后缀..1,.2等。
58.send local-file[remote-file]:同put。
59.sendport:设置PORT命令的使用。
60.site arg1,arg2…:将参数作为SITE命令逐字发送至远程ftp主机。
61.size file-name:显示远程主机文件大小,如:site idle 7200。
62.status:显示当前ftp状态。
63.struct[struct-name]:将文件传输结构设置为struct-name,缺省时使用stream结构。
64.sunique:将远程主机文件名存储设置为唯一(与runique对应)。
65.system:显示远程主机的操作系统类型。
66.tenex:将文件传输类型设置为TENEX机的所需的类型。
67.tick:设置传输时的字节计数器。
68.trace:设置包跟踪。
69.type[type-name]:设置文件传输类型为type-name,缺省为ascii,如:type binary,设置二进制传输方式。
70.umask[newmask]:将远程服务器的缺省umask设置为newmask,如:umask 3。
71.user user-name[password][account]:向远程主机表明自己的身份,需要口令时,必须输入口令,如:user anonymous my@email。
72.verbose:同命令行的-v参数,即设置详尽报告方式,ftp服务器的所有响应都将显示给用户,缺省为on.
73.?[cmd]:同help。
当作于管理进程时,pkill 命令和 killall 命令的用法相同,都是通过进程名杀死一类进程,该命令的基本格式如下:
[root@localhost ~]# pkill [信号] 进程名
表 1 pkill 命令常用信号及其含义
信号编号 信号名 含义
0 EXIT 程序退出时收到该信息。
1 HUP 挂掉电话线或终端连接的挂起信号,这个信号也会造成某些进程在没有终止的情况下重新初始化。
2 INT 表示结束进程,但并不是强制性的,常用的 "Ctrl+C" 组合键发出就是一个 kill -2 的信号。
3 QUIT 退出。
9 KILL 杀死进程,即强制结束进程。
11 SEGV 段错误。
15 TERM 正常结束进程,是 kill 命令的默认信号。
pkill命令踢出登陆用户
pkill [-t 终端号] 进程名
pkill -kill -t tty
或者pkill -9 -t tty
可以先用w命令查看当前在线用户,然后强制下线;