##################
背景:
業務自己安裝了一個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
##########################

##########################
