ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

Centos基础配置 centos7基础 含 yum 配置 时区配置 ssh配置 - openstack基础镜像-手工配置时间 linux基础 含cp显示进度 linux下载站等

Centos基础配置 centos7基础 含 yum 配置 时区配置 ssh配置 - openstack基础镜像-手工配置时间 linux基础 含cp显示进度 linux下载站等 # 先换成国内源 这里使用的aliyun的 换国内源 24年更新 http的163已经启用了cd /etc/yum.repos.d/ mkdir test mv *.repo test # wget http://mirrors.163.com/.help/CentOS7-Base-163.repo # 使用163国内源快一些 # 阿里源 curl -s -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum -y install telnet # 阿里 epel wget -O /etc/yum.repos.d/epel.repo \ http://mirrors.aliyun.com/repo/epel-7.repo# 不用下载的 cat 命令cat /etc/yum.repos.d/CentOS-Base.repo EOF # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist does not work for you, as a fall back you can try the # remarked out baseurl line instead. # # [base] nameCentOS-$releasever - Base - mirrors.aliyun.com baseurlhttp://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck1 gpgkeyhttp://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] nameCentOS-$releasever - Updates - mirrors.aliyun.com baseurlhttp://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ gpgcheck1 gpgkeyhttp://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] nameCentOS-$releasever - Extras - mirrors.aliyun.com baseurlhttp://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ gpgcheck1 gpgkeyhttp://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] nameCentOS-$releasever - Plus - mirrors.aliyun.com baseurlhttp://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ gpgcheck1 enabled0 gpgkeyhttp://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 EOFcat /etc/yum.repos.d/epel.repo EOF [epel] nameExtra Packages for Enterprise Linux 7 - $basearch baseurlhttp://mirrors.aliyun.com/epel/7/$basearch failovermethodpriority enabled1 gpgcheck0 gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo] nameExtra Packages for Enterprise Linux 7 - $basearch - Debug baseurlhttp://mirrors.aliyun.com/epel/7/$basearch/debug failovermethodpriority enabled0 gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck0 [epel-source] nameExtra Packages for Enterprise Linux 7 - $basearch - Source baseurlhttp://mirrors.aliyun.com/epel/7/SRPMS failovermethodpriority enabled0 gpgkeyfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck0 EOF# K8S 容器常用优化# 1.1 关闭swap分区 # 1.2 sysctl 修改内核参数 # 1.3 开启ipvs # 1.4 配置主机名 关闭防火墙等 systemctl stop firewalld systemctl disable firewalld sed -i s/^SELINUX.*/SELINUXdisabled/ /etc/selinux/config setenforce 0 swapoff -a sed -i / swap / s/^\(.*\)$/#\1/g /etc/fstab timedatectl set-timezone Asia/Shanghai yum install ntpdate -y ntpdate pool.ntp.org cat /etc/sysctl.d/k8s.conf EOF net.bridge.bridge-nf-call-ip6tables 1 net.bridge.bridge-nf-call-iptables 1 EOF# 临时关闭提示音rmmod pcspkr# 常用linux下载网站推荐Linux系统下载网 - 帮技术人员找到合适的系统# ls -l显示具体时间ls -l --time-stylelong-iso# 复制文件显示进度原文如何优雅地给cp命令添加进度条_cp命令显示进度_一只晨兴夜不得寐的运维人的博客-CSDN博客# -a 参数表示归档复制-infoprogress2 使用进度条 并实时更新 # source_dir/和dest_dir/分别表示源目录和目标目录。 rsync -a --infoprogress2 source_dir/ dest_dir/# 如果能安装pv工具的话 直接用 cp也可以显示# -r 表示递归复制 source_dir/和dest_dir/分别表示源目录和目标目录。 cp -r source_dir/ dest_dir/ | pv -lep -s $(du -sb source_dir | awk {print $1})# 原始centos部署之后 常规初始化配置timedatectl set-timezone Asia/Shanghai setenforce 0 sed -i s/SELINUXenforcing/SELINUXdisabled/g /etc/selinux/config # 关闭selinux# 常用开发工具 python3 gityum -y install git #wget http://mirrors.163.com/.help/CentOS7-Base-163.repo # 使用163 yum -y install epel-release yum install -y python3 python3-devel which pip3 pip3 install --upgrade pip pip3 install requests# mysqlwget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm yum -y install mysql57-community-release-el7-10.noarch.rpm # yum -y install mysql-community-server # 这步可能会花些时间安装完成后就会覆盖掉之前的mariadb。 sed -i s/gpgcheck1/gpgcheck0/g /etc/yum.repos.d/mysql-community.repo sed -i s/gpgcheck1/gpgcheck0/g /etc/yum.repos.d/mysql-community-source.repo yum -y install mysql-community-server # 这步可能会花些时间安装完成后就会覆盖掉之前的mariadb。 # 启动mysql 查看\修改密码 systemctl start mysqld.service grep password /var/log/mysqld.log alter user rootlocalhost identified by cy7m0ypu8CpLFperzI45;# 常用 运维工具yum install gcc -y yum install pcre pcre-devel -y yum install zlib zlib-devel -y yum install openssl openssl-devel -y yum -y install gcc gcc-c autoconf automake make yum -y install unzip zip #安装常用插件 yum install -y bash-completion # base-completion.noarch补全 yum -y install net-tools lrzsz wget tree screen lsof tcpdump vim bash-completion telnet sysstat yum install -y bind-utils yum -y install wget yum -y install vim net-tools lrzsz #安装常用插件 yum install -y bash-completion # base-completion.noarch补全 yum -y install net-tools lrzsz wget tree screen lsof tcpdump vim bash-completion telnet sysstat yum install -y bind-utils yum install rpcbind nfs-utils -y yum install -y libaio yum -y install httpd-tools# 只找出 当前目录 2016-12-06 这一天修改的文件find . -maxdepth 1 -newermt 2016-12-06# centos history增加时间戳 和 cut 截取 复制命令export HISTTIMEFORMAT%F %T source /etc/profile historyhistory | cut -c 28- # 带时间戳截取命令是 26- history | cut -c 8- # 不带时间戳是 8-零 # linux 查看进程网络工具安装 原文linux 查看某进程或程序的网卡流量(转) - 清明-心若淡定 - 博客园yum install epel-release -y yum install libpcap nethogs -y nethogs eth0 lsof -i :80 lsof -p 6402# 安装python3 centos#wget http://mirrors.163.com/.help/CentOS7-Base-163.repo # 使用163 yum -y install epel-release yum install -y python3 python3-devel which pip3 pip3 install --upgrade pip pip3 install requestsyum install gcc -y yum install pcre pcre-devel -y yum install zlib zlib-devel -y yum install openssl openssl-devel -y yum -y install gcc gcc-c autoconf automake make yum -y install unzip zip #安装常用插件 yum install -y bash-completion # base-completion.noarch补全 yum -y install net-tools lrzsz wget tree screen lsof tcpdump vim bash-completion telnet sysstat yum install -y bind-utils yum -y install wget yum -y install vim net-tools lrzsz#安装常用插件 yum install -y bash-completion # base-completion.noarch补全 yum -y install net-tools lrzsz wget tree screen lsof tcpdump vim bash-completion telnet sysstat yum install -y bind-utils# mysql nfs还需要装的依赖yum install -y libaio yum install mysql-devel gcc gcc-devel python-devel -y # 记得安装mysql客户端或服务端 python链接mysql才能用yum install rpcbind nfs-utils -y# 开始关闭网卡ifdown ifcfg-ens33 #关闭网卡 ifup ifcfg-ens33 #开启网卡 # 有时候上面命令不好用用下面的 效果等同 ifconfig ens33 down ifconfig ens33 up一 配置网络# eth0为网卡名称 cat /etc/sysconfig/network-scripts/ifcfg-eth0 EOF TYPEEthernet PROXY_METHODnone BROWSER_ONLYno BOOTPROTOstatic # 使用静态IP地址默认为dhcp IPADDR192.168.1.102 # 设置的静态IP地址 NETMASK255.255.255.0 # 子网掩码 GATEWAY192.168.1.1 # 网关地址 DNS1192.168.1.1 # DNS服务器 #DNS2172.20.10.1 DNS2192.168.90.1 DEFROUTEyes IPV4_FAILURE_FATALno IPV6INITyes IPV6_AUTOCONFyes IPV6_DEFROUTEyes IPV6_FAILURE_FATALno IPV6_ADDR_GEN_MODEstable-privacy NAMEens33 UUID66c0a6eb-0b92-4a00-96e0-92e0980d69df DEVICEens33 ONBOOTyes EOF二 更新yum源centos7cd /etc/yum.repos.d wget http://mirrors.aliyun.com/repo/Centos-7.repo mv Centos-7.repo CentOs-Base.repo yum clean all yum makecache yum updatecentos6.5 Centos6.6 yum源更新# 备份 下载 清理 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d//CentOS-Base.repo.ori wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo yum clean all # 更新缓存 yum makecache yum install tree -y yum update -y crontab -e # 加入定时任务 每晚一点校准 30 1 * * * ntpdate time.windows.com三 配置时间# 时间同步 ntp# 时间同步ntp yum install ntpdate -y ntpdate time.windows.com # crontab -e # 设置定时任务 */15 * * * * /usr/sbin/ntpdate time.windows.com /dev/null 2 1 */30 * * * * /usr/sbin/ntpdate time.nist.gov /dev/null 21# 时间同步chronyyum -y install chrony # a时间同步 timedatectl set-timezone Asia/Shanghai # 如果时区有问题的需要重启 系统日志时间才正常 systemctl restart chronyd systemctl status chronyd # 如果是想要作为内部 chrony # 服务端 echo allow 10/8 /etc/chrony.conf systemctl restart chronyd cat /etc/chrony.conf | grep -v ^# | grep -v ^$ # 客户端 sed -i s/server 0.centos.pool.ntp.org/#/ /etc/chrony.conf sed -i s/server 1.centos.pool.ntp.org/#/ /etc/chrony.conf sed -i s/server 2.centos.pool.ntp.org/#/ /etc/chrony.conf # 执行服务端IP sed -i s/server 3.centos.pool.ntp.org/server 10.69.15.111 iburst/ /etc/chrony.conf systemctl restart chronyd# 手工配置时间# date -s 时:分:秒 data -s 年-月-日 如 date -s 16:58:00 date -s 2021-07-21#有下面这个命令的更好timedatectl set-timezone Asia/Shanghai# 修改时区加上 修改ssh openstack镜像常用# 脚本 #!/bin/bash timedatectl set-timezone Asia/Shanghai sed -i s/PasswordAuthentication no/PasswordAuthentication yes/g /etc/ssh/sshd_config # 修改ssh可以密码登录 systemctl restart rsyslog.service systemctl restart sshd# 修改时间戳 CentOS7如何修改日志的时间戳格式包括24小时格式_beeworkshop的博客-CSDN博客vim /etc/rsyslog.conf # Use default timestamp format # 下一行是原来的配置将它注释 #$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # 添加下面两行 $template CustomFormat,%$NOW% %TIMESTAMP:8:15% %HOSTNAME% %syslogtag% %msg%\n $ActionFileDefaultTemplate CustomFormat 然后重启 rsyslog 服务 systemctl restart rsyslog.service四 开启sshyum install -y openssl openssh-server vim /etc/ssh/sshd_config systemctl status sshd五 关闭防火墙 和 selinuxsystemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i s/SELINUXenforcing/SELINUXdisabled/g /etc/selinux/config # 关闭selinux六 主机名# 临时 hostname xxx # 永久 hostnamectl set-hostname xxx
返回列表