jenkins安装脚本

  • jenkins安装脚本
#!/bin/bash
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
yum install wget git curl -y
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install java jenkins -y
systemctl start jenkins
## 查看jenkins默认生成的密码
cat /var/lib/jenkins/secrets/initialAdminPassword

SHELL脚本之case

  • 一般形式
case variable in
    pattern1 | pattern2)
        command;;
    pattern3)
        command;;
    *)
        default command;;
esac
  • 例子
#!/bin/bash
case $USER in
    root | user)
        echo "Welcome.$USER"
        echo "Please enjoy your visit";;
    testing)
        echo "Special testing acount";;
    *)
    echo "Sorry,you are not allowed here";;
esac

SHELL脚本之if

if语句的几种常用方法

  • if then fi
if command
then
    commands
fi
  • if then else fi
if command
then
    commands
else
    commands
fi
  • if then elif then fi
if command1
then
    commands
elif command2
then
    more commands
fi

PS:
1.if-then语句允许你使用布尔逻辑来组合测试,有两种布尔运算符可用:
[ condition ] && [ condition2 ]
[ condition ] || [ condition2 ]
2.双圆括号命令允许你将高级数学表达式放入比较中:
(( expression ))
3.双方括号里的expression使用了test命令中采用的标准字符串进行比较。但他提供了test命令未提供的另一种特性—-模式匹配
[[ expression ]]

Linux系统安装docker

docker的趋势是浩浩荡荡啊,下面是各个系统安装docker的脚本

#!/bin/bash
updateKernel(){
    rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
    rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
    yum --enablerepo=elrepo-kernel install kernel-lt -y
    sed -i "s/default=1/default=0/g" /etc/grub.conf
    sed -i "s/default=1/default=0/g" /boot/grub/grub.conf
}

centos6InstallDocker(){
    kernalVersion=`uname -r | cut -d "." -f 1`
    if [ $kernalVersion  -lt 3 ];then
        updateKernel
    fi
    yum -y install epel-release
    yum -y install docker-io
    service docker start
    chkconfig docker on
    docker version
}

centos7InstallDocker(){
    yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
    yum install -y yum-utils device-mapper-persistent-data lvm2
    yum-config-manager  --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    yum install docker-ce -y
    systemctl start docker
    systemctl enable docker
    docker version
}

ubuntuInstallDocker(){
    sudo apt-get remove docker docker-engine docker.io containerd runc
    sudo apt-get update
    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update
    sudo apt-get install docker-ce -y
    ## test docker
    sudo docker container run hello-world
}

centosVersion=`cat /etc/redhat-release | sed -r 's/.* ([0-9]+)\..*/\1/'`
if [ $centosVersion -eq 6 ];then
    centos6InstallDocker
elif [ $centosVersion -eq 7 ];then
    centos7InstallDocker
else
    echo "Your version is wrong , Plese check !!!"
    exit
fi

CentOS7通过yum方式安装mysql8

  • mysql8增加了许多新特性,比如支持JSON格式,密码认证方式改成了”caching-sha2-password”,不过很多客户端还不支持的,在将来肯定都会支持的。如果客户端不支持的话还是可以改成”mysql_native_password”方式。
#!/bin/bash
yum install wget -y
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install mysql-community-server -y
systemctl start mysqld.service
systemctl enable mysqld.service
systemctl status mysqld.service

#查看mysql自己生成的临时密码
grep 'temporary password' /var/log/mysqld.log

## 由于 default_password_lifetime 的存在,必须修改默认密码之后才能使用
alter user user() identified by "yourpassword";