Linux 学习
相关系统
- ubuntu
- redhat
- centOS
使用方向
- 企业服务器
- 嵌入式开发
特殊
- 区分大小写
- 一切皆文件
- 文件后缀名不重要
安装准备
- VirtualBox
- centOS 镜像文件
- 设置镜像地址
- iterm2 - ssh连接
本地网络设置
- 设置
/etc/sysconfig/network-scripts/ifcfg-enp0s3
中ONBOOT为yes - 重启网络
service network restart
- 设置
SSH学习
服务器安装SSH服务
yum install openssh-server
service sshd start
chkconfig sshd on
ssh连接服务器
1
ssh <username>@<IP address>
配置ssh链接
~/.ssh/config 文件中添加host "<name>" HostName <IP address> User <username> Port <port>
配置ssh密钥登陆
~/.ssh/config/authorized_keys
添加密钥修改ssh服务器端口号
/etc/ssh/sshd_config
中在Port部分添加或者修改端口号
常用命令
- 软件操作命令
- yum remove ~
- yum serach ~
- yum clean packages
- yum list
- yum info ~
- 服务器硬件资源信息
- 内存
free -m
- 硬盘
df -h
- 负载
w/top
0.6~0.7是正常健康值 - cpu个数
cat /proc/cupinfo
- 内存
- 文件操作命令
mkdir -p test1/test2/test3
rm -rf test1
- vim命令(菜鸟教程)
dd
删除整行gg
跳到文首G
跳到文尾u
撤销删除yy
复制p
粘贴
- 软件操作命令
权限
421 以二进制表示 如rwxr-x--x
则代表 (4+2+1) + (5) + (1) = 751文件读取
head
从头部查看tail
从尾部查看more
分页查看less
grep
模糊查找
文件查找
find -name
名称(* 模糊搜索)find -type
类型(d, f)find -ctime
时间限制
文件压缩和解压
tar -cf
压缩文件tar -tf
查看压缩文件内容tar -xf
解压文件tar -czf
压缩成gz格式tar -xzf
解压gz文件
用户操作
adduser <userName>
添加用户passwd <userName>
添加用户密码userdel -r <userName>
删除用户以及相关文件夹
防火墙
firewall-cmd
命令行操作提权操作
通过
visudo
进入到文件编辑,找到其中## Allows people in group wheel to run all commands
的部分,添加进相应的账号设置权限。获取文件
wget
curl
文件上传
scp <filename> <ipaddr>:<path>
文件下载
scp <ipaddr> <filename> <downloadpath>
Apache
yum install httpd
启动service httpd start
安装service httpd stop
结束ps -ef | grep httpd
查看启动的httpd相关的服务netstat -anpl |grep 'http'
查看http开放端口chown -R <userName>:<userName> <dirPath>
将某个文件夹权限赋予某个用户
安装好以后可能通过浏览器无法访问,此时可以将linux防火墙关闭后再试
设置虚拟主机
首先进入
/etc/httpd/conf
文件夹中,vim编辑httpd.conf
文件,添加1
2
3
4
5
6<VirtualHost *:<port>>
ServerName <serverName>
documentRoot <documentRoot>
Options Indexes FollowSymLinks
</VirtualHost>如果启动依旧报错,可以尝试运行
setenforce 0
,0为宽容模式,1为强制模式