Jigsaw-Code / outline-server

Outline Server, developed by Jigsaw. The Outline Server is a proxy server that runs a Shadowsocks instance and provides a REST API for access key management.
https://getoutline.org/
Apache License 2.0
5.82k stars 784 forks source link

fix listen tcp 74.125.224.72:9092: bind: cannot assign requested address #451

Open elicvh opened 5 years ago

elicvh commented 5 years ago

from https://github.com/Jigsaw-Code/outline-server/issues/341 (It didn't solve my problem.) I have studied a temporary solution for your reference

自己制作镜像

mkdir outline-image

vim outline-image/cmd.sh


#!/bin/sh
#
# Copyright 2018 The Outline Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

这里ip可以直接传给容器,也可以用官方的"curl -4s https://ipinfo.io/ip"

export SB_PUBLIC_IP=${SB_PUBLIC_IP:-123.99.99.99}

export SB_PUBLIC_IP=${SB_PUBLIC_IP:-$(curl -4s https://ipinfo.io/ip)} export SB_METRICS_URL=${SB_METRICS_URL:-https://metrics-prod.uproxy.org}

sed -i 's/localhost/127.0.0.1/g' /opt/outline/persisted-state/prometheus/config.yml

重点在这句,修改main.js中使用到localhost的部分,修正监听地址错误问题.

sed -i 's/localhost/127.0.0.1/g' /root/shadowbox/app/server/main.js

Make sure we don't leak readable files to other users.

umask 0007

The maximum number of files that can be opened by ss-server greatly

influence on performance, as described here:

https://shadowsocks.org/en/config/advanced.html

#

The steps described in that page do not work for processes running

under Docker, at least on modern Debian/Ubuntu-like systems whose init

daemons allow per-service limits and ignore completely

/etc/security/limits.conf. On those systems, the Shadowbox container

will, by default, inherit the limits configured for the Docker service:

https://docs.docker.com/engine/reference/commandline/run/#set-ulimits-in-container-ulimit

#

Interestingly, we observed poor performance with large values such as 524288

and 1048576, the default values in recent releases of Ubuntu. Our

non-exhaustive testing indicates a performance cliff for Outline after values

around 270k; to stay well below of this cliff we've semi-handwaved-ly settled

upon a limit of 32k files.

ulimit -n 32768

Start cron, which is used to check for updates to the GeoIP database

crond

node app/server/main.js

------------------------------------------------------

chmd 755 /opt/outline-image/cmd.sh #让脚本在容器里可以执行

------------------------------------------------------
cd /opt/outline-image
vim Dockerfile

镜像来源

FROM quay.io/outline/shadowbox:stable COPY cmd.sh /cmd.sh

docker build -t quay.io/outline/shadowbox:localstable . docker images |grep shadowbox

------------------------------------------------------

wget https://raw.githubusercontent.com/Jigsaw-Code/outline-server/master/src/server_manager/install_scripts/install_server.sh

cd /opt/
vim install_server.sh

脚本较长,这里其他部分这里省略了.

修改镜像路径为本地的镜像

readonly SB_IMAGE=${SB_IMAGE:-quay.io/outline/shadowbox:stable}

readonly SB_IMAGE=${SB_IMAGE:-quay.io/outline/shadowbox:localstable}

------------------------------------------------------

sh install_server.sh #用修改后的脚本安装服务

------------------------------------------------------

docker exec -it shadowbox sh #进入容器 netstat -lntp|grep 9092 #可以9092正常监听了

iptables -A INPUT -p tcp --dport xxx -j ACCEPT iptables -A INPUT -p tcp --dport xxx2 -j ACCEPT iptables -A INPUT -p udp --dport xxx2 -j ACCEPT


------------------------------------------------------
到这里,我的服务都正常了.(另外注意防火墙,要开放提示端口tcp/udp)
fortuna commented 5 years ago

I'm sorry this is not working for you. Could you share the log messages around the error you are seeing?

nicholasdehnen commented 5 years ago

I am getting the same problem (on CentOS 7), logs of shadowbox docker are getting spammed with:

I2019-09-03T09:36:53.138Z 8 outline_shadowsocks_server.js:85] Restarting
I2019-09-03T09:36:53.146Z 4586 server.go:224] Metrics on http://localhost:9092/metrics
I2019-09-03T09:36:53.146Z 4586 server.go:230] Using IP-Country database at /var/lib/libmaxminddb/GeoLite2-Country.mmdb
I2019-09-03T09:36:53.147Z 4586 server.go:75] Listening TCP and UDP on port 7532
I2019-09-03T09:36:53.147Z 4586 server.go:149] Loaded 3 access keys
C2019-09-03T09:36:53.149Z 4586 server.go:222] listen tcp 85.17.x.x:9092: bind: cannot assign requested address
I2019-09-03T09:36:53.150Z 8 outline_shadowsocks_server.js:84] outline-ss-server has exited with error. Code: 1, Signal: null

..where 85.17.x.x is the ip of the server running under domain.com, which is the wrong one. The server I'm trying to install Outline on is sub.domain.com, with ip 95.217.x.x.

sudo docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' shadowbox | grep SB_ > /opt/outline/docker.env

..gives the correct ip in docker.env (SB_PUBLIC_IP=95.217.x.x).

The server is freshly installed, the only things I did before installing Outline were: a) yum update b) hostnamectl set-hostname sub.domain.com Step B seems to be the issue here, if I run hostnamectl set-hostname sub before installing Outline, the shadowbox docker starts just fine.