linux常用指令(centos)
2023-05-10 00:23:56 0 举报
AI智能生成
linux常用指令(centos)
作者其他创作
大纲/内容
ssh-keygen -t rsa
生成密钥
centos免密码登录authorized_keys需要600权限
ssh-copy-id -i ~/.ssh/id_rsa.pub root@要拷贝到的机器ip
通信其他服务器
ssh
adduser hdfs
创建用户
passwd
密码
linuxidc ALL=(ALL) ALL #这个是新增的用户
sudo
linuxidc ALL=(ALL) NOPASSWD: ALL
免密 sudo
授权 /etc/sudoers
userdel -r username
删除用户
增加用户
getenforce
/usr/sbin/sestatus -v
setenforce 0
临时关闭
vi /etc/selinux/config
永久关闭
SELinux
临时关闭防火墙systemctl stop firewalld
永久防火墙开机自关闭systemctl disable firewalld
临时打开防火墙systemctl start firewalld
防火墙开机启动systemctl enable firewalld
查看防火墙状态systemctl status firewalld
防火墙
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.servicesudo systemctl enable nginx.service
nginx
yum remove mysql
rpm -qa | grep mysql
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum localinstall mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install glibc.i686
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
MySQL GPG 密钥已过期导致
yum install -y mysql-community-server --nogpgcheck
yum install mysql-server
systemctl enable mysqld
service mysqld restart
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
set password for 'root'@'localhost'=password('MyNewPass4!');
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
use mysql;update user set password=PASSWORD('MyNewPass5!') where user='root';flush privileges;
mysql> update user set host='%' where user='root';mysql> flush privileges;
update set 语句修改密码
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%';
修改验证密码策略
root用户密码
[mysqld]character-set-server=utf8[client]default-character-set=utf8[mysql]default-character-set=utf8
修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:
设置默认编码为 utf8
配置文件:/etc/my.cnf日志文件:/var/log/mysqld.log服务启动脚本:/usr/lib/systemd/system/mysqld.servicesocket文件:/var/run/mysqld/mysqld.pid
默认配置文件
mysql
fdisk -l
磁盘挂载
# Command (m for help): n //输入N表示新建一个分区# Command (m for help): w //保存分区
fdisk /dev/sdb
磁盘分区
mkfs.ext3 /dev/sdb
用mkfs.ext3格式化新分区
$ mkdir /mnt/hdb1 //新建一个挂载点。$ mount /dev/hdb1 /mnt/hdb1 //挂载。$ df -h
挂载使用
lsblk -f
查看挂载uid
开机使用
挂载硬盘
cd /etc/yum.repos.dsudo mv CentOS-Base.repo CentOS-Base.repo.bak
备份旧源
sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
修改为阿里源
安装base reop源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
安装epel repo源
yum clean allyum makecache
刷新缓存
yum源加速
vi /etc/docker/daemon.json{ \"registry-mirrors\": [\"http://hub-mirror.c.163.com\"]}systemctl restart docker.service
yum -y install docker systemctl restart docker.service
docker
docker pull jenkins docker images | grep jenkins 查看jenkin镜像是否下载成功
mkdir /home/jenkins_home chown /home/jenkins_home/ 1000:1000 jenkins_home
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镜像(最新版)
docker run -d --name myjenkins -p 3927:3927 -p 19362:19362 -v /data/home/jenkins:/data/home/jenkins docker.io/jenkins:latest
安装启动 Jenkins 容器
docker run -d --name myjenkins -p 50000:8080 -v /home/jenkins_home:/home/jenkins_home jenkins 创建容器并启动 docker ps | grep jenkins 查看是否映射成功
docker ps 查看容器 docker exec -i -t 容器的id或者容器名字 /bin/bash 进入容器 cat /var/jenkins_home/secrets/initialAdminPassword 查看密码
$ 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
$ 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
修改更新源
vim /etc/sysconfig/jenkins
修改端口
yum安装
jenkins
#Port 22 //这行去掉#号,防止配置不好以后不能远程登录,还得去机房修改,等修改以后的端口能使用以后在注释掉Port 20000 //下面添加这一行
vi /etc/ssh/sshd_config
systemctl restart sshd.service
修改ssh端口
chsh -s /bin/bash
https://github.com/sshstack/sshstack
跳板机
强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
删除残余文件 # whereis python|xargs rm -frv
删除centos7自带的python
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' {} \\;
LIB=\".:${FPATH}/lib/javax.el-3.0.0.jar:${FPATH}/lib/*:${FPATH}/core/*:${FPATH}/blib/*.jar\"
启动优先级
替换
命令
linux常用指令(centos)
0 条评论
回复 删除
下一页