001 linux安装优化、bash概述、命令行介绍、命令结构、获取命令的帮助信息
基础介绍
主要介绍企业中常用的服务器操作系统
-
什么是Linux?
类似于windows,是一个服务器上使用的操作系统,Linux支持多用户,多进程,多CPU,多任务等功能,而且Linux是开源的,支持嵌入式等。
Linux发展史
1969年,美国贝尔实验室开发,Unix
- 优点:性能好
- 缺点:消耗资源大
1987年,谭宁邦开发微内核unix,主要用来教学
1991年,芬兰 林纳斯-托瓦丝 在大学期间基于unix微内核开发了第一款Linux内核,并且开源,并且很快加入FSF基金会,
Linux核心概念
FSF基金会,GPL通用公共协议:开源的公共协议
GNU
Linux的组成:Linux内核—>系统软件—>个人软件 GNU Linux
虚拟机介绍
-
网络类型
-
仅主机
只能跟宿主主机进行连接
-
桥接
共享宿主主机网卡,跟宿主主机处于同一个局域网
-
NAT
使用自己的虚拟网卡,有自己的一套网络
-
Linux发现版本
- RedHat/CentOS
- Ubuntu
- Debian
虚拟机软件
一般用来虚拟化一台主机的
- 虚拟机软件分类
- vmware workstation(个人使用,或者开发者使用)
- KVM一般用在云服务平台上
- ESXI部署在物理主机上
系统网络优化
- 解决网络下载软件慢的问题
- 解决系统软件升级的问题
- 安装一些常用的计算机软件
- 关闭一些不必要软件
- 防火墙
- selinux
修改系统下载源
# 第一步:备份原来源
mkdir /etc/yum.repos.d/backup/
mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/backup/
# 第二步:下载新的源
cd /etc/yum.repos.d
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
# 第三步:生成新的源的缓存
[root@localhost yum.repos.d]# yum cleanall
[root@localhost yum.repos.d]# yum makecache
# 第四步:更新系统
[root@localhost yum.repos.d]# yum update -y
# 第五步:安装常用的计算机软件
# 安装系统常用软件
[root@www yum.repos.d]# yum -y install tree nmap sysstat lrzsz telnet bash-completion vim lsof net-tools rsync ntpdate nfs-utils
# 第六步:关闭防火墙和Selinux
[root@localhost ~]# systemctl disable --now firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
#关闭SELINUX
1、临时关闭
[root@oldboy ~]# setenforce 0
setenforce: SELinux is disabled
2、永久关闭
[root@oldboy ~]# vim /etc/selinux/config
SELINUX=disabled
#稍微高级点的
[root@localhost ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
#关闭NetworkManager服务
[root@tecent_cloud ~]# systemctl stop NetworkManager
[root@tecent_cloud ~]# systemctl disable NetworkManager
# 第七步:拍摄快照
系统优化脚本
#!/bin/bash
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
cat >/etc/yum.repos.d/huawei_epel.repo<<EOF
[huawei_epel]
baseurl=https://repo.huaweicloud.com/epel/7/x86_64/
name="huawei"
enabled=1
gpgcheck=0
EOF
cat >/etc/yum.repos.d/nginx.repo<<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
yum clean all
yum makecache
yum update -y
yum -y install python-setuptools python-pip gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel zipqunzip ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssh openssl-develnss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced python wget lsof iptraf strace lrzsz kernel-devel kernel-headers pam-devel tcl tk cmake ncurses-devel bisonsetuptool popt-devel net-snmp screen perl-devel pcre-devel net-snmp screen tcpdump rsync sysstat man iptables sudo libconfiggit bind-utils tmux elinks numactl iftop bwm-ng net-tools expect
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
systemctl disable --now NetworkManage
systemctl disable --now firewalld
echo '#Timing synchronization time' >>/var/spool/cron/root
echo '0 */1 * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null' >>/var/spool/cron/root
cat >>/etc/sysctl.conf <<EOF
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
net.ipv4.ip_forward = 1
EOF
sysctl -p
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
systemctl restart sshd
systemctl disable abrt-ccpp.service
systemctl disable abrt-oops.service
systemctl disable abrt-vmcore.service
systemctl disable abrt-xorg.service
systemctl disable abrtd.service
systemctl disable accounts-daemon.service
systemctl disable atd.service
systemctl disable auditd.service
systemctl disable autovt@.service
systemctl disable avahi-daemon.service
systemctl disable bluetooth.service
systemctl disable cups.service
systemctl disable dbus-org.bluez.service
systemctl disable dbus-org.fedoraproject.FirewallD1.service
systemctl disable dbus-org.freedesktop.Avahi.service
systemctl disable dbus-org.freedesktop.ModemManager1.service
systemctl disable dbus-org.freedesktop.NetworkManager.service
systemctl disable dbus-org.freedesktop.nm-dispatcher.service
systemctl disable display-manager.service
systemctl disable dmraid-activation.service
systemctl disable firewalld.service
systemctl disable gdm.service
systemctl disable irqbalance.service
systemctl disable iscsi.service
systemctl disable ksm.service
systemctl disable ksmtuned.service
systemctl disable libstoragemgmt.service
systemctl disable libvirtd.service
systemctl disable lvm2-monitor.service
systemctl disable mcelog.service
systemctl disable mdmonitor.service
systemctl disable microcode.service
systemctl disable ModemManager.service
systemctl disable multipathd.service
systemctl disable NetworkManager-dispatcher.service
systemctl disable NetworkManager.service
systemctl disable postfix.service
systemctl disable qemu-guest-agent.service
systemctl disable rngd.service
systemctl disable rtkit-daemon.service
systemctl disable smartd.service
systemctl disable spice-vdagentd.service
systemctl disable systemd-readahead-collect.service
systemctl disable systemd-readahead-drop.service
systemctl disable systemd-readahead-replay.service
systemctl disable tuned.service
systemctl disable vgauthd.service
systemctl disable vmtoolsd.service
bash概述
bash(壳)是一个命令解释器,负责跟系统的内核进行交互,在操作系统的最外层
bash可以干什么?针对于操作系统做了一些操作
-
文件管理
-
目录管理
-
权限管理
-
用户管理
-
应用管理
-
软件管理
-
磁盘管理
-
等等
执行方式 操作简单 针对简单的管理操作
脚本script 操作复杂 操作一些复杂性较大的操作
命令行介绍
[root@localhost ~]# #表示超级用户管理员命令提示符,注释
[test@localhost ~] $普通用户命令提示符
[] #表示括号,没有其他的作用
root #本身是超级管理员 所在的位置是登录的用户
@ #表示分隔符
qls #表示主机名,是唯一的,也是可以修改的
~ #表示本身当时用户的家目录
变量 PS1 定义了命令行的结构
命令结构
命令的语法:
一条完整命令
命令 [选项] [参数]
command [options] [arguments]
[root@localhost ~]# ls #命令
1.txt 2.txt anaconda-ks.cfg a.txt
[root@localhost ~]# ls -l #命令+选项
total 12
-rw-r--r--. 1 root root 979 Dec 9 11:11 1.txt
-rw-r--r--. 1 root root 0 Dec 8 04:01 2.txt
-rw-------. 1 root root 1439 Dec 2 04:04 anaconda-ks.cfg
-rw-r--r--. 1 root root 5 Dec 9 09:13 a.txt
[root@localhost ~]# ls /root #命令+参数
1.txt 2.txt anaconda-ks.cfg a.txt
[root@localhost ~]# ls -l /root #命令+选项+参数
total 12
-rw-r--r--. 1 root root 979 Dec 9 11:11 1.txt
-rw-r--r--. 1 root root 0 Dec 8 04:01 2.txt
-rw-------. 1 root root 1439 Dec 2 04:04 anaconda-ks.cfg
-rw-r--r--. 1 root root 5 Dec 9 09:13 a.txt
1、中括号内的内容是可有可无的,选项和参数不是必须的
2、命令是指令的主体,是必须存在的
3、选项是用于调节命令的某个功能
引导短格式(单个字符) 以短横杠表示‘-’ 例如 -l
引导长格式(多个字符) 多个字符表示一定的含义 以‘--’表示 --all
多个短格式(多个字符) 每个字符都有一定的功能,‘-’ -al
4、参数是命令操作的对象 文件或者目录
5、指令、选项、参数两两之间必须要有一个空格
6、完整的命令、选项、参数之间不能有空格
7、命令的位置是在最前面的,是不能改变位置的
8、选项和参数的位置是可以发生改变的
获取命令的帮助信息
- man + 命令:详细的显示一个命令的使用方法
- help:查看一个命令的帮助信息,只能查看系统的内置命令(很少使用,不推荐)
- 命令 ----help:显示命令的选项帮助信息,有的命令不支持
- info:信息比较杂糅,查看说明信息,用的比较少
- 通过互联网的方式获取命令的帮助信息