GreatSQL社区

搜索

GreatSQL社区

将GreatSQL添加到系统systemd服务

GreatSQL社区 已有 374 次阅读2022-8-24 09:21 |个人分类:技术分享|系统分类:用户实践

1、关于systemd

systemd 是Linux系统启动和服务器守护进程管理器,负责在系统启动或运行时,激活系统资源,服务器进程和其它进程,systemd被设计用来改进原来sysvinit中的多个缺点。

CentOS 7的systemd服务程序脚本存放在 /usr/lib/systemd/目录下,并区分 system 和 user,每一个服务程序脚本以 .service 结尾,例如 /usr/lib/systemd/system/sshd.service

2、编辑systemd服务程序脚本

设定 GreatSQL 二进制文件放在 /usr/local/GreatSQL-8.0.23-14/ 目录下,即设定 basedir 为此目录,先进入到这个工作目录中。

[root@greatsql~]# cd /usr/local/GreatSQL-8.0.23-14/

复制 support-files/greatsql.server 程序脚本到 /usr/lib/systemd/system/ 目录下:

[root@greatsql~]# cp -f ./support-files/greatsql.server /usr/lib/systemd/system/

该脚本内容如下,基本上不需要再修改什么内容:

[root@greatsql~]# cat /usr/lib/systemd/system/greatsql.service[Unit]Description=GreatSQL ServerDocumentation=man:mysqld(8)Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlType=notifyTimeoutSec=0PermissionsStartOnly=trueExecStartPre=/usr/local/GreatSQL-8.0.23-14/bin/mysqld_pre_systemdExecStart=/usr/local/GreatSQL-8.0.23-14/bin/mysqld $MYSQLD_OPTSEnvironmentFile=-/etc/sysconfig/mysqlLimitNOFILE = 10000Restart=on-failureRestartPreventExitStatus=1Environment=MYSQLD_PARENT_PID=1PrivateTmp=false

3、准备my.cnf及其他配置文件

复制 support-files/my.cnf/etc/ 目录下,替换原来的配置文件(原来的 /etc/my.cnf 建议先备份),并确认 datadir、port、server_id 等参数是否要修改:

[root@greatsql~]# cp -f ./support-files/my.cnf /etc/my.cnf[root@greatsql~]# cat /etc/my.cnf#my.cnf[mysqld]user = mysqlport = 3306server_id = 3306basedir=/usr/local/GreatSQL-8.0.23-14datadir = /data/GreatSQLsocket = /data/GreatSQL/mysql.sockpid-file = mysql.pidcharacter-set-server = UTF8MB4skip_name_resolve = 1#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数default_time_zone = "+8:00"#performance setttingslock_wait_timeout = 3600open_files_limit    = 65535back_log = 1024max_connections = 512max_connect_errors = 1000000table_open_cache = 1024table_definition_cache = 1024thread_stack = 512Ksort_buffer_size = 4Mjoin_buffer_size = 4Mread_buffer_size = 8Mread_rnd_buffer_size = 4Mbulk_insert_buffer_size = 64Mthread_cache_size = 768interactive_timeout = 600wait_timeout = 600tmp_table_size = 32Mmax_heap_table_size = 32M#log settingslog_timestamps = SYSTEMlog_error = /data/GreatSQL/error.loglog_error_verbosity = 3slow_query_log = 1log_slow_extra = 1slow_query_log_file = /data/GreatSQL/slow.loglong_query_time = 0.1log_queries_not_using_indexes = 1log_throttle_queries_not_using_indexes = 60min_examined_row_limit = 100log_slow_admin_statements = 1log_slow_slave_statements = 1log_bin = /data/GreatSQL/binlogbinlog_format = ROWsync_binlog = 1binlog_cache_size = 4Mmax_binlog_cache_size = 2Gmax_binlog_size = 1Gbinlog_rows_query_log_events = 1binlog_expire_logs_seconds = 604800#MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行binlog_checksum = CRC32gtid_mode = ONenforce_gtid_consistency = TRUE#myisam settingskey_buffer_size = 32Mmyisam_sort_buffer_size = 128M#replication settingsmaster_info_repository = TABLErelay_log_info_repository = TABLErelay_log_recovery = 1slave_parallel_type = LOGICAL_CLOCK#可以设置为逻辑CPU数量的2倍slave_parallel_workers = 64binlog_transaction_dependency_tracking = WRITESETslave_preserve_commit_order = 1slave_checkpoint_period = 2#mgr settingsloose-plugin_load_add = 'mysql_clone.so'loose-plugin_load_add = 'group_replication.so'loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"#MGR本地节点IP:PORT,请自行替换loose-group_replication_local_address = "172.16.16.10:33061"#MGR集群所有节点IP:PORT,请自行替换loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"loose-group_replication_start_on_boot = OFFloose-group_replication_bootstrap_group = OFFloose-group_replication_exit_state_action = READ_ONLYloose-group_replication_flow_control_mode = "DISABLED"loose-group_replication_single_primary_mode = ON#innodb settingstransaction_isolation = REPEATABLE-READinnodb_buffer_pool_size = 2Ginnodb_buffer_pool_instances = 8innodb_data_file_path = ibdata1:12M:autoextendinnodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 32Minnodb_log_file_size = 1Ginnodb_log_files_in_group = 3innodb_max_undo_log_size = 4G# 根据您的服务器IOPS能力适当调整# 一般配普通SSD盘的话,可以调整到 10000 - 20000# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000innodb_io_capacity = 4000innodb_io_capacity_max = 8000innodb_open_files = 65535innodb_flush_method = O_DIRECTinnodb_lru_scan_depth = 4000innodb_lock_wait_timeout = 10innodb_rollback_on_timeout = 1innodb_print_all_deadlocks = 1innodb_online_alter_log_max_size = 4Ginnodb_print_ddl_logs = 1innodb_status_file = 1#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快innodb_status_output = 0innodb_status_output_locks = 1innodb_sort_buffer_size = 67108864#innodb monitor settingsinnodb_monitor_enable = "module_innodb"innodb_monitor_enable = "module_server"innodb_monitor_enable = "module_dml"innodb_monitor_enable = "module_ddl"innodb_monitor_enable = "module_trx"innodb_monitor_enable = "module_os"innodb_monitor_enable = "module_purge"innodb_monitor_enable = "module_log"innodb_monitor_enable = "module_lock"innodb_monitor_enable = "module_buffer"innodb_monitor_enable = "module_index"innodb_monitor_enable = "module_ibuf_system"innodb_monitor_enable = "module_buffer_page"innodb_monitor_enable = "module_adaptive_hash"#pfs settingsperformance_schema = 1#performance_schema_instrument = '%memory%=on'performance_schema_instrument = '%lock%=on'

再复制 support-files/sysconfig/mysql 文件到 /etc/sysconfig 目录下。

[root@greatsql~]# cp -f ./support-files/sysconfig/mysql /etc/sysconfig/mysql[root@greatsql~]# cat /etc/sysconfig/mysqlLD_PRELOAD=/usr/lib64/libjemalloc.so.1

这是为了能让GreatSQL启动时加载jemalloc,获得更好的内存管理性能。

4、启动GreatSQL服务

上述准备工作完成后,还要将 GreatSQL 服务正式加载到 systemd 列表中:

[root@greatsql~]# systemctl daemon-reload

这就会自动将GreatSQL这个新服务加载进来了。

然后开始启动服务:

[root@greatsql~]# systemctl start greatsql#如果加上 .service 后缀也可以,例如[root@greatsql~]# systemctl start greatsql.service

如果启动失败,可能会输出类似的报错提示:

[root@greatsql~]# systemctl start greatsqlJob for greatsql.service failed because the control process exited with error code. See "systemctl status greatsql.service" and "journalctl -xe" for details.

按照错误提示,执行 systemctl status greatsql.servicejournalctl -xe 查看失败的原因,亦可查看系统日志 /var/log/messages 或 GreatSQL日志 /data/GreatSQL/error.log 确认失败原因。

第一次会比较慢,因为还要初始化InnoDB系统表空间、redo、undo日志等。初始化时,还会为root生成临时密码,例如这样:

...[MY-010454] [Server] A temporary password is generated for root@localhost: dofI,0HE#E>C...

首次登入需要用这个密码,并立即修改成新密码,新密码还必须符合安全规范才行,不能是弱密码:

# 先登入[root@greatsql~]# mysql -uroot -p -S/data/GreatSQL/mysql.sockEnter password: ************# 而后修改密码,否则不能做其他操作[root@GreatSQL][(none)]> ALTER USER CURRENT_USER() IDENTIFIED BY 'GreatSQL3##)^';

这是因为用默认加载了 validate_password 组件(component),对密码有合规性要求。

[root@GreatSQL][(none)]> SELECT * FROM mysql.component;+--------------+--------------------+------------------------------------+| component_id | component_group_id | component_urn                      |+--------------+--------------------+------------------------------------+|            1 |                  1 | file://component_validate_password |+--------------+--------------------+------------------------------------+

如果嫌麻烦可以卸载掉(但非常不建议这么做):

[root@GreatSQL][(none)]> UNINSTALL COMPONENT 'file://component_validate_password';

最后,介绍systemctl主要几个的命令:

  • 重载系统服务:systemctl daemon-reload
  • 启用开机启动:systemctl enable greatsql
  • 禁用开机启动:systemctl disable greatsql
  • 启动服务:systemctl start greatsql
  • 停止服务:systemctl stop greatsql
  • 重启服务:systemctl restart greatsql
  • 查看服务状态:systemctl status greatsql

全文完。

Enjoy GreatSQL :)



评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-5-14 02:16 , Processed in 0.014341 second(s), 8 queries , Redis On.
返回顶部