GreatSQL配置到系统systemd服务
Posted bisal(Chen Liu)
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GreatSQL配置到系统systemd服务相关的知识,希望对你有一定的参考价值。
GreatSQL历史文章,
我们单机版安装用的是mysql.server start启动的数据库,但从标准化管理的角度,使用systemd更加合适,我们参考《技术分享 | 将GreatSQL添加到系统systemd服务》,进行下配置。
systemd是Linux系统启动和服务器守护进程管理器,负责在系统启动或运行时,激活系统资源,服务器进程和其他进程,systemd被设计用来改进原来sysvinit中的多个缺点。
1. 服务程序脚本
CentOS 7的systemd服务程序脚本存放在/usr/lib/systemd/目录下,并区分system和user,每一个服务程序脚本以.service结尾,例如/usr/lib/systemd/system/sshd.service。
为了配置GreatSQL到systemd,我们需要一些辅助的脚本,GreatSQL标准二进制包中没提供这些,可以从下面这个链接中下载,Ansible安装包提供了这几个文件,如果是rpm包安装,会自动配好systemd。
https://gitee.com/GreatSQL/GreatSQL-Ansible/tree/master/mysql-support-files
greatsql.service是GreatSQL的服务程序脚本,需要放到/usr/lib/systemd/system,内容如下,
[Unit]
Description=GreatSQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStartPre=/opt/mysql/GreatSQL/bin/mysqld_pre_systemd
ExecStart=/opt/mysql/GreatSQL/bin/mysqld $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
2. 其他配置文件
(1) 需要将数据库的my.cnf配置文件复制到/etc路径下。
(2) 需要将如上下载到的sysconfig/mysql配置文件复制到/etc/sysconfig,内容如下,这是为了能让GreatSQL启动时加载jemalloc,获得更好的内存管理性能,
cat mysql
LD_PRELOAD=/usr/lib64/libjemalloc.so.1
3. 启动GreatSQL服务
将GreatSQL服务正式加载到systemd列表中,这就会自动将GreatSQL这个新服务加载进来了,
[root@bisal~]# systemctl daemon-reload
启动服务,
[root@bisal~]# systemctl start greatsql
或者
[root@bisal~]# systemctl start greatsql.service
mysql.error.log记录如下,
[mysql@bisal logs]$ tail -f mysql.error.log
2022-04-05T09:00:32.363066+08:00 0 [Warning] [MY-010097] [Server] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2022-04-05T09:00:32.363131+08:00 0 [System] [MY-010116] [Server] /opt/mysql/GreatSQL/bin/mysqld (mysqld 8.0.25-15) starting as process 24903
2022-04-05T09:00:32.482816+08:00 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-04-05T09:00:32.907440+08:00 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-04-05T09:00:33.291026+08:00 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2022-04-05T09:00:33.500896+08:00 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-04-05T09:00:33.501261+08:00 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-04-05T09:00:33.602927+08:00 0 [System] [MY-010931] [Server] /opt/mysql/GreatSQL/bin/mysqld: ready for connections. Version: '8.0.25-15' socket: '/opt/mysql/data/tmp/mysql.3306.sock' port: 3306 GreatSQL, Release 15, Revision c7feae175e0.
可以使用systemctl status greatsql,查看服务状态,
[root@bisal bin]# systemctl status greatsql
● greatsql.service - GreatSQL Server
Loaded: loaded (/usr/lib/systemd/system/greatsql.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-04-05 09:00:33 CST; 2min 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 24879 ExecStartPre=/opt/mysql/GreatSQL/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 24903 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/greatsql.service
└─24903 /opt/mysql/GreatSQL/bin/mysqld
Apr 05 09:00:31 bisal systemd[1]: Starting GreatSQL Server...
Apr 05 09:00:33 bisal systemd[1]: Started GreatSQL Server.
停止服务,
[root@bisal bin]# systemctl stop greatsql
mysql.error.log记录如下,
2022-04-05T09:00:00.647734+08:00 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.25-15).
2022-04-05T09:00:03.513475+08:00 0 [System] [MY-010910] [Server] /opt/mysql/GreatSQL/bin/mysqld: Shutdown complete (mysqld 8.0.25-15) GreatSQL, Release 15, Revision c7feae175e0.
启用开机启动,
[root@bisal bin]# systemctl enable greatsql
Created symlink from /etc/systemd/system/multi-user.target.wants/greatsql.service to /usr/lib/systemd/system/greatsql.service.
常用指令,
重载系统服务:systemctl daemon-reload
启用开机启动:systemctl enable greatsql
禁用开机启动:systemctl disable greatsql
启动服务:systemctl start greatsql
停止服务:systemctl stop greatsql
重启服务:systemctl restart greatsql
查看服务状态:systemctl status greatsql
近期更新的文章:
《推荐一款小游戏》
文章分类和索引:
以上是关于GreatSQL配置到系统systemd服务的主要内容,如果未能解决你的问题,请参考以下文章