Loading... <h2>Linux一些重要的命令</h2> | :----: | ---- | | Vi快捷键 | 注释 | | :------: | ------------------------ | | dd | 删除光标所在行内容 | | ndd | 删除光标向下n行 | | yy | 复制当前行 | | p | 粘贴复制内容 | | u | 撤销修改 类似Ctrl+Z 回滚 | <h3>linux用户管理</h3> |:---- | ---- | |groupadd/del <组名>|添加删除用户名组| |useradd [-g -d] <用户名>|创建用户 -g指定组 -d指定home路径| |useradd [-r] <用户名>|删除用户 -r删除HOME目录| |id [用户名]|查看自己的所属组| |usermod -aG 用户组 用户名|将指定用户加入指定组| |getent passwd|用户名:密码:组id:描述:Home:bash| |getent group|组名称:组认证:组id| <h3>权限控制信息</h3> ls -l 可以以列表形式查看内容,并显示权限细节; |:---- | ---- | ---- | |语法:|**drwxr -xr-x 2 [1]root [2]root 37 15:07**|| |细则一|drwxr -xr-x |表示文件、文件夹的权限控制信息| |细则二|[1]root|表示文件、文件夹所属用户| |细则三|[2]root|表示文件、文件夹所属用户组| 细则一:drwxr -xr-x r - 查看文件 w - 修改文件 x - 执行文件 ![认知权限信息.jpg][1] <h3>修改权限控制-chmod</h3> > chmod u=rwx,g=rx,o=x hello.txt > chmod -R u=rwx,g=rx,o=x test -R即子文件 > 如果ls文件被标绿,即表示文件权限放太开,过于危险; <h3>权限数字符号</h3> > 0:--- > 1:--x > 2:-w- > 3:-wx > 4:r-- > 5:r-x > 6:rw- > 7:rwx > >>chmod 751 1.txt <h3>修改文件权限组-chwn命令</h3> > 语法:chown [-R] [用户1]{:}[用户组] > chown root hello.txt 将hello.txt所属用户修改为root > chown :root hello.txt 将hello.txt所属用户组修改为root > chown root: itheima hello.txt 将hello.txt所属用户修改成root > chown -R root test 将文件夹test的所属用户组修改为root并对子文件生效 <h3>linux各类好用的快捷键</h3> |:---- | ---- | |Ctrl + C|强制停止当前命令| |Ctrl + D|退出账号登陆| |history|历史命令搜索| |Ctrl + R|匹配历史命令| |Ctrl + A|到命令开头| |Ctrl + E|到命令结尾| |Ctrl + 键盘左右|以单词为单位| |Ctrl + l|同clear效果| <h3>软件篇</h3> Centos yum [-y] install|remove|search wget 通过yum命令安装wget程序 无可用软件包 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos7.repo yum -y install wget Ubantu apt install wget apt remove wget apt search wget <h3>Systemctl</h3> Systemctl说白就是通过命令 打开/关闭linux的软件,还有设置他们是否开机自启动; 随便认识一点linux内置的服务名称:NetworkManager(主网络服务)、Network(副网络服务)、firewalld(防火墙服务)、sshd、ssh(远程登陆服务). > 语法:ststemctl start|stop|status|enable(自启)|disable 服务名 <h3>软链接-快捷方式</h3> ln -s 被快捷方式的文件 快捷方式存放路径 <h3>时间管理</h3> 这里分校准时间和获取当前时间 我们可以在linux安装一个叫ntp的软件去获取北京时间 yum -y install ntp systemctl start ntpd ntpdate -u ntp.aliyun.com 获取当前时间 date "+%Y-%m-%d %H:%M:%S" <h3>IP地址及主机名</h3> 查看本机的IP地址以及网卡地址 yum -y install net-tools ifconfig hostname 查看主机名 hostnamectl set-hostname <主机名> 修改主机名 /etc/hosts <h3>固定ip</h3> cd /etc/sysconfig/network-scripts/ ls vim ifcfg-*** BOOTPROTO="dhcp" 改成 "static" 新增 IPADDR="" NETMASK="" GETWAY="" DNS1="" systemctl stop network systemctl start network <h3>测延迟、下载、查看网页</h3> ping [检查次数] ip/url wget [-b] url 下载、[-b]是否生成日志 tail -f wget-log 监控后台下载进度 curl [-o] url 查看网页,-o作用同wget <h3>虚拟端口</h3> yum -y install nmap 安装nmap查看所有端口占用情况 nmap 127.0.0.1 查看本机所有端口的占用情况 yum -y install net-tools 安装netstat查看指定端口占用情况 netstat -anp|grep 22 查看指定端口占用 有谁在连接 <h3>进程管理</h3> > ps [-e -f] 查看进程信息 -e全部 -f > ![ps -ef.png][2] > UID:进程所属用户ID | PID:进程号ID | PPID:启动此进程的其它进程 | C:CPU占用率 | TIME:占用CPU的时间 | CMD:进程名称或启动路径| > ![ps -ef grep tail.png][3] > ps -ef | grep tail 查询tail的占用情况 > kill [-9] 进程ID 关闭进程 -9为强制关闭进程 <h3>主机状态</h3> <h4>内存及进程状态</h4> > ![top内容详解.png][4] > top的细分命令 > -p 只显示某进程 > -d 设置刷新时间 > -c 显示产生进程的完整命令 > -n 指定刷新次数 top -n 3,刷新3次后退出 > -b 以日志形式保存 top > -i 不显示任何闲置(idel)或无用(zombie)进程 > -u 查找特定用户的进程 > 按键交互 F+空格选择显示项目、M键根据内存大小排序、P键按CPU百分比排序 > T根据累计使用时间排序,i键不显示闲置或无用进程 第一行:top - 1:14 当前时间,up 运行时间,user 用户登陆,load 1、5、15分钟负载 第二行:Tasks:进程数,running:子进程 sleeping:睡眠进程 zombie:僵尸进程 第三行:us用户CPU使用率、sy系统CPU使用率、ni高优先级进程占用CPU时间百分比,id空闲CPU率,wa io等待CPU占用率、hiCPU硬件中断率,siCPU软件中断率,st强制等待占用CPU率 第四行: total内存总量、free空闲内存、used使用内存、buff/cache缓存内存 <h3>环境变量</h3> > **一般方法** > Linux环境变量可以用户自行设置 > 临时生效:export 变量名=变量值; > 永久生效: > 针对当前用户生效:~/bashrc > 对全局用户生效:/etc/profile > cd ~ > vi ~/bashrc > export MYNAME=hahaha > :wq > echo $MYNAME > **PATH** > vi /etc/profile > export PATH=$PATH:/变量环境一:/变量环境二:/变量环境三 <h3>上传与下载</h3> yum -y install lrzsz sz <需下载的文件名> rz -窗口选择需上传的文件 <h3>压缩与解压</h3> 格式:zip,tar,gzip tar [-z以gzip -c创建压缩 -v查看进度 -x解压模式 -f -C解压目的地] tar -cvf test.tar 1.txt 2.txt 3.txt tar -xvf test.tar -解压到当前目录 tar -xvf test.tar -C /home/ 解压到home目录下(+Z是以gzip模式解压) <h3>MySQL数据库</h3> 5.7安装 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 /更新密钥/ rpm -Uvh http://repo.mysql.com/mysql57-community-release-el7-7.noarch.rpm /安装mysql yum/ yum -y install mysql-community-server 管理 systemctl start mysql -启动 systemctl enable mysqld -开机自启 systemctl status mysqld -检查运行状态 cat /var/log/mysqld.log | grep "temporary password" -查看初始密码 mysql -uroot -p -登陆账户\ set global validate_password_policy=LOW; #密码安全等级最低 set global validate_password_length=4; #密码最低长度 ALTER USER 'root'@'localhost' IDENTIFIED BY '密码'; #修改密码 grant all privileges on *.* to root"全局% & ip" identified by '远程登陆密码' with grant option;n; -远程登陆 flush privilegesl; -刷新权限,生效 exit & Ctrl + d -退出控制台 netstat -anp | grep 3306; -检查3306端口是否开启 Mysql8.0安装&配置 rpm -Uvh http://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm grep 'temporary password' /var/log/mysqld.log set global validate_password_policy=0; create user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码'; -首次配置远程登陆 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码'; -远程登陆密码修改 <h3>NginX建站环境</h3> > **下载环境搭建** > yum install -y yum-utils 安装yum依赖程序 > cd /etc/yum.repos.d/ 手动添加nginx的yum仓库 > pwd > ls -l > vi nginx.repo > [nginx-stable] > name=nginx stable repo > baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ > gpgcheck=1 > enabled=1 > gpgkey=https://nginx.org/keys/nginx_signing.key > module_hotfixes=true > > [nginx-mainline] > name=nginx mainline repo > baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ > gpgcheck=1 > enabled=0 > gpgkey=https://nginx.org/keys/nginx_signing.key > module_hotfixes=true > **Nginx环境搭建** > yum install -y nginx > systemctl start/stop/status/enable/disable nginx > firewall-cmd --add-port=80/tcp --permanent > firewall-cmd --reload > netstat -anp | grep 80 > > > <h3>DNS域名解析</h3> > > yum install -y unbound* bind-u > yum install -y vim* > cd /etc/unbound/ > > vim unbound.conf > interface: 0.0.0.0 监听接口 > access-control: 0.0.0.0/0 allow 允许/禁止自定义用户服务 > msg-cache-size: 4m 缓存大小 > username: "" 允许任何用户访问 > module-config: "iterator" 禁用DNSSEC验证,实现外网地址转发 > forward-zone: #递归查询 > name:"." > forward-addr:8.8.8.8 > unbound-checkconf > > firewall-cmd --permanent -add-service=dns > firewall-cmd --reload > > 正向查询及反向查询 > cd local.d > vim my.conf > local-data:"www.abc.com IN A 10.0.0.1" > local-data-ptr:"10.0.0.1 www.abc.com" > local-data"www.abc.com NS 10.0.0.1" > sudo unbound-control reload 重置配置文件 > systemctl restart unbound > > nslook link/ip 本机dns应指向本机unbound > <h3>建立邮件服务器</h3> > >> SMTP 未加密使用25端口,加密时使用465端口; >> POP3 未加密使用110端口,加密时使用995端口; >> IMAP4未加密使用143端口,加密时使用993端口; >> ![mail.png][5] >> rpm -qa | grep postfix >> hostnamectl --static set-hostname mail.dyzx.edu >> #配置unbound.conf >> vim /etc/unbound/unbound.conf >> systemctl enable --now unbound >> do-ip4:yes >> local-zone:"dyzx.edu."static >> #正向解析 >> local-data:"dyzx.ed. 86400 IN SOA ns.dyzx.edu. root.dyzx.edu 200 3600 1800 7200 86400" >> local-data:"ns.dyzx.edu. IN A 192.168.8.10" >> local-data:"dyzx.edu. IN MX 5 mail.dyzx.edu." >> local-data"mail.dyzx.edu. IN A 192.168.8.10" >> #配置postfix main.cf >> vim /etc/postfix/main.cf >> myhostname = mail.dyzx.edu (域名) >> mydomain = dyzx.edu >> myorigin = $mydomain >> inet_interfaces = all >> mydestination = $myhostname,locahost.$mydomain,locahost,$mydomain 允许接收的邮件域的域名 >> mynetworks = 192.168.0.0/16 允许发送邮件的客户端IP >> relay_domains = $mydestination 允许中转的本地或远程邮件域 >> home_mailbox = Maildir/ mailbox储存位置 >> postfix check 检查语法是否存在错误 >> #邮箱账号管理 >> groupadd stu_mail //创建邮箱组 >> adduser -g stu_mail -s /sbin/nologin mai >> passwd mai >> #防火墙设置 >> setsebool -P allow_postfix_local_write_mail_spool on >> firewall-cmd --permanent --add-service=dns >> firewall-cmd --permanent --add-service=smtp >> firewall-cmd --reload >> vim /etc/resolv.conf >> #telnet环境搭建 >> rpm-qa telnet-server/xinetd 检查是否安装 >> yum -y install telnet-server >> yum -y install telnet >> yum -y install xinetd >> systemctl enable xinetd.service >> systemctl enable/start telnet.socket >> systemctl start xinetd >> firewall-cmd--permanent--add-port=23/tcp >> firewall-cmd--reload >> #telnet发信测试 >> telnet mail.dyzx.edu 25 >> HELO localhost >> MAIL FROM: zhang@dyzx.edu 告知发件人地址 >> RCPT TO:li@dyzx.edu 告知收件人地址 >> DATA 告知服务器将开始传输数据 >> Subject: the first Mail 标题 >> hello,erver body! 内容 >> . 结束 >> quit 结束本次会话 >> #查看Mailbox内的邮件 >> ls /home/user/Maildir/new >> cat **/Maildir/new/****.****.mail.dyzx.edu >> #安装Dovecot做邮件接收 >> yum -y install dovecot >> vim /etc/dovecot/dovecot.conf >> protocols = imap pop3 lmtp >> listen = * >> login_trusted_networks = 192.168.0.0/16 >> vim /etc/dovecot/conf.d/10-mail.conf >> mail_location = maildir:~/Maildir >> firewall-cmd --permanent --zone=public --add-port={110/tcp,143/tcp} >> firewall-cmd --reload >> systemctl enable --now dovecot >> #放行端口予客户端使用 >> firewall-cmd --permanent --zone=public --add-port={25/tcp,110/tcp} >> firewall-cmd --reload >> > > [1]: https://qqclwy.com/usr/uploads/2023/11/1925565426.jpg > [2]: https://qqclwy.com/usr/uploads/2023/11/845560289.png > [3]: https://qqclwy.com/usr/uploads/2023/11/1549696980.png > [4]: https://qqclwy.com/usr/uploads/2023/11/3285625280.png > [5]: https://qqclwy.com/usr/uploads/2023/11/1786015030.png 最后修改:2023 年 12 月 10 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏