增加.net环境部署 mysql部署 和其他
需要连外网
1.1 更新yum源
rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
1.2 安装
yum install dotnet-sdk-3.1
1.3 完成后查看
dotnet -info
2.1. 安装yum源
# 下载 wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm # 安装 mysql 源 yum localinstall mysql57-community-release-el7-11.noarch.rpm
2.2. 取消密钥验证
vi /etc/yum.repos.d/mysql-community.repo
将5.7 下的gpgcheck改为0;保存(Esc : wq! 回车)
2.3. 安装
yum install -y mysql-community-server
2.4.启动服务
systemctl start mysqld 查看服务状态 systemctl status mysqld
2.5. 设置开机启动
#开机服务 systemctl enable mysqld # 重载所有修改过的配置文件 systemctl daemon-reload
2.6.修改root本地账户密码
#查看临时密码 grep 'temporary password' /var/log/mysqld.log
使用临时密码登录,修改密码
mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXXX';
以后通过 update set 语句修改密码
mysql> use mysql; mysql> update user set password=PASSWORD('MyNewPass5!') where user='root'; mysql> flush privileges;
2.7. 添加远程登录用户
mysql> use mysql; mysql> UPDATE user SET Host='%' WHERE User='root'; mysql> flush privileges;
2.8. 设置默认编码
vim /etc/my.cnf
#设置字符 character-set-client-handshake = 0 character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' #设置备份用户 [mysqldump] user=root #密码 password=xxx [server] max_allowed_packet = 1024M
重启服务并检查是否已经改过来了
shell> systemctl restart mysqld shell> mysql -uroot -p mysql> show variables like 'character%';
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid
启动关闭服务:systemctl start|stop mysqld
2.9. 还原数据库脚本 创建数据库
mysql -uroot -p #输入密码 create database Test;
创建还原脚本
vim mysqlRestore.sh
username="root" #用户名 password="Hdzx2022." #密码 mysql -u$username -p$password Test<$1
执行
/home/mysqlRestore.sh /home/20220228154729_Test.sql
2.10. 备份数据脚本
创建备份脚本
vim /home/mysqlback.sh
#---备份---# !/bin/bash backup="/home/mysqlbackup" tablename="Test" if [ ! -d $backup ];then mkdir $backup chmod 777 $backup fi /usr/bin/mysqldump --default-character-set=utf8 $tablename > $backup/$(date +%Y%m%d%H%M%S)$1_$tablename.sql
chmod 777 /home/mysqlback.sh
3.1 安装
yum install keepalived #service keepalived start #启动服务 #service keepalived stop #停止服务 #service keepalived restart #重启服务 #ps -ef | grep keepalived #查看进程 3个就是启动了
3.2 查看日志
vim /var/log/messages #按G到最后一行
3.3 配置
vim /etc/keepalived/keepalived.conf
3.4 监听策略
global_defs { router_id MES } vrrp_script chk_mq { script "/etc/keepalived/chk_mq.sh" interval 10 #会出现advert_int时间内无效应情况 要大于此值 weight -15 #减优先级 fall 2 #2次失败才是失败 } vrrp_instance VI_1 { state MASTER # 备份服务器上将 MASTER 改为 BACKUP interface ens32 #ip a virtual_router_id 51 priority 100 #备机 90 advert_int 1 #间隔时间 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.123.45 } track_script { chk_mq } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" }
global_defs { router_id MES } vrrp_script chk_mq { script "/etc/keepalived/chk_mq.sh" interval 10 weight -15 fall 2 } vrrp_instance VI_1 { state MASTER interface em1 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.123.45 } track_script { chk_mq } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" }
3.5 notify.sh邮件通知
contact='xxx@xxx.com' #多个请以 -c 开头 arg=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"` hostip=$arg #只拿第一个网卡 可以写死 function notify() { mailsubject=" IP $hostip" mailbody="$(date +'%F %T'),\n\n 权重变更 $1, 请检查服务状态" echo -e "$mailbody" | mail -s "$mailsubject" $contact } function notify2() { mailsubject=" 服务出现异常请排查 IP $hostip" mailbody="$(date +'%F %T'), 服务异常 $1" echo "$mailbody" | mail -s "$mailsubject" $contact } case $1 in master) notify 主服务 ;; backup) notify 备服务 ;; fault) notify fault ;; *) notify2 $1 ;; esac
3.6 ch_mq.sh监听端口
#!/bin/bash port=61614 pid=$(netstat -nlp | grep -w :$port | awk '{print $7}' | awk -F"/" '{ print $1 }' | wc -l); #拿到pid第一位 如果是0 if [ $pid -eq 0 ];then exit 1 fi exit 0
编号 | 项目 | 内容 |
---|---|---|
1 | 主服务器IP | * |
2 | 备份器IP | * |
3 | 虚拟IP | * |
4 | Mysql数据库名 | * |
5 | Mysql用户名 | * |
6 | Mysql密码 | * |
7 | Mysql备份路径 | * |
8 | MySql还原脚本路径 | * |
9 | MySql备份文件夹 | * |
10 | Keepalived相关脚本位置 | * |
本文作者:没想好
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!