read_only 与 super_read_only 生产维护注意事项

在主从中,我们设置从库只读:
1、如果只是打开read_only=on 在从库上启用确保只接受来自主库的更新,不接受来自客户端的更新。但是不能保证连到从库具有super权限误写数据。
2、mysql5.7.8开始支持super_read_only参数,如果super_read_only=on,在从库直接受来自主库的更新,连接到从库的含有super用户权限也不能更新,确保从库不被写如异常数据。

另外注意:
如果设置了super_read_only =on ,那么默认的read_only 也设置为on,如果再设置super_read_only =off,此时read_only 还是on,如果主从角色发生变化注意read_only也设置为off。

日常维护:
主库可读写
从库只读

从库只读的两种选择:
1、read_only = on;
2、read_only = on;
super_read_only = on;

区别是如果从库也设置了super_read_only=on,可很好确保了从库不被误写数据,即便是变更时候,不小心在从库执行了super权限用户语句也会失败,不会造成主从不一致。

那么我们的从库是否一定要设置为super_read_only = on 吗?

看不同的架构:
传统的主从,建议从库也设置super_read_only=on防止应用用户高权在从库写如数据,也防止变更的时候在从库误写数据。
如果是分布式架构,涉及到了专门的管理agent负责对db节点切换,那么还是不能设置为super_read_only=on,但是相关应用等不负责切换的用户务必不能具备super权限。
mgr架构,mgr内部会自动为从库设置为super_read_only=on。

从库重启后维护:
如果传统主从架构,遇到宿主机宕机虚拟机漂移后启动数据库,还是从库本身是物理机异常宕机,还是从库计划内升级系统补丁等操作重启后建议显示把从库设置为super_read_only=on只读。
如果是分布式,建议启动管理agent由管理的agent负责把从节点加入主库并且把从库设置为read_only=on。

其他问题:
如果使用nbu备份,备份策略是从库,由于备份用户需要super权限,需要在备份时候先把super_read_only=off备份结束后设置super_read_only=on。

(venv) zjh@ds-test:~/test7.2$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \ --trusted-host pypi.tuna.tsinghua.edu.cn \ --default-timeout=600 \ paramiko oracledb Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting paramiko Downloading https://pypi.tuna.tsinghua.edu.cn/packages/15/f8/c7bd0ef12954a81a1d3cea60a13946bd9a49a0036a5927770c461eade7ae/paramiko-3.5.1-py3-none-any.whl (227 kB) Collecting oracledb Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d9/c8/62103e3d5229d6fbf443ff2e89978d96468ec4318e3315e321fd0c68108d/oracledb-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (2.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 17.4 MB/s eta 0:00:00 Collecting bcrypt>=3.2 (from paramiko) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/dc/7f/1e36379e169a7df3a14a1c160a49b7b918600a6008de43ff20d479e6f4b5/bcrypt-4.3.0-cp39-abi3-manylinux_2_34_x86_64.whl (284 kB) Collecting cryptography>=3.3 (from paramiko) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/35/6e/dca39d553075980ccb631955c47b93d87d27f3596da8d48b1ae81463d915/cryptography-44.0.3-cp39-abi3-manylinux_2_34_x86_64.whl (4.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 21.3 MB/s eta 0:00:00 Collecting pynacl>=1.5 (from paramiko) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/87/f1bb6a595f14a327e8285b9eb54d41fef76c585a0edef0a45f6fc95de125/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (856 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 856.7/856.7 kB 8.9 MB/s eta 0:00:00 Collecting cffi>=1.12 (from cryptography>=3.3->paramiko) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b2/d5/da47df7004cb17e4955df6a43d14b3b4ae77737dff8bf7f8f333196717bf/cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (479 kB) Collecting pycparser (from cffi>=1.12->cryptography>=3.3->paramiko) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl (117 kB) Installing collected packages: pycparser, bcrypt, cffi, pynacl, cryptography, paramiko, oracledb Successfully installed bcrypt-4.3.0 cffi-1.17.1 cryptography-44.0.3 oracledb-3.1.0 paramiko-3.5.1 pycparser-2.22 pynacl-1.5.0 (venv) zjh@ds-test:~/test7.2$ ^C (venv) zjh@ds-test:~/test7.2$ pip install paramiko -i https://mirrors.aliyun.com/pypi/simple/ Looking in indexes: https://mirrors.aliyun.com/pypi/simple/ Requirement already satisfied: paramiko in ./venv/lib/python3.12/site-packages (3.5.1) Requirement already satisfied: bcrypt>=3.2 in ./venv/lib/python3.12/site-packages (from paramiko) (4.3.0) Requirement already satisfied: cryptography>=3.3 in ./venv/lib/python3.12/site-packages (from paramiko) (44.0.3) Requirement already satisfied: pynacl>=1.5 in ./venv/lib/python3.12/site-packages (from paramiko) (1.5.0) Requirement already satisfied: cffi>=1.12 in ./venv/lib/python3.12/site-packages (from cryptography>=3.3->paramiko) (1.17.1) Requirement already satisfied: pycparser in ./venv/lib/python3.12/site-packages (from cffi>=1.12->cryptography>=3.3->paramiko) (2.22) (venv) zjh@ds-test:~/test7.2$ ^C (venv) zjh@ds-test:~/test7.2$ pip install pyinstaller Collecting pyinstaller Downloading pyinstaller-6.13.0-py3-none-manylinux2014_x86_64.whl.metadata (8.3 kB) ERROR: Exception: Traceback (most recent call last): File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher yield File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 561, in read data = self._fp_read(amt) if not fp_closed else b"" ^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 527, in _fp_read return self._fp.read(amt) if amt is not None else self._fp.read() ^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 98, in read data: bytes = self.__fp.read(amt) ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/http/client.py", line 479, in read s = self.fp.read(amt) ^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/socket.py", line 720, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/ssl.py", line 1251, in recv_into return self.read(nbytes, buffer) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/ssl.py", line 1103, in read return self._sslobj.read(len, buffer) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TimeoutError: The read operation timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 105, in _run_wrapper status = _inner_run() ^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 96, in _inner_run return self.run(options, args) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper return func(self, options, args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 379, in run requirement_set = resolver.resolve( ^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 95, in resolve result = self._result = resolver.resolve( ^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve state = resolution.resolve(requirements, max_rounds=max_rounds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 397, in resolve self._add_to_criteria(self.state.criteria, r, parent=None) File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _add_to_criteria if not criterion.candidates: ^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/resolvelib/structs.py", line 156, in __bool__ return bool(self._sequence) ^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 174, in __bool__ return any(self) ^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 162, in <genexpr> return (c for c in iterator if id(c) not in self._incompatible_ids) ^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 53, in _iter_built candidate = func() ^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 186, in _make_candidate_from_link base: Optional[BaseCandidate] = self._make_base_candidate_from_link( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 232, in _make_base_candidate_from_link self._link_candidate_cache[link] = LinkCandidate( ^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 303, in __init__ super().__init__( File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 158, in __init__ self.dist = self._prepare() ^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 235, in _prepare dist = self._prepare_distribution() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 314, in _prepare_distribution return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 521, in prepare_linked_requirement metadata_dist = self._fetch_metadata_only(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 373, in _fetch_metadata_only return self._fetch_metadata_using_link_data_attr( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 393, in _fetch_metadata_using_link_data_attr metadata_file = get_http_url( ^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 111, in get_http_url from_path, content_type = download(link, temp_dir.path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/network/download.py", line 148, in __call__ for chunk in chunks: ^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_internal/network/utils.py", line 65, in response_chunks for chunk in response.raw.stream( ^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 622, in stream data = self.read(amt=amt, decode_content=decode_content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 560, in read with self._error_catcher(): ^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/contextlib.py", line 158, in __exit__ self.gen.throw(value) File "/home/zjh/test7.2/venv/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher raise ReadTimeoutError(self._pool, None, "Read timed out.") pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
最新发布
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值