Linux¶
概述¶
Linux 是一种开源的类 Unix 操作系统,包括许多不同的版本,诸如 CentOS、Ubuntu 等。
安装¶
下载 CentOS 或 Ubuntu 的 ISO 镜像。除了服务器,也可以安装在虚拟机上,比如 VMware。
远程连接¶
使用 XShell 可以通过 SSH(Linux 通常自带 SSH)远程连接 Linux 服务器。查看 SSH 状态:service sshd status
,如果没有,可以按照如下命令安装:
yum install openssh-server # 安装 SSH
vim /etc/ssh/ssh_config # 编辑配置文件
/bin/systemctl start sshd.service # 启动 SSH 服务
/bin/systemctl enable sshd.service # 开机自启动
大部分的远程连接(比如 MySQL 和 Redis)都支持 SSH,此时,SSH 需要配置为允许 TCP 连接:AllowTcpForwarding yes
。
镜像¶
国内可以修改软件服务镜像为 aliyun:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # base
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo # epel
yum clean all # 更新镜像
yum makecache # 创建缓存
目录结构¶
RPM 结构的目录结构通常设置如下:
- /etc: 配置文件
- /usr/bin: 可执行文件
- /usr/lib: 动态库
- /usr/share/doc: 用户文档
- /usr/share/man: 帮助文档
Get Started¶
Linux 是一个权限管理的多用户系统. 使用命令 su
从普通用户切换为 root 身份,使用命令 exit
以退出。
开发工具¶
安装常见的开发工具
yum -y groupinstall "Development tools"
yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tree dos2unix htop iftop iotop unzip telnet sl psmisc nethogs glances bc
System and Partitions¶
Each hardware device in Linux is regarded as a file. They are almost all under /dev directory.
Service¶
Relative commands are shown as follows:
/bin/systemctl start <service>
service <service> status
/bin/systemctl enable <service> # start at startup
User and Privilege¶
id
show idsuseradd
add a new userpasswd [username]
change password for users
Files and Directories Management¶
Path¶
Absolute paths start with the root path /, such as /usr/share/doc. But on the contrary, relative paths don't start with /, share/etc for example.
Commands¶
Use -help to list some options of the command or use man/info commands to show details, such as man cd. Following are some common commands.
Directory¶
cd
change directorypwd
print working directorymkdir
make a directory by a level. Append -p after the command if recursion is required.rmdir
remove an empty directory by a level. Append -p if recursion is required.
Operator¶
ls
listcp
copyrm
removemv
move
Text Document¶
cat
concatenate content of filetac
concatenate content in reverse directionnl
print with line numbersmore
print one page. Click Space to next page or Enter to next line.less
familiar tomore
head
defaults to the first 10 linestail
familiar tohead
Upload and Download¶
Install toolkit rz and sz by yum install lrzsz
. Then use commands rz
to upload or sz
to download. Target files will be upload to current directory.
Vim¶
Misc¶
Firewall¶
The service name is firewalld and the command is firewall-cmd.
Open the specific port when remote connections are refused.
FAQ¶
Pane is dead¶
If it occurs to Pane is dead when installing, open settings of hardwares and then change CD/DVD (IDE) connection to the path of the ISO file.
Connect to Internet¶
If failed, open settings of current network connection of the host and allow Internet Connection Sharing.
Static IP¶
Edit the /etc/sysconfig/network-scripts/ifcfg-ens33 file:
BOOTPROTO="static"
IPADDR=<ip>
NETMASK=255.255.255.0
GATEWAY=<gateway> # same as that of the host
DNS1=<dns1> # also same as those of the host
DNS2=<dns2>
参考¶
- Linux 教程 | 菜鸟教程
- 鸟哥的 Linux 私房菜.