linux常用指令(centos)
2023-05-10 00:23:56 0 举报
AI智能生成
linux常用指令(centos)
作者其他创作
大纲/内容
命令
ssh
生成密钥
ssh-keygen -t rsa
centos免密码登录authorized_keys需要600权限
通信其他服务器
ssh-copy-id -i ~/.ssh/id_rsa.pub root@要拷贝到的机器ip
增加用户
创建用户
adduser hdfs
密码
passwd
授权 /etc/sudoers
sudo
linuxidc ALL=(ALL) ALL #这个是新增的用户
免密 sudo
linuxidc ALL=(ALL) NOPASSWD: ALL
删除用户
userdel -r username
SELinux
getenforce
/usr/sbin/sestatus -v
临时关闭
setenforce 0
永久关闭
vi /etc/selinux/config
防火墙
临时关闭防火墙
systemctl stop firewalld
systemctl stop firewalld
永久防火墙开机自关闭
systemctl disable firewalld
systemctl disable firewalld
临时打开防火墙
systemctl start firewalld
systemctl start firewalld
防火墙开机启动
systemctl enable firewalld
systemctl enable firewalld
查看防火墙状态
systemctl status firewalld
systemctl status firewalld
nginx
设置开机启动
sudo systemctl enable nginx
启动服务
sudo systemctl start nginx
停止服务
sudo systemctl restart nginx
重新加载,因为一般重新配置之后,不希望重启服务,这时可以使用重新加载。
sudo systemctl reload nginx
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
sudo systemctl enable nginx.service
mysql
rpm -qa | grep mysql
yum remove mysql
rpm -ivh mysql-community-release-el7-5.noarch.rpm
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum localinstall mysql57-community-release-el7-11.noarch.rpm
yum install glibc.i686
yum install mysql-server
MySQL GPG 密钥已过期导致
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install -y mysql-community-server --nogpgcheck
service mysqld restart
systemctl enable mysqld
root用户密码
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
修改密码
set password for 'root'@'localhost'=password('MyNewPass4!');
update set 语句修改密码
use mysql;
update user set password=PASSWORD('MyNewPass5!') where user='root';
flush privileges;
update user set password=PASSWORD('MyNewPass5!') where user='root';
flush privileges;
mysql> update user set host='%' where user='root';
mysql> flush privileges;
mysql> flush privileges;
远程用户连接
GRANT ALL PRIVILEGES ON *.* TO 'zhangsan'@'%' IDENTIFIED BY 'Zhangsan2018!' WITH GRANT OPTION;
子主题
创建用户
CREATE USER ‘username‘@‘host‘ IDENTIFIED BY ‘password‘;
修改验证密码策略
SET GLOBAL validate_password_policy=LOW;
SHOW VARIABLES LIKE 'validate_password%';
设置默认编码为 utf8
修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
默认配置文件
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
挂载硬盘
磁盘挂载
fdisk -l
磁盘分区
fdisk /dev/sdb
# Command (m for help): n //输入N表示新建一个分区
# Command (m for help): w //保存分区
# Command (m for help): w //保存分区
用mkfs.ext3格式化新分区
mkfs.ext3 /dev/sdb
挂载使用
$ mkdir /mnt/hdb1 //新建一个挂载点。
$ mount /dev/hdb1 /mnt/hdb1 //挂载。
$ df -h
$ mount /dev/hdb1 /mnt/hdb1 //挂载。
$ df -h
查看挂载uid
lsblk -f
开机使用
开机自动挂载
在vi /etc/fstab中添加新硬盘的挂载信息,添加下面一行:
/dev/hdb1 /mnt/hdb1 ext3 defaults 1 2(如果还有一个分区就是1 3,以此类推)
这样,每次开机后,系统会自动将/dev/hdb1挂载到/mnt/hdb1
在vi /etc/fstab中添加新硬盘的挂载信息,添加下面一行:
/dev/hdb1 /mnt/hdb1 ext3 defaults 1 2(如果还有一个分区就是1 3,以此类推)
这样,每次开机后,系统会自动将/dev/hdb1挂载到/mnt/hdb1
yum源加速
安装base reop源
备份旧源
cd /etc/yum.repos.d
sudo mv CentOS-Base.repo CentOS-Base.repo.bak
sudo mv CentOS-Base.repo CentOS-Base.repo.bak
修改为阿里源
sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安装epel repo源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
刷新缓存
yum clean all
yum makecache
yum makecache
docker
vi /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
systemctl restart docker.service
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
systemctl restart docker.service
yum -y install docker
systemctl restart docker.service
systemctl restart docker.service
jenkins
docker pull jenkins
docker images | grep jenkins 查看jenkin镜像是否下载成功
docker images | grep jenkins 查看jenkin镜像是否下载成功
mkdir /home/jenkins_home
chown /home/jenkins_home/ 1000:1000 jenkins_home
chown /home/jenkins_home/ 1000:1000 jenkins_home
docker run -d --name myjenkins -p 50000:8080 -v /home/jenkins_home:/home/jenkins_home jenkins 创建容器并启动
docker ps | grep jenkins 查看是否映射成功
docker ps | grep jenkins 查看是否映射成功
安装启动 Jenkins 容器
docker run -d --name jenkins -p 8081:8080 -v /data/jenkins_home:/var/jenkins_home jenkins/jenkins:lts;
备注:
-d //启动在后台
--name //容器名字
-p //端口映射(8081:宿主主机端口,8080:容器内部端口)
-v //数据卷挂载映射(/data/jenkins_home:宿主主机目录,另外一个即是容器目录)
enkins/jenkins:lts //Jenkins镜像(最新版)
备注:
-d //启动在后台
--name //容器名字
-p //端口映射(8081:宿主主机端口,8080:容器内部端口)
-v //数据卷挂载映射(/data/jenkins_home:宿主主机目录,另外一个即是容器目录)
enkins/jenkins:lts //Jenkins镜像(最新版)
docker run -d --name myjenkins -p 3927:3927 -p 19362:19362 -v /data/home/jenkins:/data/home/jenkins docker.io/jenkins:latest
docker ps 查看容器
docker exec -i -t 容器的id或者容器名字 /bin/bash 进入容器
cat /var/jenkins_home/secrets/initialAdminPassword 查看密码
docker exec -i -t 容器的id或者容器名字 /bin/bash 进入容器
cat /var/jenkins_home/secrets/initialAdminPassword 查看密码
yum安装
$ yum -y install wget
$ wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.263.1-1.1.noarch.rpm
$ yum -y localinstall jenkins-2.263.1-1.1.noarch.rpm
$ systemctl start jenkins
$ systemctl status jenkins
$ chkconfig jenkins on
$ wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.263.1-1.1.noarch.rpm
$ yum -y localinstall jenkins-2.263.1-1.1.noarch.rpm
$ systemctl start jenkins
$ systemctl status jenkins
$ chkconfig jenkins on
修改更新源
$ sed -i 's#updates.jenkins.io#mirror.tuna.tsinghua.edu.cn/jenkins/updates#g' /var/lib/jenkins/hudson.model.UpdateCenter.xml
$ sed -i 's#updates.jenkins.io/download#mirrors.tuna.tsinghua.edu.cn/jenkins#g' /var/lib/jenkins/updates/default.json
$ sed -i 's#www.google.com#www.baidu.com#g' /var/lib/jenkins/updates/default.json
$ sed -i 's#updates.jenkins.io/download#mirrors.tuna.tsinghua.edu.cn/jenkins#g' /var/lib/jenkins/updates/default.json
$ sed -i 's#www.google.com#www.baidu.com#g' /var/lib/jenkins/updates/default.json
修改端口
vim /etc/sysconfig/jenkins
修改ssh端口
vi /etc/ssh/sshd_config
#Port 22 //这行去掉#号,防止配置不好以后不能远程登录,还得去机房修改,等修改以后的端口能使用以后在注释掉
Port 20000 //下面添加这一行
Port 20000 //下面添加这一行
systemctl restart sshd.service
chsh -s /bin/bash
跳板机
https://github.com/sshstack/sshstack
删除centos7自带的python
强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
删除残余文件 # whereis python|xargs rm -frv
替换
find -name "*.locked" | for i in *;do mv $i `echo $i | sed 's/\.locked//g'`;done
find / -name "*.jar" -exec grep -Hsli 类名 {} \;
find . -name "*.jar" -exec grep -Hsli 'javax.el.ExpressionFactory' {} \;
find . -name "*.jar" -exec grep -Hsli 'javax.el.ExpressionFactory' {} \;
查询类名
启动优先级
LIB=".:${FPATH}/lib/javax.el-3.0.0.jar:${FPATH}/lib/*:${FPATH}/core/*:${FPATH}/blib/*.jar"
0 条评论
下一页