linux 初始化
shell
#!/bin/bash
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/Centos-7.repo
yum clean all
yum makecache
yum repolist
yum install -t wget
yum install -y rsync
yum install -y vim
rsync
shell
rsync -r -u /opt/hadoop/ root@192.168.83.140:/opt/hadoop/
rsync -r -u /opt/jdk1.8.0_201/ root@192.168.83.140:/opt/jdk1.8.0_201/
scp -r env.sh root@192.168.83.140:/opt/
source env.sh
rsync -av /opt/hadoop/ root@192.168.83.140:/opt/hadoop/
touch nginx-{01..10}.txt
rocky linux
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/rocky*.repo
dnf makecache
磁盘管理
sh
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
shell
lsblk
fdisk -l
centos 添加新硬盘 并格式化 建立分区 挂载
https://www.cnblogs.com/studyjobs/p/18168763
##在虚拟机添加硬盘后执行操作
lsblk
fdisk -l
## 新硬盘是 /dev/sdb
## 分区 只见一个主分区
fdisk /dev/sdb
## 输入p 创建主分区 两次回车 创建一个主分区
p
## 保存
wq
## 查看磁盘分区
lsblk
sdb
sdb1
## 格式化 xfs 分区
mkfs.xfs /dev/sdb1
## 创建目录
mkdir -p /mnt/data
## 把硬盘挂载到指定的挂载点上
mount /dev/sdb1 /mnt/data
## 卸载 分区
umount /dev/sdb1
## 查询硬盘分区
df -h
## fstab 追加分区挂载
vim /etc/fstab
# 之间使用 空格 或者 tab 进行隔开即可
/dev/sdb1 /mnt/data xfs defaults 0 0
创建数据库 脚本
sh
#!/bin/bash
HOST="localhost"
PORT="3306"
USER="root"
PASSWORD="root"
dbName="test"
mysql_sh="mysql -u$USER -p$PASSWORD"
echo ${mysql_sh}
echo "create database test"
create_db_sql="create database IF NOT EXISTS ${dbName}"
echo ${create_db_sql} | ${mysql_sh}
if [ $? -ne 0 ] #判断是否创建成功
then
echo "create databases ${dbName} failed ..."
exit 1
fi
echo "create table ${TABLENAME}"
服务启停
sh
#!/bin/bash
port=8081
path='travelApp.jar'
pid=`ps -ef |grep $path |grep -v grep | awk '{print $2}'`
if [[ $pid == "" ]];then
echo "服务不存在" && exit 1
fi
kill -9 $pid && echo "服务已停止 pid=$pid"
sh
#!/bin/bash
port=8081
path='travelApp.jar'
pid=`ps -ef |grep $path |grep -v grep | awk '{print $2}'`
if [[ $pid != "" ]];then
echo "服务已存在" && exit 1
fi
nohup java -jar $path --server.servlet.context-path=/travelApp > travelApp.log 2>&1 &
echo "服务启动成功 $!"
centos7 升级bash
sh
wget -v http://ftp.gnu.org/gnu/bash/bash-5.1.16.tar.gz
tar zxvf bash-5.1.16.tar.gz
cd bash-5.1.16/
./configure
make && make install
## 因为bash默认是安装在/usr/local/bin/目录下,所以需要创建一个链接到/bin/目录下,
#安装完毕后需要重启生效!
mv /bin/bash /bin/bash.bak && ln -s /usr/local/bin/bash /bin/bash
#重新加载bash或者重新断开连接,重新远程登录即可完成bash版本升级。
exec $SHELL
/usr/local/bin/bash -version
/bin/bash --version
bash --version
bashtop
sh
## ubuntu 直接 使用 apt install bashtop
## centos 需要先升级bash 以上
#下载bashtop 源码 bashtop-0.9.25.tar.gz
#解压并执行
make install
centos 配置 ssh 免密登录
shell
# 在当前机器下 执行命令 生成 私钥和公钥 ~/.ssh 目录下
ssh-keygen -t rsa
# 执行如下命令 把公钥 放到 对应机器上的 ~/.ssh/authorized_keys
ssh-copy-id 172.17.68.220
# 如此 两台机器两两配置
centos 连接慢
sh
vim /etc/ssh/sshd_config
# UseDNS 设置为no
UseDNS no
systemctl restart sshd
centos 安装 ansible
sh
yum -y install epel-release
yum -y install ansible
harbor 搭建
sh
tar -zxvf harbor-offline-installer-v2.11.1.tgz -C /opt
mv harbor.yml.tmpl harbor.yml
vim harbor.yml
# 修改hostname为当前IP
# 注释https 相关
./install.sh
# 访问
ip+80(用户: admin/Harbor12345)
## 安装docker 的各个客户机都需操作
vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.229.134"]
}
systemctl daemon-reload
systemctl restart docker
docker login 192.168.229.134
# 输入harbor用户名及密码
# 打标签
docker tag nginx:latest 192.168.229.134/library/nginx:latest
# 推送至私服
docker push 192.168.229.134/library/nginx:latest