Chào mọi người, khi em start thì nó báo lỗi này, mọi người giúp em với ạ, em sửa hoài mà k ra. T.T
ERROR 2005 (HY000): Unknown MySQL server host '-P' (2)
Cậu thử chạy câu lệnh này, rồi paste log cho bọn tớ nhé!
sh -x gamectl.sh startall
Nếu được, cậu có thể cho bọn tớ nội dung của script gamectl.sh
cũng được.
Đừng chụp ảnh nhé cậu! Cho bọn tớ raw text và sử dụng markdown để format.
EDIT: cậu deploy thiếu file configure_plat.xml
và configure_record.xml
kìa
dạ đây là lỗi log của dòng ở trên
+++ dirname gamectl.sh
++ cd .
++ pwd
+ PROJECT_PATH=/root/server/sh1
+ NAME_CONFIG=configure
+ SERVER_CONFIG=configure.xml
+ CENTER_CONFIG=configure_center.xml
+ CROSS_CONFIG=configure_cross.xml
+ PLAT_CONFIG=configure_plat.xml
+ RECORD_CONFIG=configure_record.xml
+ SERVER_LOG=lfile.log
+ CENTER_LOG=lcenter.log
+ CROSS_LOG=lcross.log
+ PLAT_LOG=lplat.log
+ RECORD_LOG=lrecord.log
+ APP=/root/server/sh1/../libc++/App
+ SERVER_CONFIG_FILE=/root/server/sh1/configure.xml
+ CENTER_CONFIG_FILE=/root/server/sh1/configure_center.xml
+ CROSS_CONFIG_FILE=/root/server/sh1/configure_cross.xml
+ PLAT_CONFIG_FILE=/root/server/sh1/configure_plat.xml
+ RECORD_CONFIG_FILE=/root/server/sh1/configure_record.xml
+ TARGET=startall
+ PARAM1=
+ PARAM2=
+ PARAM3=
+ case $TARGET in
+ start /root/server/sh1/configure_center.xml lcenter.log
+ set_sqlinfo /root/server/sh1/configure_center.xml
+ get_sqlinfo /root/server/sh1/configure_center.xml
++ grep '<cache' /root/server/sh1/configure_center.xml
++ gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ ip=127.0.0.1
++ grep '<cache' /root/server/sh1/configure_center.xml
++ gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ port=3306
++ grep '<cache' /root/server/sh1/configure_center.xml
++ gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ dbname=center
++ grep '<cache' /root/server/sh1/configure_center.xml
++ gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ user=root
++ grep '<cache' /root/server/sh1/configure_center.xml
++ gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
mysql: [Warning] Using a password on the command line interface can be insecure.
+ echo 'create database if not exists `center` character set utf8mb4 COLLATE utf8mb4_bin;'
+ '[' lcenter.log ']'
+ start /root/server/sh1/configure_cross.xml lcross.log
+ set_sqlinfo /root/server/sh1/configure_cross.xml
+ get_sqlinfo /root/server/sh1/configure_cross.xml
+ nohup /root/server/sh1/../libc++/App -configure=/root/server/sh1/configure_center.xml
++ grep '<cache' /root/server/sh1/configure_cross.xml
++ gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ ip=127.0.0.1
++ grep '<cache' /root/server/sh1/configure_cross.xml
++ gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ port=3306
++ gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
++ grep '<cache' /root/server/sh1/configure_cross.xml
+ dbname=cross
++ grep '<cache' /root/server/sh1/configure_cross.xml
++ gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ user=root
++ grep '<cache' /root/server/sh1/configure_cross.xml
++ gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ pass=xxxx
+ echo 'create database if not exists `cross` character set utf8mb4 COLLATE utf8mb4_bin;'
+ mysql -uroot -pxxx -h127.0.0.1 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
+ '[' lcross.log ']'
+ start /root/server/sh1/configure.xml lfile.log
+ set_sqlinfo /root/server/sh1/configure.xml
+ get_sqlinfo /root/server/sh1/configure.xml
+ nohup /root/server/sh1/../libc++/App -configure=/root/server/sh1/configure_cross.xml
++ grep '<cache' /root/server/sh1/configure.xml
++ gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ ip=127.0.0.1
++ grep '<cache' /root/server/sh1/configure.xml
++ gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ port=3306
++ grep '<cache' /root/server/sh1/configure.xml
++ gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ dbname=xntg
++ gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
++ grep '<cache' /root/server/sh1/configure.xml
+ user=root
++ grep '<cache' /root/server/sh1/configure.xml
++ gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ pass=xxx
+ echo 'create database if not exists `xntg` character set utf8mb4 COLLATE utf8mb4_bin;'
+ mysql -uroot -pxxx -h127.0.0.1 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
+ '[' lfile.log ']'
+ start /root/server/sh1/configure_plat.xml lplat.log
+ set_sqlinfo /root/server/sh1/configure_plat.xml
+ get_sqlinfo /root/server/sh1/configure_plat.xml
+ nohup /root/server/sh1/../libc++/App -configure=/root/server/sh1/configure.xml
++ grep '<cache' /root/server/sh1/configure_plat.xml
grep: /root/server/sh1/configure_plat.xml: No such file or directory
++ gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ ip=
++ gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
++ grep '<cache' /root/server/sh1/configure_plat.xml
grep: /root/server/sh1/configure_plat.xml: No such file or directory
+ port=
++ grep '<cache' /root/server/sh1/configure_plat.xml
grep: /root/server/sh1/configure_plat.xml: No such file or directory
++ gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ dbname=
++ grep '<cache' /root/server/sh1/configure_plat.xml
grep: /root/server/sh1/configure_plat.xml: No such file or directory
++ gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ user=
++ grep '<cache' /root/server/sh1/configure_plat.xml
grep: /root/server/sh1/configure_plat.xml: No such file or directory
++ gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ pass=
+ echo 'create database if not exists `` character set utf8mb4 COLLATE utf8mb4_bin;'
+ mysql -u -p -h -P
ERROR 2005 (HY000): Unknown MySQL server host '-P' (2)
+ '[' lplat.log ']'
+ start /root/server/sh1/configure_record.xml lrecord.log
+ set_sqlinfo /root/server/sh1/configure_record.xml
+ get_sqlinfo /root/server/sh1/configure_record.xml
+ nohup /root/server/sh1/../libc++/App -configure=/root/server/sh1/configure_plat.xml
++ grep '<cache' /root/server/sh1/configure_record.xml
grep: /root/server/sh1/configure_record.xml: No such file or directory
++ gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ ip=
++ gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
++ grep '<cache' /root/server/sh1/configure_record.xml
grep: /root/server/sh1/configure_record.xml: No such file or directory
+ port=
++ gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
++ grep '<cache' /root/server/sh1/configure_record.xml
grep: /root/server/sh1/configure_record.xml: No such file or directory
+ dbname=
++ grep '<cache' /root/server/sh1/configure_record.xml
grep: /root/server/sh1/configure_record.xml: No such file or directory
++ gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ user=
++ grep '<cache' /root/server/sh1/configure_record.xml
grep: /root/server/sh1/configure_record.xml: No such file or directory
++ gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'
+ pass=
+ echo 'create database if not exists `` character set utf8mb4 COLLATE utf8mb4_bin;'
+ mysql -u -p -h -P
ERROR 2005 (HY000): Unknown MySQL server host '-P' (2)
+ '[' lrecord.log ']'
[root@localhost sh1]# + nohup /root/server/sh1/../libc++/App -configure=/root/server/sh1/configure_record.xml
#!/bin/bash
PROJECT_PATH=$(cd `dirname $0`;pwd)
NAME_CONFIG="configure"
SERVER_CONFIG="configure.xml"
CENTER_CONFIG="configure_center.xml"
CROSS_CONFIG="configure_cross.xml"
PLAT_CONFIG="configure_plat.xml"
RECORD_CONFIG="configure_record.xml"
SERVER_LOG="lfile.log"
CENTER_LOG="lcenter.log"
CROSS_LOG="lcross.log"
PLAT_LOG="lplat.log"
RECORD_LOG="lrecord.log"
# CLIENT_CONFIG_FILE=$PROJECT_PATH/configure_client.xml
# MERGE_CONFIG_FILE=$PROJECT_PATH/configure_merge.xml
APP=$PROJECT_PATH/../libc++/App
SERVER_CONFIG_FILE=$PROJECT_PATH/${SERVER_CONFIG}
CENTER_CONFIG_FILE=$PROJECT_PATH/${CENTER_CONFIG}
CROSS_CONFIG_FILE=$PROJECT_PATH/${CROSS_CONFIG}
PLAT_CONFIG_FILE=$PROJECT_PATH/${PLAT_CONFIG}
RECORD_CONFIG_FILE=$PROJECT_PATH/${RECORD_CONFIG}
get_config() {
case ${1} in
game) NOW_CONFIG_FILE=${SERVER_CONFIG_FILE};;
center) NOW_CONFIG_FILE=${CENTER_CONFIG_FILE};;
cross) NOW_CONFIG_FILE=${CROSS_CONFIG_FILE};;
plat) NOW_CONFIG_FILE=${PLAT_CONFIG_FILE};;
record) NOW_CONFIG_FILE=${RECORD_CONFIG_FILE};;
*) help ;;
esac
}
## 获取子shell命令
TARGET=$1
PARAM1=$2
PARAM2=$3
PARAM3=$4
## 帮助函数
help () {
echo "gamectl 使用说明"
echo "基本语法: gamectl [start|stop|restart|update] "
echo "命令模块:"
echo "help 显示当前帮助内容"
echo "start 启动游戏服务"
echo "startbg 后台运行游戏服务"
echo "stop 关闭游戏服务"
echo "forcestop 强制关闭游戏服务"
echo "restart 重新启动游戏服务"
echo "update 更新lua脚本"
echo "startall 开启所有服务"
echo "startbase 开启跨服逻辑相关服务"
echo "stopall 关闭所有服务"
echo "updateall 更新所有服务lua脚本"
echo "center 启动中心服务"
echo "centerbg 后台启动中心服务"
echo "stopcenter 关闭中心服务"
echo "updatecenter 启动中心服务lua脚本"
echo "cross 启动跨服服务"
echo "crossbg 后台启动跨服服务"
echo "stopcross 关闭跨服服务"
echo "forcestopcross 强制关闭跨服服务"
echo "updatecross 启动跨服服务lua脚本"
# echo "record 启动后台数据服务"
# echo "plat 启动平台登录服务"
echo ""
exit 0
}
## 确认函数
confirm() {
echo "${1}""?(Yes/No): "
if [ "${2}" == "Yes" ]; then
echo "Yes(auto)"
return 0
fi
read SELECT
if [ "$SELECT" != "Yes" ]; then
exit 1
fi
return 0
}
## 设置数据库
get_sqlinfo() {
ip=`grep "<cache" ${1} | gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
port=`grep "<cache" ${1} | gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
dbname=`grep "<cache" ${1} | gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
user=`grep "<cache" ${1} | gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
pass=`grep "<cache" ${1} | gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
}
get_svrsqlinfo() {
get_config ${1}
get_sqlinfo ${NOW_CONFIG_FILE}
}
set_sqlinfo() {
get_sqlinfo ${1}
echo "create database if not exists \`${dbname}\` character set utf8mb4 COLLATE utf8mb4_bin;" \
| mysql -u${user} -p${pass} -h${ip} -P${port}
}
reset_sqlinfo() {
get_svrsqlinfo ${1}
confirm "确认删除${1}数据库${dbname}" ${PARAM2}
echo "drop database if exists \`${dbname}\`;" \
| mysql -u${user} -p${pass} -h${ip} -P${port}
}
dump_sql() {
get_svrsqlinfo ${1}
mysqldump --opt -u${user} -p${pass} -h${ip} -P${port} ${dbname} | gzip > dbdump.sql.gz
}
backup_sql() {
get_svrsqlinfo ${1}
mkdir -p "/data"
mysqldump --opt -u${user} -p${pass} -h${ip} -P${port} ${dbname} | gzip > "/data/"${dbname}_`date +%F_%H-%M`.sql.gz
}
recover_sql() {
get_config ${1}
set_sqlinfo ${NOW_CONFIG_FILE}
confirm "确认还原数据库" ${PARAM3}
gunzip < "${2}" | mysql -u${user} -p${pass} -h${ip} -P${port} ${dbname}
}
## 启动
start() {
set_sqlinfo ${1}
if [ ${2} ]; then # 后台启动
nohup $APP -configure=${1} > ${2} 2>&1 &
else # 前台启动
$APP -configure=${1}
fi
}
## 热更
update() {
tar=$PROJECT_PATH
for pid in `pgrep App`;
do
ttt=$(ps -ef | grep $pid | grep -v grep)
if [[ ${ttt} == *$tar* ]] && [[ ${ttt} == *"${1}"* ]]
then
ttt=${ttt##*libc++/App -configure=}
echo update ${ttt%%.xml*}".xml" $pid
kill -s 12 $pid
sleep 1
else
continue
fi
done
# ps -ef | grep App |grep -v grep | awk '{print $2}' | xargs kill -s 12
}
stop() {
killtype=10
if [ ${2} ]; then
killtype=${2}
fi
#kill -s 10 `ps -aux | grep App | grep -v grep | awk '{print $2}'`
tar=$PROJECT_PATH
count=0
while true
do
exist=0
for pid in `pgrep App`;
do
ttt=$(ps -ef | grep $pid | grep -v grep)
if [[ ${ttt} == *${tar}* ]] && [[ ${ttt} == *"${1}"* ]]
then
exist=1
break
fi
done
if [[ $exist -eq 0 ]]
then
break
fi
let count++
if [ ${PARAM1} ] && [ ${count} -gt ${PARAM1} ]; then
echo ${TARGET} "failed: count out" ${PARAM1}
exit 1
fi
for pid in `pgrep App`;
do
ttt=$(ps -ef | grep $pid | grep -v grep)
if [[ ${ttt} == *${tar}* ]] && [[ ${ttt} == *"${1}"* ]]
then
ttt=${ttt##*libc++/App -configure=}
echo killing ${ttt%%.xml*}".xml" $pid
kill -s ${killtype} $pid
sleep 1
else
continue
fi
done
done
}
# ## 启动客户端
# start_client()
# {
# $APP -debug -nocheck -a -configure=${CLIENT_CONFIG_FILE}
# }
# start_merge()
# {
# ip=`grep "<cache" ${MERGE_CONFIG_FILE} | gawk '{match($0, /ip[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
# port=`grep "<cache" ${MERGE_CONFIG_FILE} | gawk '{match($0, /port[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
# dbname=`grep "<cache" ${MERGE_CONFIG_FILE} | gawk '{match($0, /dbname[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
# user=`grep "<cache" ${MERGE_CONFIG_FILE} | gawk '{match($0, /user[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
# pass=`grep "<cache" ${MERGE_CONFIG_FILE} | gawk '{match($0, /pass[ \t]*=[ \t]*"([^ \t]*)"/, data); print data[1]}'`
# echo "create database if not exists ${dbname} character set utf8mb4 COLLATE utf8mb4_bin;" \
# | mysql -u${user} -p${pass} -h${ip} -P${port}
# $APP -configure=${MERGE_CONFIG_FILE} -plat=$1
# }
case $TARGET in
dropsql) reset_sqlinfo "game";;
dump) dump_sql ${PARAM1};;
reset) reset_sqlinfo ${PARAM1};;
backup) backup_sql ${PARAM1};;
recover) recover_sql ${PARAM1} ${PARAM2};;
start) start ${SERVER_CONFIG_FILE};;
startbg) start ${SERVER_CONFIG_FILE} ${SERVER_LOG};;
gamebg) start ${SERVER_CONFIG_FILE} ${SERVER_LOG};;
stop) stop ${SERVER_CONFIG};;
forcestop) stop ${SERVER_CONFIG} 9;;
restart) stop ${SERVER_CONFIG};start ${SERVER_CONFIG_FILE} ${SERVER_LOG};;
update) update ${SERVER_CONFIG};;
dropsqlbase) reset_sqlinfo "game"
reset_sqlinfo "cross"
reset_sqlinfo "center";;
startbase) start ${CENTER_CONFIG_FILE} ${CENTER_LOG}
start ${CROSS_CONFIG_FILE} ${CROSS_LOG}
start ${SERVER_CONFIG_FILE} ${SERVER_LOG};;
restartbase) stop ${SERVER_CONFIG}
stop ${CROSS_CONFIG}
stop ${CENTER_CONFIG}
start ${CENTER_CONFIG_FILE} ${CENTER_LOG}
start ${CROSS_CONFIG_FILE} ${CROSS_LOG}
start ${SERVER_CONFIG_FILE} ${SERVER_LOG};;
stopbase) stop ${SERVER_CONFIG}
stop ${CROSS_CONFIG}
stop ${CENTER_CONFIG};;
forcestopbase) stop ${SERVER_CONFIG} 9
stop ${CROSS_CONFIG} 9
stop ${CENTER_CONFIG} 9;;
updatebase) update ${CROSS_CONFIG}
update ${SERVER_CONFIG}
update ${CENTER_CONFIG};;
dropsqlall) reset_sqlinfo "game"
reset_sqlinfo "cross"
reset_sqlinfo "center"
reset_sqlinfo "plat"
reset_sqlinfo "record";;
startall) start ${CENTER_CONFIG_FILE} ${CENTER_LOG}
start ${CROSS_CONFIG_FILE} ${CROSS_LOG}
start ${SERVER_CONFIG_FILE} ${SERVER_LOG}
start ${PLAT_CONFIG_FILE} ${PLAT_LOG}
start ${RECORD_CONFIG_FILE} ${RECORD_LOG};;
restartall) stop ${NAME_CONFIG}
start ${CENTER_CONFIG_FILE} ${CENTER_LOG}
start ${CROSS_CONFIG_FILE} ${CROSS_LOG}
start ${SERVER_CONFIG_FILE} ${SERVER_LOG}
start ${PLAT_CONFIG_FILE} ${PLAT_LOG}
start ${RECORD_CONFIG_FILE} ${RECORD_LOG};;
stopall) stop ${NAME_CONFIG};;
forcestopall) stop ${NAME_CONFIG} 9;;
updateall) update ${NAME_CONFIG};;
center) start ${CENTER_CONFIG_FILE};;
centerbg) start ${CENTER_CONFIG_FILE} ${CENTER_LOG};;
stopcenter) stop ${CENTER_CONFIG};;
forcestopcenter)stop ${CENTER_CONFIG} 9;;
updatecenter) update ${CENTER_CONFIG};;
cross) start ${CROSS_CONFIG_FILE};;
crossbg) start ${CROSS_CONFIG_FILE} ${CROSS_LOG};;
stopcross) stop ${CROSS_CONFIG};;
forcestopcross) stop ${CROSS_CONFIG} 9;;
updatecross) update ${CROSS_CONFIG};;
plat) start ${PLAT_CONFIG_FILE};;
platbg) start ${PLAT_CONFIG_FILE} ${PLAT_LOG};;
stopplat) stop ${PLAT_CONFIG};;
forcestopplat) stop ${PLAT_CONFIG} 9;;
updateplat) update ${PLAT_CONFIG};;
record) start ${RECORD_CONFIG_FILE};;
recordbg) start ${RECORD_CONFIG_FILE} ${RECORD_LOG};;
stoprecord) stop ${RECORD_CONFIG};;
forcestoprecord)stop ${RECORD_CONFIG} 9;;
updaterecord) update ${RECORD_CONFIG};;
# client) start_client;;
# merge) start_merge $*;;
*) help ;;
esac
Vấn đề là cậu không có file /root/server/sh1/configure_record.xml
.
Trong file đó nên có DB credential.
Vì không có file đó, nên DB credential bị trống hết. Thế nên câu lệnh dưới đây được thực thi:
mysql -u -p -h -P
# ERROR 2005 (HY000): Unknown MySQL server host ‘-P’ (2)
Điều tương tự xảy ra với file /root/server/sh1/configure_plat.xml
Cậu phải thêm file kia vào
EDIT: Đừng comment out file đó nếu như cậu không hiểu nó.
Tớ quên mất không hỏi cậu, cậu định build dự án gì thế?
EDIT 2: cậu nên xóa password thật trên log comment mà cậu đưa tớ ở trên (trông nó giống password của production DB).
dạ e đang thực tập, sếp giao cho cài server game đó anh. Dạ anh cho e hỏi 1 câu nữa là nếu e start nginx với httpd, thì nó báo lỗi như thế này. Em cũng mới tìm hiểu, mong anh thông cảm T.T
Sau khi chạy xong lệnh đó, cậu gõ:
systemctl status nginx.service
Rồi sau đó:
ps aux | grep nginx
Rồi post kết quả lên đây xem (raw text, với markdown nhé cậu ).
EDIT: quên mất, cậu nhớ xóa username/password/host của DB ở log trên nhé! Vì cậu thực tập nên điều này quan trọng đó.
dạ e chưa biết sử dụng raw text nên mong anh thông cảm
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset : disabled)
Active: failed (Result: exit-code) since Wed 2020-09-09 12:18:45 +07; 17min a go
Process: 43883 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
Process: 43881 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 43880 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status =0/SUCCESS)
Main PID: 42609 (code=exited, status=0/SUCCESS)
Sep 09 12:18:43 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to ...
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to ...
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to ...
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to ...
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to ...
Sep 09 12:18:45 localhost.localdomain nginx[43883]: nginx: [emerg] still coul...
Sep 09 12:18:45 localhost.localdomain systemd[1]: nginx.service: control proc...
Sep 09 12:18:45 localhost.localdomain systemd[1]: Failed to start The nginx H...
Sep 09 12:18:45 localhost.localdomain systemd[1]: Unit nginx.service entered ...
Sep 09 12:18:45 localhost.localdomain systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
Và đây là của log ở dưới
root 44349 0.0 0.0 112808 964 pts/1 R+ 12:39 0:00 grep --color=auto nginx
Hm, raw text nghĩa là cậu copy text (không có chỉnh sửa gì) đó cậu
Từ log của cậu, tớ chỉ biết được nginx không được start thôi.
Phần […] trong log của cậu là do cậu tự xóa, hay nó chỉ hiển thị thế thôi vậy cậu? Nếu có thể, tớ cần thêm thông tin sau dấu […] đó cậu. Cậu có thể bổ dung được không Khoa?
Ngoài ra, cậu thử post log của câu lệnh này nữa:
journalctl -xe
Sep 09 12:18:43 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Sep 09 12:18:44 localhost.localdomain nginx[43883]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Sep 09 12:18:45 localhost.localdomain nginx[43883]: nginx: [emerg] still could not bind()
Sep 09 12:18:45 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Sep 09 12:18:45 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Sep 09 12:18:45 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Sep 09 12:18:45 localhost.localdomain systemd[1]: nginx.service failed.
dạ đây anh
Tớ hiểu rồi.
Vì có phần mềm nào đó đang sử dụng cổng 80 của cậu rồi.
Thử câu lệnh này xem cậu:
lsof -i :80
Nó sẽ hiện ra process nào đang sử dụng cổng 80. Cậu lấy process đó và sử dụng command này để biết guilty process:
ps -ef | grep <pid ở trên>
Sau đó paste kết quả lên đây xem cậu.
sau khi em dùng câu lệnh đó thì ra :
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 43304 root 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 43305 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 43306 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 43307 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 43308 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 43309 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 43310 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
httpd 44473 apache 4u IPv6 76331 0t0 TCP *:http (LISTEN)
và em ps -ef | grep
của 43304
thì nó ra ntn ạ a
root 43304 1 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 43305 43304 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 43306 43304 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 43307 43304 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 43308 43304 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 43309 43304 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 43310 43304 0 12:13 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 44473 43304 0 12:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 44510 44331 0 12:58 pts/1 00:00:00 grep --color=auto 43304
đoán chắc là server centos, có apache làm web server mặc định
tắt đi là xong
sudo systemctl stop httpd
disable nó luôn để sau này có reboot server nó khỏi start theo
sudo systemctl disable httpd
nếu mà em muốn nó chạy cùng thì được không anh
Được cậu à. Cậu chỉ cần thay đổi port của nginx thôi. Chuyển nó sang cổng 81 chẳng hạn
Cậu có thể follow hướng dẫn này: https://stackoverflow.com/questions/10829402/how-to-start-nginx-via-different-portother-than-80
dạ, nhưng mà trong /etc của em không có folder nginx
dạ sau khi em tắt bật lại thì nó có, em xin cảm ơn anh đã sp e nãy giờ <3
You’re welcome!