Linux 客户端修改主机名称
修改主机名称,例如把[root@localhost ~]# 修改为[root@centos-110 ~]#
第一步:使用root用户登录;
第二步:执行命令:hostnamectl set-hostname centos-110
第三步:执行命令以下两条命令,强制重新加载主机名
systemctl restart systemd-hostnamed.service
systemctl reboot
Linux 常用命令:
查看系统的ip地址:ip addr
虚拟机修改ip:cd /etc/sysconfig/network-scripts/
vim ifcfg-eth0 或 vim ifcfg-ens33
vim /etc/sysconfig/network-scripts/ifcfg-ens33
重启网络服务:service network restart
查看是否能联网:ping + ip
shell客户端远程登录: ssh root@192.168.1.128
进入某个目录,如 :cd /usr/local/
当前目录中: cd ./,进入上一级目录 cd ../
创建目录:mkdir /abc
创建多级目录:mkdir -p /tmp/zzq/test1/
查看磁盘占用:df
查看磁盘占用详情:df -lh
查看内存占用:
1、使用free命令查看内存;
2、通过top命令显示每个进程的内存实时使用率
3、使用ps命令显示各个进程的内存使用情况;
4、通过“/proc/meminfo”方法查看内存;
方式1:free
free 单位K
free -m 单位M
free -h 单位G
方式2:top
创建用户: useradd zzq
添加用户密码:passwd zzq
[root@localhost /]# useradd zzq
[root@localhost /]# password zzq
-bash: password: command not found
[root@localhost /]# passwd zzq
Changing password for user zzq.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
查看进程:ps -aux | grep 进程号
修改yum 源:
安装 wget:yum install wget -y
安装阿里 yum源 和 epel源wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
nginx 相关命令:
yum install nginx -y
启动应用 nginx:systemctl start nginx
关闭nginx:systemctl stop nginx
检查所有进程: ps -ef
检查nginx 的进程:ps -ef | grep nginx
过滤命令grep :搜索过滤信息的
管道符 |
查看nginx端口号: netstat -tunlp |grep nginx
当 netstat命令不能使用时 安装:yum install net-tools -y
查询nginx 安装位置:whereis nginx
防火墙命令:
查看防火状态:systemctl status firewalld
暂时关闭防火墙:systemctl stop firewalld
永久关闭防火墙:systemctl disable firewalld
重启防火墙:systemctl enable firewalld
永久关闭后重启:chkconfig iptables on
安装gcc:
yum install -y gcc gcc-c++
yum 运行时被锁解决:
rm -r /var/run/yum.pid
docker相关命令:
1.安装docker 工具包:
yum install -y yum-utils
2.设置镜像仓库:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.更新yum 软件包索引:
yum makecache fast
4.安装docker最新 社区版 ce:
yum install -y docker-ce docker-ce-cli containerd.io
5.docker 启动/停止/重启 :
systemctl start docker、
systemctl stop docker、
systemctl restart docker
5.1 查看docker 运行状态:
systemctl status docker
5.1 设置开机启动docker:
systemctl enable docker
6. 运行hello-world :
docker run hello-world
7. 查看镜像:
docker images
8.删除镜像:docker rmi 镜像id或名称
9.拉取镜像:docker pull 镜像名称:版本号
10.卸载docker:
10.1 卸载依赖:
yum remove docker-ce docker-ce-cli containerd.io
10.2 删除资源:
rm -rf /var/lib/docker
10.3 docker的默认工作路径:
/var/lib/docker
11. 查看正在运行中的docker实例:
docker ps
12.启动、重启、停止容器:
启动:
docker start 容器ID或容器名
停止:
docker stop 容器ID或容器名
13. 强制停止容器:
docker kill 容器ID或容器名
14. 删除已停止的容器:
docker rm 容器ID / docker rm -f 容器ID
15. 运行镜像:
docker run -it ubutu /bin/bash (前台交互式运行)
docker run -d ubutu /bin/bash (后台守护运行,此镜像需要交互,后台运行不适用)
docker run -d redis : 6.0.8 (后台守护运行,此镜像不需要交互,适用后台运行)
16.查看容器日志:
docker logs
17.查看容器内运行的进程:
docker top 容器ID
18.查看容器内部细节:
docker inspect 容器ID
19. 退出容器后 ,重新进入容器的两种命令:
docker exec -it 容器ID 、 docker attach 容器ID
两个命令的区别:attach 直接进入容器启动命令终端,不会开启新进程,会导致容器停止;
exec 在容器打开新的终端,会开启新进程,不会导致容器停止;(推荐使用exec)
20.从容器内拷贝文件到主机:
docker cp 容器ID :容器内文件路径 目标主机路径
21.备份容器成为镜像文件
docker export 容器ID > 文件名.tar
22.将备份的文件 还原成容器实例
redis 命令:
1.安装redis
首先安装gcc 依赖:npm install -y gcc ctl
redis命令:
启动: systemctl start redis
停止:systemctl stop redis
重启:systemctl restart redis
查看状态:systemctl status redis
Redis开机自启
1.新建一个系统服务文件: vi /etc/systemd/system/redis.service
2.配置文件内容如下
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /myredis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3.重载系统服务:systemctl daemon-reload
4. 执行命令:systemctl enable redis
mysql命令:
- 连接到MySQL服务器:mysql -u 用户名 -p 密码
mysql -u root -p123456