蓝鲸模拟考试

mysql --login-path=default-root

1、变更域名
cd /data/install
./bin/change_bk_domain.sh bktencent.org
2、修改公共组件密码
vim /data/install/bin/01-generate/

3、修改 es 和 job 的 jvm 最小堆和最大堆大小。
vim /etc/elasticsearch/jvm.options el
vim /etc/sysconfig/bk-job-* job

4、nginx 配置反向代理 rabbitmq
source /data/install/utils.fc
ssh $BK_NGINX_IP
source /data/install/load_env.sh
cat > /usr/local/openresty/nginx/conf/conf.d/rabbitmq.conf <<EOF
server {
listen 80;
server_name rabbitmq.alone.com;
access_log $BK_HOME/logs/nginx/rabbitmq_ui_access.log main;

location / {
proxy_pass http://127.0.0.1:15672;
}
}
EOF
systemctl reload openresty

需要浏览器本地配置hosts

5、将目录 /opt/yum/ 配置本地为 yum 源,并且用 nginx 提供对外的 http 服务
source /data/install/utils.fc
scp -r /data/src/yum/ root@$BK_NGINX_IP:/opt/
ssh $BK_NGINX_IP 2>&1 <<eof
cat > /usr/local/openresty/nginx/conf/conf.d/yum.conf <<EOF
server {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
listen 8081;
root /opt/yum;
access_log /data/bkce/logs/nginx/yum_access.log main;
location / {
}
}
EOF
systemctl reload openresty
chmod 777 -R /opt/yum/

#制作yum源
yum install -y createrepo
createrepo /opt/yum/
cat > /etc/yum.repos.d/yum.repo <<EOF
[yum-custom]
name=yum
baseurl=http://10.0.6.63:8081
enabled=1
gpgcheck=0
EOF
yum repolist
eof

6、从paas nginx日志中过滤api url
awk '{print $7}' /data/bkce/logs/nginx/access.log

7、再从结果中过滤IP,方法,URL,useragent(useragent会包含空格)
awk -F "[ \"]+" '{print $1,$6,$7,$12,$13,$14,$15,$16}' /data/bkce/logs/nginx/access.log

8、再从结果中统计IP+url+useragent相同访问次数,并输出统计次数、IP、URL、useragent
awk -F "[ \"]+" '{print $1,$6,$7,$12,$13,$14,$15,$16}' /data/bkce/logs/nginx/access.log |sort -nr | uniq -c

9、初始服务器 。修改主机名为linux-ip(第三段)-ip(第四段) 时间同步
[root@linux-6-63 ~]# cat hostname.sh
#!/bin/bash
ip=`ifconfig ens192 | grep 'inet ' | awk '{print $2}' | awk -F. '{print $3"-"$4}'`
hostnamectl set-hostname linux-$ip
hostname linux-$ip

systemctl restart ntpd
ntpdate -u cn.pool.ntp.org


10、第一步文件传输,将软件包同步到服务器。

第二步,脚本执行,修改 websvr 的配置文件。adress 修改为内网IP,并且启动进程。创建一个
上下文参数 process_id, 并将pid 赋值给 process_id, 写入 /opt/websvr/websvr.pid
tar xf logicsvr.tar.gz
ip=`ifconfig ens192 | grep 'inet ' | awk '{print $2}'`
sed -i s/address=.*/address=$ip/g logicsvr/logicsvr.conf
/root/logicsvr/logicsvr -f /root/logicsvr/logicsvr.conf
pid=`ps -ef | grep logicsvr | grep -v grep | awk '{print $2}'`
process_id=$pid
echo $process_id > /root/logicsvr/logicsvr.pid

第三步,创建一个作业,当websvr 挂掉时重启服务,并将新的pid 写入 /opt/websvr/websvr.pid
po=`ps -ef | grep logicsvr | grep -v grep | awk '{print $2}' | wc -l`
pid=`ps -ef | grep logicsvr | grep -v grep | awk '{print $2}'`
if [ $po -eq 0 ];then
/root/logicsvr/logicsvr -f /root/logicsvr/logicsvr.conf
echo $pid > /root/logicsvr/logicsvr.pid
fi

11、脚本采集 /proc/stat cpu使用率,并且配置仪表盘视图。
#!/bin/sh
#脚本功能描述:依据/proc/stat文件获取并计算CPU使用率
#CPU时间计算公式:CPU_TIME=user+system+nice+idle+iowait+irq+softirq
#CPU使用率计算公式:cpu_usage=[(user_2 +sys_2+nice_2) - (user_1 + sys_1+nice_1)]/(total_2 - total_1)*100
#默认时间间隔
TIME_INTERVAL=5
time=$(date "+%s")
LAST_CPU_INFO=$(cat /proc/stat | grep -w cpu | awk '{print $2,$3,$4,$5,$6,$7,$8}')
LAST_SYS_IDLE=$(echo $LAST_CPU_INFO | awk '{print $4}')
LAST_USER_BUSY=$(echo $LAST_CPU_INFO | awk '{print $1}')
LAST_SYS_BUSY=$(echo $LAST_CPU_INFO | awk '{print $3}')
LAST_TOTAL_CPU_T=$(echo $LAST_CPU_INFO | awk '{print $1+$2+$3+$4+$5+$6+$7}')
LAST_CPU_USAGE=$(echo $LAST_CPU_INFO | awk '{print $1+$2+$3}')
sleep ${TIME_INTERVAL}
NEXT_CPU_INFO=$(cat /proc/stat | grep -w cpu | awk '{print $2,$3,$4,$5,$6,$7,$8}')
NEXT_SYS_IDLE=$(echo $NEXT_CPU_INFO | awk '{print $4}')
NEXT_USER_BUSY=$(echo $NEXT_CPU_INFO | awk '{print $1}')
NEXT_SYS_BUSY=$(echo $NEXT_CPU_INFO | awk '{print $3}')
NEXT_TOTAL_CPU_T=$(echo $NEXT_CPU_INFO | awk '{print $1+$2+$3+$4+$5+$6+$7}')
NExT_CPU_USAGE=$(echo $NEXT_CPU_INFO | awk '{print $1+$2+$3}')
#系统空闲时间
SYSTEM_IDLE=`echo ${NEXT_SYS_IDLE} ${LAST_SYS_IDLE} | awk '{print $1-$2}'`
#系统使用时间
SYSTEM_BUSY=`echo ${NEXT_SYS_BUSY} ${LAST_SYS_BUSY} | awk '{print $1-$2}'`
#用户使用时间
USER_BUSY=`echo ${NEXT_USER_BUSY} ${LAST_USER_BUSY} | awk '{print $1-$2}'`
#用户+系统+nice时间
TOTAL_BUSY=`echo ${NExT_CPU_USAGE} ${LAST_CPU_USAGE} | awk '{print $1-$2}'`
#CPU总时间
TOTAL_TIME=`echo ${NEXT_TOTAL_CPU_T} ${LAST_TOTAL_CPU_T} | awk '{print $1-$2}'`

#CPU总时间百分比
CPU_USAGE=`echo ${TOTAL_BUSY} ${TOTAL_TIME} | awk '{printf "%.2f", $1/$2*100}'`
#用户时间百分比
CPU_USER_USAGE=`echo ${USER_BUSY} ${TOTAL_TIME}|awk '{printf "%.2f", $1/$2*100}'`
#系统时间百分比
CPU_sys_USAGE=`echo ${SYSTEM_BUSY} ${TOTAL_TIME} |awk '{printf "%.2f", $1/$2*100}'`

echo "cpu_usage" ${CPU_USAGE}

12、在新机器上按照 consul,并且加入原有的 consul 集群。需要用作业平台完成。
yum -y install sshpass
sshpass -p'Lj@2021' /data/install/configure_ssh_without_pass

source /data/install/utils.fc
echo "10.0.6.55 consul" >> /data/install/install.config
/data/install/bkcli sync common
/data/install/pcmd.sh -H 10.0.6.55 /data/install/bin/init_new_node.sh

13、在新机器上安装 mysql。
#!/bin/bash
systemctl stop firewalld
setenforce 0
user="root" #这里写授权的用户
password="admin520" #这里写授权的数据库密码
slave_ipaddr="10.0.6.55" #这里写自己从的IP地址
master_ipaddr="10.0.6.64" #这里写自己主的IP地址

bk_mysql_password=`grep -E "BK_MYSQL_ADMIN_PASSWORD" /data/install/bin/01-generate/dbadmin.env | awk -F '=' '{print $2}'`
echo ${bk_mysql_password} > /tmp/bk_mysql_password.txt

yum -y install openssh-clients #安装ssh检测工具
sed -i '/^\[mysqld\]$/a\server-id=1' /etc/my.cnf #在配置文件my.cnf添加
sed -i '/^\[mysqld\]$/a\log-bin=/var/lib/mysql/mysql/mysql-bin.log' /etc/my.cnf #在配置文件my.cnf添加
sed -i '/^\[mysqld\]$/a\relay-log=mysql-relay' /etc/my.cnf #在配置文件my.cnf添加
sed -i '/^\[mysqld\]$/a\max_binlog_size = 1G' /etc/my.cnf
sed -i '/^\[mysqld\]$/a\log-bin-index = master-bin.index' /etc/my.cnf

systemctl restart mysql@default.service #启动mysql
#做数据备份
mysqldump -u root -p$bk_mysql_password -hlocalhost --all-databases > /tmp/all_db.sql
echo "备份完成"

master_status=`mysql -uroot -p$bk_mysql_password -h$master_ipaddr -e "show master status;"`
echo $master_status #打印master_status
master_file=`echo "$master_status" | grep "bin" | awk '{print $1}'`
echo "$master_file" > /tmp/master_file.txt
master_pos=`echo "$master_status" | grep "bin" | awk '{print $2}'`
echo "$master_pos" > /tmp/master_pos.txt

scp /tmp/all_db.sql root@$slave_ipaddr:/tmp/
scp /tmp/bk_mysql_password.txt root@$slave_ipaddr:/tmp/
scp /tmp/master_file.txt root@$slave_ipaddr:/tmp/
scp /tmp/master_pos.txt root@$slave_ipaddr:/tmp/
scp /etc/yum.repos.d/Blueking.repo root@$slave_ipaddr:/etc/yum.repos.d/

mysql -uroot -p$bk_mysql_password -hlocalhost -e "grant all privileges on *.* to '$user'@'$slave_ipaddr' identified by '$password';" #给用户授权
echo "授权完成"
#两台服务器已经做了免密码登录#

ssh root@$slave_ipaddr 2>&1 <<eof

systemctl stop firewalld
setenforce 0

#下载mysql
yum repolist
yum -y install mysql-server
#启动mysql,修改配置文件

sed -i '/^\[mysqld\]$/a\server-id=2' /etc/my.cnf
sed -i '/^\[mysqld\]$/a\log-bin=/var/lib/mysql/mysql/mysql-bin.log' /etc/my.cnf
sed -i '/^\[mysqld\]$/a\relay-log=mysql-relay' /etc/my.cnf
sed -i '/^\[mysqld\]$/a\skip-grant-tables' /etc/my.cnf

systemctl restart mysqld
echo "重启完成"
bk_mysql_password=`cat /tmp/bk_mysql_password.txt`
master_file=`cat /tmp/master_file.txt`
master_pos=`cat /tmp/master_pos.txt`

#开始做主从
mysql -e "source /tmp/all_db.sql;"
echo "导入完成"
mysql -e "change master to master_host='$master_ipaddr', master_password='$password', master_user='$user', master_log_file='$master_file', master_log_pos=$master_pos;"
echo "指定主完成"
mysql -e "start slave;"
echo "start slave 完成"
mysql -uroot -p$bk_mysql_password -e "flush privileges;"
echo "刷新完成"
mysql -uroot -p$bk_mysql_password -e "show slave status \G;"
check=`mysql -uroot -p$bk_mysql_password -e "show slave status \G;" | grep Yes | wc -l`
if [ $check == 1 ]; then
echo "仅输出一个yes"
elif [ $check == 2 ]; then
echo "输出俩个yes"
else
echo "mysql错误"
fi
eof


13、将新机器上的 mysql-slave 注册到 consul 的服务发现,并且配置监控检测
/data/install/bin/reg_consul_svc -n mysql-slave -p 3306 -a 10.0.6.55 中控机执行
dig mysql-slave.service.consul

 

posted @ 2021-05-19 15:29  金元  阅读(149)  评论(0编辑  收藏  举报