##################
背景:
业务自己安装了一个percona分支的mysql server 5.7.25版本,端口号配置为3307,后来业务发现自己电脑与该机器有防火墙限制,想通过443或80端口绕过防火墙限制,于是将配置文件中的端口号改成443,如下:
启动命令如下:
shell> /home/work/mysql_3307/bin/mysqld_safe --defaults-file=/home/work/mysql_3307/etc/my.cnf &
my.cnf文件内容部分如下:
[client] port = 443 socket = /home/work/mysql_3307/tmp/mysql.sock [mysqld]
# 问题就出现在下面这一行配置,当特权端口< 1024的时候,
需要 root 访问权限,而业务就是想通过443端口来绕过防火墙的限制,
user = work port = 443 socket = /home/work/mysql_3307/tmp/mysql.sock datadir = /home/work/mysql_3307/data basedir = /home/work/mysql_3307 pid_file = /home/work/mysql_3307/tmp/mysql.pid log-error = /home/work/mysql_3307/log/mysql.err default-time-zone = "+08:00" thread_handling = pool-of-threads thread_pool_stall_limit = 50 thread_pool_oversubscribe = 20 performance_schema = 1 log_slave_updates log_timestamps = SYSTEM general_log = /home/work/mysql_3307/log/mysql.log general_log = /home/work/mysql_3307/log/mysql.log log_warnings slow_query_log slow_query_log_file = /home/work/mysql_3307/log/slow.log tmpdir = /home/work/mysql_3307/tmp
查看mysql的错误日志:
shell> less /home/work/mysql_3307/log/mysql.err
2021-09-10T11:59:39.494044+08:00 0 [Warning] option 'general_log': boolean value '/home/work/mysql_3307/log/mysql.log' wasn't recognized. Set to OFF. 2021-09-10T11:59:39.494128+08:00 0 [Warning] option 'general_log': boolean value '/home/work/mysql_3307/log/mysql.log' wasn't recognized. Set to OFF. 2021-09-10T11:59:39.494142+08:00 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead. 2021-09-10T11:59:39.494526+08:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-09-10T11:59:39.494572+08:00 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2021-09-10T11:59:39.494612+08:00 0 [Note] /home/work/mysql_3307/bin/mysqld (mysqld 5.7.25-28-log) starting as process 167258 ... 2021-09-10T11:59:39.503292+08:00 0 [Warning] option 'innodb-buffer-pool-chunk-size': unsigned value 128 adjusted to 1048576 2021-09-10T11:59:39.504031+08:00 0 [Note] InnoDB: PUNCH HOLE support available 2021-09-10T11:59:39.504054+08:00 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2021-09-10T11:59:39.504063+08:00 0 [Note] InnoDB: Uses event mutexes 2021-09-10T11:59:39.504071+08:00 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2021-09-10T11:59:39.504082+08:00 0 [Note] InnoDB: Compressed tables use zlib 1.2.7 2021-09-10T11:59:39.507458+08:00 0 [Note] InnoDB: Number of pools: 1 2021-09-10T11:59:39.507618+08:00 0 [Note] InnoDB: Using CPU crc32 instructions 2021-09-10T11:59:39.510419+08:00 0 [Note] InnoDB: Initializing buffer pool, total size = 10G, instances = 8, chunk size = 1M 2021-09-10T11:59:39.991718+08:00 0 [Note] InnoDB: Completed initialization of buffer pool 2021-09-10T11:59:40.063282+08:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2021-09-10T11:59:40.075849+08:00 0 [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /home/work/mysql_3307/data/xb_doublewrite 2021-09-10T11:59:40.077084+08:00 0 [Note] InnoDB: Opened 3 undo tablespaces 2021-09-10T11:59:40.077104+08:00 0 [Note] InnoDB: 3 undo tablespaces made active 2021-09-10T11:59:40.077505+08:00 0 [Note] InnoDB: Highest supported file format is Barracuda. 2021-09-10T11:59:40.148881+08:00 0 [Note] InnoDB: Created parallel doublewrite buffer at /home/work/mysql_3307/data/xb_doublewrite, size 31457280 bytes 2021-09-10T11:59:40.320501+08:00 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2021-09-10T11:59:40.320607+08:00 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2021-09-10T11:59:40.326149+08:00 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2021-09-10T11:59:40.327480+08:00 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2021-09-10T11:59:40.327496+08:00 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2021-09-10T11:59:40.327981+08:00 0 [Note] InnoDB: Waiting for purge to start 2021-09-10T11:59:40.378141+08:00 0 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.25-28 started; log sequence number 2504477 2021-09-10T11:59:40.378254+08:00 0 [Note] InnoDB: Loading buffer pool(s) from /home/work/mysql_3307/data/ib_buffer_pool 2021-09-10T11:59:40.378487+08:00 0 [Note] Plugin 'FEDERATED' is disabled. 2021-09-10T11:59:40.410408+08:00 0 [Note] InnoDB: Buffer pool(s) load completed at 210910 11:59:40 2021-09-10T11:59:40.410792+08:00 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key 2021-09-10T11:59:40.410817+08:00 0 [Note] Server hostname (bind-address): '*'; port: 443 2021-09-10T11:59:40.410869+08:00 0 [Note] IPv6 is available. 2021-09-10T11:59:40.410888+08:00 0 [Note] - '::' resolves to '::'; 2021-09-10T11:59:40.410906+08:00 0 [Note] Server socket created on IP: '::'. 2021-09-10T11:59:40.410944+08:00 0 [ERROR] Can't start server: Bind on TCP/IP port: Permission denied 2021-09-10T11:59:40.410951+08:00 0 [ERROR] Do you already have another mysqld server running on port: 443 ? 2021-09-10T11:59:40.410963+08:00 0 [ERROR] Aborting
问题根本原因:
特权端口:是指在 Linux 系统下,只允许 root 用户运行的程序才可以使用特权端口 ( 1024 以下的端口 )。如果在普通用户下使用特权端口将会报错。 业务使用的443端口,很明显是小于1024的,因此是特权端口,这就要求启动进程的时候,必须以root身份启动,但是my.cnf文件中指定work用户(一般用户)来启动,那肯定就不是root用户了,因此无法启动,但是mysql这个报错内容让人摸不着头脑
解决问题:将配置文件中的user=work改成user=root,然后用root用户执行:
root-shell> /home/work/mysql_3307/bin/mysqld_safe --defaults-file=/home/work/mysql_3307/etc/my.cnf &
/home/work/mysql_3307/etc/my.cnf文件内容如下:
[client] port = 443 socket = /home/work/mysql_3307/tmp/mysql.sock [mysqld] # 将work改成rootuser = root port = 443 socket = /home/work/mysql_3307/tmp/mysql.sock datadir = /home/work/mysql_3307/data basedir = /home/work/mysql_3307 pid_file = /home/work/mysql_3307/tmp/mysql.pid log-error = /home/work/mysql_3307/log/mysql.err default-time-zone = "+08:00" thread_handling = pool-of-threads thread_pool_stall_limit = 50 thread_pool_oversubscribe = 20 performance_schema = 1 log_slave_updates log_timestamps = SYSTEM general_log = /home/work/mysql_3307/log/mysql.log general_log = /home/work/mysql_3307/log/mysql.log log_warnings slow_query_log slow_query_log_file = /home/work/mysql_3307/log/slow.log tmpdir = /home/work/mysql_3307/tmp
##########################
##########################