跳到主要内容

Linux 服务器时间同步

· 阅读需 1 分钟

Linux 服务器时间同步

方法一

# 安装 ntpd 相关服务
yum install -y ntp

# 同步阿里云服务时间
ntpdate ntp1.aliyun.com

# 编辑 /etc/ntp.conf 文件
server ntp.aliyun.com iburst

# 开启自动同步及开机同步
systemctl restart ntp
systemctl enable ntp

方法二 下载 ntpdate

yum install -y ntpdate

调整时区为上海,也就是北京时间+8区

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

yes | cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

使用NTP来同步时间

ntpdate us.pool.ntp.org

定时同步时间(每隔10分钟同步时钟)

crontab -l >/tmp/crontab.bak

echo "*/10 * * * * /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP" >> /tmp/crontab.bak

crontab /tmp/crontab.bak

# 查看定时任务
crontab -l

Mysql 主从复制

· 阅读需 3 分钟

Mysql 主从复制

搭建主从

# Slave 机器执行 change master to

CHANGE MASTER TO
MASTER_HOST='192.168.100.171',
MASTER_USER='test',
MASTER_PASSWORD='passwd123',
MASTER_PORT=3306,
MASTER_LOG_FILE='master-bin.000006',
MASTER_LOG_POS=2556,
MASTER_CONNECT_RETRY=10;

验证

mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

从库复制主库的部分表

思路为:1.master只发送需要的;2.slave只接收想要的

master端:

binlog-do-db 二进制日志记录的数据库(多数据库用逗号```,隔开) binlog-ignore-db 二进制日志中忽略数据库 (多数据库用逗号,隔开)

1、binlog-do-db=YYY 需要同步的数据库,不在内的不同步。(不添加这行表示同步所有)

# 这里主库只同步 test1 ,test2库
[mysqld]
binlog-do-db = test1,test2

2、binlog-ignore-db = mysql 这是不记录binlog,来达到从库不同步mysql库,以确保各自权限 binlog-ignore-db = performance_schema binlog-ignore-db = information_schema

# 这里向从库同步时忽略test1,test2库
[mysqld]
binlog-ignore-db = test1,test2

slave端:

replicate-do-db 设定需要复制的数据库(多数据库使用逗号,隔开) replicate-ignore-db 设定需要忽略的复制数据库 (多数据库使用逗号,隔开) replicate-do-table 设定需要复制的表 replicate-ignore-table 设定需要忽略的复制表 replicate-wild-do-table 同replication-do-table功能一样,但是可以通配符 replicate-wild-ignore-table 同replication-ignore-table功能一样,但是可以加通配符

# 例如:从库忽略复制数据库test3,但是需要说明的是,其实从库的relaylog中是从在关于test3的相关日志,只是从库没有使用罢了。
[mysqld]
replicate-ignore-db = test3

# 增加通配符的两个配置
replicate-wild-do-table=db_name.% 只复制哪个库的哪个表
replicate-wild-ignore-table=mysql.% 忽略哪个库的哪个表

报错解决:

1、报错:Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).

# 查看主从UUID是否相同
/var/lib/mysql/auto.cnf

# 查看 mysql 配置文件的 server-id 是否一致,例如:
主:server-id=1
从:server-id=2

2、报错:Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

从机器:

stop slave;

主机器:

mysq> show master status;
File Position
binlog.000010 157

mysql> flush logs;
因为刷新日志file的位置会+1,即File变成为:binlog.000011

从机器

CHANGE MASTER TO MASTER_LOG_FILE='binlog.000011',MASTER_LOG_POS=157;
start slave;
show slave status\G;

SkyWalking 安装部署

· 阅读需 3 分钟

SkyWalking 安装部署

系统设置

  • 设置 iptables
iptables -P FORWARD ACCEPT
  • 关闭swap
swapoff -a
# 防止开机自动挂载 swap 分区
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  • 设置yum源
curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum clean all && yum makecache

安装 Docker

yum install docker-ce-cli-19.03.9-3.el7  docker-ce-19.03.9-3.el7 -y

# 配置docker加速
mkdir -p /etc/docker
vi /etc/docker/daemon.json

{
"registry-mirrors": ["镜像加速地址, 改自己的~"]

}

# 启动docker
systemctl enable docker && systemctl start docker

安装 Docker-compose

# 下载安装包
wget https://github.com/docker/compose/releases/download/1.28.6/docker-compose-Linux-x86_64

chmod +x docker-compose-Linux-x86_64
mv docker-compose-Linux-x86_64 /usr/local/sbin/docker-compose

docker-compose version

启动相关容器

  • elasticsearch 作为 skywalking 的存储,保存链路和日志数据等

  • oap 数据接收和分析 Observability Analysis Platform

  • ui web端的数据展示

创建配置文件目录

mkdir -p /data/skywalking
cd /data/skywalking

vi docker-compose.yml
# 拉去镜像并启动
docker-compose up -d
# 查看日志
docker-compose logs -f

编写 yml 文件

vi docker-compose.yml

version: '3.8'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.1
container_name: elasticsearch
restart: always
ports:
- 9200:9200
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- TZ=Asia/Shanghai
ulimits:
memlock:
soft: -1
hard: -1
oap:
image: apache/skywalking-oap-server:8.7.0-es7
container_name: oap
depends_on:
- elasticsearch
links:
- elasticsearch
restart: always
ports:
- 11800:11800
- 12800:12800
healthcheck:
test: ["CMD-SHELL", "/skywalking/bin/swctl"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
environment:
TZ: Asia/Shanghai
SW_STORAGE: elasticsearch7
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
ui:
image: apache/skywalking-ui:8.7.0
container_name: ui
depends_on:
- oap
links:
- oap
restart: always
ports:
- 8088:8080
environment:
TZ: Asia/Shanghai
SW_OAP_ADDRESS: http://oap:12800

启动容器

# 拉去镜像并启动
docker-compose up -d
# 查看日志
docker-compose logs -f

# docker 全部开启和全部关闭
docker start `docker ps -qa`
docker stop `docker ps -qa`

访问 ip:8088

数据不持久化启动

 ./bin/startup.sh

下载 agent 代理包

wget https://archive.apache.org/dist/skywalking/8.7.0/apache-skywalking-apm-es7-8.7.0.tar.gz

tar xf apache-skywalking-apm-es7-8.7.0.tar.gz

启动 agent

java -javaagent:上一步解压目录/agent/skywalking-agent.jar=agent.service_name=自定义服务名,collector.backend_service=服务器IP:11800 -jar xx.jar

开启日志收集

待更新