centos下安装etcd集群

环境准备
172.16.50.30(centos7.x)
172.16.50.31(centos7.x)

  • 在172.16.50.30这台机器上面运行
#!/bin/bash
yum install wget -y
cd /opt && wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz
tar zxvf etcd-v3.3.10-linux-amd64.tar.gz && cd etcd-v3.3.10-linux-amd64
nohup ./etcd --name docker-node1 \
--initial-advertise-peer-urls http://172.16.50.30:2380 \
--listen-peer-urls http://172.16.50.30:2380 \
--listen-client-urls http://172.16.50.30:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.50.30:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster docker-node1=http://172.16.50.30:2380,docker-node2=http://172.16.50.31:2380 \
--initial-cluster-state new&
  • 在172.16.50.31这台机器上面运行
#!/bin/bash
yum install wget -y
cd /opt && wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz
tar zxvf etcd-v3.3.10-linux-amd64.tar.gz && cd etcd-v3.3.10-linux-amd64
nohup ./etcd --name docker-node2 \
--initial-advertise-peer-urls http://172.16.50.31:2380 \
--listen-peer-urls http://172.16.50.31:2380 \
--listen-client-urls http://172.16.50.31:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.50.31:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster docker-node1=http://172.16.50.30:2380,docker-node2=http://172.16.50.31:2380 \
--initial-cluster-state new&
  • 查看集群状态
./etcdctl cluster-health

ansible的安装

考虑到环境的多样性,这儿使用python的虚拟环境安装使用ansible模块

cd /opt

##安装ansible的python3虚拟环境(需要先安装python3环境在opt目录下面)
/opt/python3/bin/pip install virtualenv
/opt/python3/bin/virtualenv -p /opt/python3/bin/python3 ansible_vitualenv

##启动ansible的python3虚拟环境
source /opt/ansible_vitualenv/bin/activate

##安装ansible模块以及依赖模块
pip install ansible paramiko PyYAML jinja2

##检测是否安装成功
ansible --version

K8S集群搭建

  • 本集群搭建在 aws上面,使用的是UBUNTU18.04系统
  • 集群环境如下:
master节点: 172.31.25.36
node1节点: 172.31.21.5
node2节点: 172.31.23.174
  • 安装docker,参考以下文章
  • 安装k8s
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
echo " " >>  /etc/profile
echo "## setting for k8s" >> /etc/profile
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
. /etc/profile
kubeadm init --apiserver-advertise-address=172.31.25.36 --pod-network-cidr=192.168.16.0/20  ## 初始化master
curl -L "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" > weave.yaml  ##  安装weave网络
修改 weave.yaml  再env下加入:
  - name: IPALLOC_RANGE
    value: 192.168.16.0/20
kubectl  apply -f weave.yaml
kubectl get pods -n kube-system -o wide ## 查看pods状态
kubeadm join 172.31.25.36:6443 --token lbm7wf.hiwr8d1ed5nxkxfh \
    --discovery-token-ca-cert-hash sha256:b2758c8b463658df45f0c2a665b5985fdb302c3efbe260921ff4a56b84c8445a  ## 在node节点运行,将node加入到master当中
kubectl get nodes ## 查看集群状态
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml  ## 安装kubernetes-dashboard
  • 创建一个dashboard登录用户
vi jiang-user.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: jiang
  namespace: kube-system
vi jiang-user-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: dashboard:jiang
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: jiang
  namespace: kube-system
kubectl create -f jiang-user-role-binding.yaml
kubectl get secret -n kube-system | grep jiang ## 得到jiang-token-fhrsq 这个用户的对象
kubectl describe secret/jiang-token-fhrsq -n kube-system  ## 得到token,登录的时候就使用这个token登录

test 常用命令

--- 数值比较
    n1 -eq n2       --- 检查n1是否与n2相等
    n1 -ge n2       --- 检查n1是否大于等于n2
    n1 -gt n2       --- 检查n1是否大于n2
    n1 -le n2       --- 检查n1是否小于等于n2
    n1 -lt n2       --- 检查n1是否小于n2
    n1 -ne n2       --- 检查n1是否不等于n2

--- 字符串比较
    str1 == str2        --- 检查str1是否和str2相同
    str1 != str2    --- 检查str1是否和str2不同
    str1 < str2     --- 检查str1是否比str2小
    str1 > str2     --- 检查str1是否比str2大
    -n str1         --- 检查str1的长度是否为非0
    -z str1         --- 检查str1的长度是否为0
PS:大于小于符号必须转义,否则shell会把他们当做重定向符号,而把字符串当做文件名;大于小于顺序和sort命令所采用的不同

--- 文件比较
    -d file             --- 检查file是否存在并是一个目录
    -e file             --- 检查file是否存在
    -f file             --- 检查file是否存在并是一个文件
    -r file             --- 检查file是否存在并可读
    -s file             --- 检查file是否存在并非空
    -w file             --- 检查file是否存在并可写
    -x file             --- 检查file是否存在并可执行
    -O file             --- 检查file是否存在并属当前用户所有
    -G file             --- 检查file是否存在并且默认组与当前用户相同
    file1 -nt file2     --- 检查file1是否比file2新
    file1 -ot file2     --- 检查file1是否比file2久
    file1 -ef file2     --- 判断file1和file2的Inode号是否一致

--- 多重条件判断
    判断1 -a 判断2      --- 逻辑与,判断和判断2都成立,最终的结果才为真
    判断1 -o 判断2      --- 逻辑或,判断1和判断2有一个成立,最终的结果就为真
    ! 判断            --- 逻辑非,使原始的判断取反

yum安装最新mariadb

该测试系统为centos7.x

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum install MariaDB-server MariaDB-devel galera MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation  ## 初始化数据库