标题命令
命令 | 功能 |
---|---|
hostname | 查看主机域名 |
rpm -qa | 查看Centos已经安装的软件包 |
ps -el | 查看所有进程 |
kill -9 pid | 关闭某个进程 |
systemctl restart network.service | 重启网络服务 |
systemctl status network.service | 查看网络服务状态 |
systemctl enable nfs-server.service | – |
service network restart | 重启网络服务 |
du -sh /tmp | 查看tmp文件夹空间大小 |
-touch file_name- | 创建文件 |
find / -name | 查找文件 |
gzip file_name | 使用gzip压缩 |
gunzip | 解压缩 |
gzip -d file_name | 解压缩 |
xz file_name | 使用xz对文件压缩 |
unxz | 解压缩 |
bzip2 | 使用bzip2对文件压缩 |
bunzip2 | 解压缩 |
tar -zcf file_name dir_name | 对文件夹打包并压缩 |
tar -zxf file_name | 解压缩包 |
mount /dev/sda1 /mnt/sda1 | 挂载分区 |
umount | 取消挂载 |
rpm -ivh *.rpm | 用rpm安装软件包 |
rpm -qa | 查看已安装软件包 |
rpm -e telnet | 删除telnet软件 |
yum install telnet* | yum安装telnet |
yum -y | 安装过程中全部“yes” |
yum update | 更新软件 |
yum list | 列出已安装软件 |
yum remove telnet | 删除telnet |
tar -zxvf file_name | 解压缩软件包 |
./configure | 运行配置脚本 |
make | 编译 |
make install | 安装 |
useradd user_name | 添加用户 |
-d | 指定用户家目录 |
usermod -d 目录 用户 | 修改用户家目录 |
passwd -l user_name | 锁定账户 |
passwd -u user_name | 解锁账户 |
userdel user_name | 删除账户 |
userdel -r user_name | 删除账户及所有相关文档 |
groupadd group_name | 添加用户组 |
gpasswd -a user_name group_name | 将用户添加到组中 |
gpasswd -d user_name group_name | 将用户从组中删除 |
groupdel group_name | 删除用户组 |
chmod 777 file_name | 更改文件权限 |
chown user_name file_name | 更改文件所有者 |
df -hT | 显示各分区使用情况 |
du -h /boot | 显示目录及子目录信息 |
hostname -i | 显示主机名对应的IP地址 |
ifconfig eth0 down | 关闭网卡 |
ifconfig eth0 up | 开启网卡 |
ifconfig eth0 IP地址 netmask 掩码 | 修改IP地址 |
netstat -antup | 显示所有网络连接 |
systemctl stop filewalld | 关闭防火墙 |
command & | 后台执行命令 |
firewall-cmd --permanent --add-port=1521/tcp | 添加tcp端口到防火墙 |
shutdown option time | 在指定的时间,执行某项操作 |
-h | 关机 |
-r | 重启 |
-c | 取消前一个关机命令 |
shutdown -h now | 立即关机 |
ip link show | 显示出所有可用网络接口的列表 |
ip link shou up | 查看激活的网络接口信息 |
ip -s link show eth0 | 查看更加详细的网络接口信息 |
ip link set 设备名 | |
ip link set eth0 up | 开启网卡 |
down | 关闭网卡 |
ip link set eth0 mtu 1480 | 更改网卡mtu |
ip link set eth0 name | 更改网卡名 |
ip link set eth0 address mac地址 | 更改网卡mac地址 |
ip addr show eth0 | 查看网络设备的协议地址等信息 |
ip addr add IP地址/24 dev eth0 | 添加IP地址到网卡 |
ip addr del IP地址/24 dev eth0 | 删除网卡的IP地址 |
– | – |
– | – |
– | – |
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
#更改yum镜像源
配置文件
文件 | 作用 |
---|---|
/etc/network | 网络配置 |
/etc/hostname | 主机域名 |
/etc/yum.repos.d/ | yum源 |
/etc/passwd | |
/etc/shadow | |
/etc/group | – |
/etc/exports | NFS服务配置 |
/etc/dhcp/dhcpd.conf | DHCP服务器配置 |
/etc/httpd/conf/httpd.conf | Apache配置文件 |
/etc/sysconfig/network-scripts/ifcfg-eth0 | 网卡配置文件 |
/etc/vsftpd/vsftpd.conf | vsftpd配置文件 |
– | – |
– | – |
– | – |
NFS服务器配置
命令 | 功能 |
---|---|
systemctl status nfs-server | 查看nfs-server的运行状态 |
systemctl status rpcbind | 查看rpcbind的运行状态 |
systemctl enable nfs-server rpcbind | 将服务设为开机启动 |
systemctl start nfs-server rpc-bind | 启动服务 |
vim /etc/exports | 编辑配置文件 |
showmount -e IP地址 | 列出共享目录 |
firewall-cmd --add-service=nfs --permanent | 将nfs-server添加到防火墙 |
firewall-cmd --add-service=rpc-bind --permanent | |
firewall-cmd --reload | 重新加载配置 |
mount IP地址:/share | 挂载 |
/etc/exports 配置
/server *(rw)
图片来自中国MOOC大学
配置DHCP服务器
命令 | 功能 |
---|---|
yum install dhcp | 安装DHCP服务 |
vim /etc/dhcp/dhcpd.conf | 编辑配置文件 |
systemctl start dhcpd | 启动DHCPD服务 |
systemctl stop firewalld | 关闭防火墙 |
– | – |
/etc/dhcp/dhcpd.conf 内容
subnet 192.168.1.0 netmask 255.255.255.0 {
#//网络地址和掩码
range 192.168.1.70 192.168.1.80;#//地址池
option domain-name-servers 180.76.76.76;#//默认DNS
option routers 192.168.1.1;#//默认网关
default-lease-time 86400;#//默认租期
}
host a{
#设置静态IP
hardware ethernet xx:xx:xx:xx:xx:xx ;
fixed-address 192.168.1.50;
}
Apache http服务器配置
命令 | 作用 |
---|---|
yum install httpd -y | yum 安装Apache |
firewall-cmd --add-service=http | 添加到防火墙 |
firewall-cmd --reload | 重新加载防火墙配置 |
systemctl enable httpd | 设置开机启动 |
- 将index.html文件复制到/var/www/html目录下(默认主页保存目录,默认主页为index.html)
- 配置文件:
/etc/httpd/conf #主配置文件目录,主配置文件里用include *.conf来包含从配置文件
/etc/httpd/conf.d #子配置目录
/etc/httpd/conf.modules.d #子配置目录
/var/log/httpd #httpd的日志存放目录
- 禁止浏览器查看主目录下文件列表
删除 httpd.conf 文件第114行的Indexs,就是将Options Indexes FollSymLinks中的indexes删掉 - 禁止指定IP访问网站
编辑 /etc/httpd/conf配置文件
找到图中的设置部分
上图表示网站主目录允许所有用户访问,在语句前面输入
<RequireAll>
Require not ip 192.168.10.1#逐条扫描配置
Require all granted #此句不能省略,因为默认拒绝所有主机访问
<RequireAll>
- 设置用户认证功能
打开 /etc/httpd/con 主配置文件
添加
AuthName "test" #名称可以任意设置
AuthType Basic #设置类型为基本类型
AuthUserFile "/htuwer" #设置用户文件,该文件用于存放可以访问HTTP的用户名和密码
<RequireAll>
Require valid-user#允许合法用户访问
<RequireAll>
执行以下命令创建可访问用户
htppasswd -c /htuser user1 #创建一个用户,并立即配置密码
- 添加虚拟目录
打开 /etc/httpd/con 主配置文件
Alias /user1 "/vdir"#带引号的为真实目录
<Directory "/vdir">
Require all granted
<Directory>
- 设置用户主页
使用vim 编辑配置文件
vim /etc/httpd/conf.d/userdir.conf
注释掉下面的语句即可打开功能
去掉下面语句的注释,既可以把用户的家目录下的主页设置为用户主页
useradd use1#新建用户
passwd user1#设置用户密码
chmod 711 /home/user1#开放所有用户的执行权限
mkdir public_html#创建用于存放主页的文件夹,并将主页复制到这里
- 虚拟主机的配置(用于提供多个web服务)
使用vim编辑配置文件
vim /etc/httpd/conf/httpd.conf
添加内容
(虚拟主机地位更高)
<VirtualHost *:80>#侦听80号端口,可以创建多个
DocumentRoot /var/www/html#设置虚拟主机网站子目录
ServerName 域名 #设置域名
</VirtualHost>#虚拟主机结束表示
<VirtualHost *:80>#第二个虚拟主机,第三台依次类推
DocumentRoot /var/www/html2
ServerName 域名 #设置域名
<Directory "/var/www/html2">
Require all granted
</Directory>
</VirtualHost>#虚拟主机结束表示
重启httpd
mkdir /var/www/html2#创建虚拟主机的页面保存目录
#复制主页文件到目录中
- PHP的安装
yum install php* #自动安装
systemctl restart httpd #重启httpd服务
Linux添加开机启动项
(1)编辑文件 /etc/rc.local
输入命令:vim /etc/rc.local 将出现类似如下的文本片段:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/etc/init.d/mysqld start #mysql开机启动
/etc/init.d/nginx start #nginx开机启动
/etc/init.d/php-fpm start #php-fpm开机启动
/etc/init.d/memcached start #memcache开机启动
#在文件末尾(exit 0之前)加上你开机需要启动的程序或执行的命令即可
#(执行的程序需要写绝对路径,添加到系统环境变量的除外),如:
/usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
(2)自己写一个shell脚本
将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。
Linux 网络配置
1 复制/etc/sysconfig/network-scripts/ifcfg-eth0文件到ifcfg-eth1
2 修改新的ifcfg-eth1文件的MAC地址,IP地址,设备名,删去UUID
3 执行 systemctl restart network 重启网络服务
DEVICE=eth0 #描述网卡对应的设备别名
BOOTPROTO=static #设置网卡获得ip地址的方式,选项可以为为static,dhcp或bootp
BROADCAST=192.168.44.255 #对应的子网广播地址
HWADDR="00:0C:29:6B:2E:7B" #对应的网卡物理地址
IPADDR=192.168.44.137 #只有网卡设置成static时,才需要此字段
NETMASK=255.255.255.0 #网卡对应的网络掩码
NETWORK=192.168.44.0 #网卡对应的网络地址,也就是所属的网段
ONBOOT=yes #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备
配置FTP服务器
命令 | 作用 |
---|---|
yum install vsftpd | |
firewall-cmd --add-service=ftp | 把vsftpd添加到防火墙 |
chmod 777 -R /var/ftp | 更改文件夹访问权限 |
setenforce 0 | 关闭SELINUX |
vim /etc/vsftpd/vsftpd.conf | 修改vsftpd配置文件 |
– | – |
对配置文件夹进行编辑
#允许匿名写入
anon_upload_enable=YES
anon_mkdir_write_enable=YES
#以下需要添加
anon_other_write_enable=YES
Windows 命令
route 192.168.0.0 mask 255.255.255.0 192.168.1.2