Skip to content

Commit

Permalink
Set nginx max body to 100GB. v1.0.303
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 9, 2023
1 parent e3d99e8 commit c5e4ebf
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 62 deletions.
41 changes: 19 additions & 22 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,40 +302,37 @@ Create a CVM instance:

```bash
rm -f /tmp/lh-*.txt &&
VM_TOKEN=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 16) && echo "$VM_TOKEN" >/tmp/lh-token.txt &&
VM_TOKEN=$VM_TOKEN bash scripts/tools/tencent-cloud/helper.sh create-cvm.py 2>/tmp/lh-instance.txt && VM_INSTANCE=$(cat /tmp/lh-instance.txt) &&
bash scripts/tools/tencent-cloud/helper.sh query-cvm-ip.py --instance $VM_INSTANCE 2>/tmp/lh-ip.txt && VM_IP=$(cat /tmp/lh-ip.txt) &&
echo "Instance: $VM_INSTANCE, IP: ubuntu@$VM_IP"
echo $(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32) >/tmp/lh-token.txt &&
VM_TOKEN=$(cat /tmp/lh-token.txt) bash scripts/tools/tencent-cloud/helper.sh create-cvm.py --id /tmp/lh-instance.txt
bash scripts/tools/tencent-cloud/helper.sh query-cvm-ip.py --instance $(cat /tmp/lh-instance.txt) --id /tmp/lh-ip.txt &&
echo "Instance: $(cat /tmp/lh-instance.txt), IP: ubuntu@$(cat /tmp/lh-ip.txt), Password: $(cat /tmp/lh-token.txt)" && sleep 5 &&
bash scripts/setup-lighthouse/build.sh --ip $(cat /tmp/lh-ip.txt) --os ubuntu --user ubuntu --password $(cat /tmp/lh-token.txt) &&
bash scripts/tools/tencent-cloud/helper.sh create-image.py --instance $(cat /tmp/lh-instance.txt) --id /tmp/lh-image.txt &&
bash scripts/tools/tencent-cloud/helper.sh share-image.py --image $(cat /tmp/lh-image.txt) &&
echo "Image: $(cat /tmp/lh-image.txt) created and shared." &&
bash scripts/tools/tencent-cloud/helper.sh remove-cvm.py --instance $(cat /tmp/lh-instance.txt)
```

Run blueprint script:
Next, create a test CVM instance with the image:

```bash
VM_IP=$(cat /tmp/lh-ip.txt) && VM_TOKEN=$(cat /tmp/lh-token.txt) && VM_INSTANCE=$(cat /tmp/lh-instance.txt) &&
bash scripts/setup-lighthouse/build.sh --ip $VM_IP --os ubuntu --user ubuntu --password $VM_TOKEN &&
bash scripts/tools/tencent-cloud/helper.sh create-image.py --instance $VM_INSTANCE 2>/tmp/lh-image.txt && VM_IMAGE=$(cat /tmp/lh-image.txt) &&
bash scripts/tools/tencent-cloud/helper.sh share-image.py --image $VM_IMAGE &&
echo "Image: $VM_IMAGE created and shared."
echo $(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32) >/tmp/lh-token2.txt &&
VM_TOKEN=$(cat /tmp/lh-token2.txt) bash scripts/tools/tencent-cloud/helper.sh create-verify.py --image $(cat /tmp/lh-image.txt) --id /tmp/lh-test.txt &&
bash scripts/tools/tencent-cloud/helper.sh query-cvm-ip.py --instance $(cat /tmp/lh-test.txt) --id /tmp/lh-ip2.txt &&
echo "IP: ubuntu@$(cat /tmp/lh-ip2.txt), Password: $(cat /tmp/lh-token2.txt)" &&
echo "http://$(cat /tmp/lh-ip2.txt)"
```

Next, create a test CVM instance with the image:
Verify then cleanup the test CVM instance:

```bash
TEST_TOKEN=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 16) && VM_IMAGE=$(cat /tmp/lh-image.txt) &&
VM_TOKEN=$TEST_TOKEN bash scripts/tools/tencent-cloud/helper.sh create-verify-cvm.py --image $VM_IMAGE 2>/tmp/lh-test.txt && TEST_INSTANCE=$(cat /tmp/lh-test.txt) &&
bash scripts/tools/tencent-cloud/helper.sh query-cvm-ip.py --instance $TEST_INSTANCE 2>/tmp/lh-ip2.txt && TEST_IP=$(cat /tmp/lh-ip2.txt) &&
echo "Instance: $TEST_INSTANCE, IP: ubuntu@$TEST_IP, Password: $TEST_TOKEN" &&
echo "http://$TEST_IP"
bash scripts/tools/tencent-cloud/helper.sh remove-cvm.py --instance $(cat /tmp/lh-test.txt)
```

Then run the script to remove all the CVM, disk images, and snapshots:
After publish to lighthouse, cleanup the CVM, disk images, and snapshots:

```bash
VM_INSTANCE=$(cat /tmp/lh-instance.txt) && VM_IMAGE=$(cat /tmp/lh-image.txt) && TEST_INSTANCE=$(cat /tmp/lh-test.txt) &&
(bash scripts/tools/tencent-cloud/helper.sh remove-cvm.py --instance $TEST_INSTANCE || echo OK) &&
(bash scripts/tools/tencent-cloud/helper.sh remove-cvm.py --instance $VM_INSTANCE || echo OK) &&
(bash scripts/tools/tencent-cloud/helper.sh remove-image.py --image $VM_IMAGE || echo OK) &&
echo "Cleanup Instance: $VM_INSTANCE, Image: $VM_IMAGE OK."
bash scripts/tools/tencent-cloud/helper.sh remove-image.py --image $(cat /tmp/lh-image.txt)
```

# Tips
Expand Down
12 changes: 12 additions & 0 deletions scripts/setup-aapanel/do_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ Install() {
touch ${DATA_HOME}/config/nginx.server.conf
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi

# TODO: FIXME: Move to code.
echo "Start to setup nginx.http.conf"
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
echo "The nginx.http.conf already exists, skip"
else
cat << END > ${DATA_HOME}/config/nginx.http.conf
# Limit for upload file size
client_max_body_size 100g;
END
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
fi

# Allow network forwarding, required by docker.
# See https://stackoverflow.com/a/41453306/17679565
echo "Controls IP packet forwarding"
Expand Down
12 changes: 12 additions & 0 deletions scripts/setup-bt/do_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ Install() {
touch ${DATA_HOME}/config/nginx.server.conf
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi

# TODO: FIXME: Move to code.
echo "Start to setup nginx.http.conf"
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
echo "The nginx.http.conf already exists, skip"
else
cat << END > ${DATA_HOME}/config/nginx.http.conf
# Limit for upload file size
client_max_body_size 100g;
END
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
fi

# Allow network forwarding, required by docker.
# See https://stackoverflow.com/a/41453306/17679565
echo "Controls IP packet forwarding"
Expand Down
12 changes: 12 additions & 0 deletions scripts/setup-droplet/scripts/01-srs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ touch ${DATA_HOME}/config/nginx.server.conf
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi
echo "Create data and config files ok"

# TODO: FIXME: Move to code.
echo "Start to setup nginx.http.conf"
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
echo "The nginx.http.conf already exists, skip"
else
cat << END > ${DATA_HOME}/config/nginx.http.conf
# Limit for upload file size
client_max_body_size 100g;
END
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
fi

# Setup the nginx configuration.
rm -f /etc/nginx/nginx.conf &&
cp ${SOURCE}/platform/containers/conf/nginx.conf /etc/nginx/nginx.conf &&
Expand Down
13 changes: 6 additions & 7 deletions scripts/setup-lighthouse/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ echo "SOURCE=$SOURCE, ip=$ip, os=$os, user=$user, password=${#password}B, cleanu
sshCmd="sshpass -p $password ssh -o StrictHostKeyChecking=no"
scpCmd="sshpass -p $password scp -o StrictHostKeyChecking=no"

$sshCmd -t $user@$ip "hostname" >/dev/null 2>/dev/null &&
echo "Check sshpass ok"
if [[ $? -ne 0 ]]; then echo "Check sshpass failed"; echo "For mac to install sshpass, see https://stackoverflow.com/a/32258393/17679565"; exit 1; fi
$sshCmd -t $user@$ip "hostname" && echo "Check sshpass ok"
if [[ $ret -ne 0 ]]; then echo "Check sshpass failed"; echo "See https://stackoverflow.com/a/32258393/17679565"; exit 1; fi

SRS_HOME=/tmp/lighthouse/srs-cloud &&
rm -rf $(dirname $SRS_HOME) && mkdir -p $SRS_HOME &&
Expand All @@ -66,8 +65,8 @@ cp ${SOURCE}/mgmt/bootstrap ${SRS_HOME}/mgmt/bootstrap &&
cp ${SOURCE}/platform/containers/conf/nginx.conf ${SRS_HOME}/platform/containers/conf/nginx.conf
if [[ $? -ne 0 ]]; then echo "Copy srs-cloud failed"; exit 1; fi

tgzName=/tmp/lighthouse/srs-cloud.tar.bz2 &&
(cd $(dirname $tgzName) && rm -f $tgzName && tar jcf $tgzName $(basename $SRS_HOME)) &&
tgzName=/tmp/lighthouse/srs-cloud.zip &&
(cd $(dirname $tgzName) && rm -f $tgzName && zip -q -r $tgzName $(basename $SRS_HOME)) &&
echo "Package $tgzName ok" && ls -lh $tgzName
if [[ $? -ne 0 ]]; then echo "Package $tgzName failed"; exit 1; fi

Expand All @@ -78,11 +77,11 @@ echo "Copy $tgzName to $ip ok"
tgzFile=$(basename $tgzName) &&
SRS_NAME=$(basename $SRS_HOME) &&
echo "Run command on server: $ip" &&
echo " tar xf $tgzFile"
echo " unzip -q $tgzFile"
echo " bash ~/$SRS_NAME/scripts/setup-lighthouse/setup_lighthouse.sh"

$sshCmd -t $user@$ip "
rm -rf $SRS_NAME && tar xf $tgzFile && \
rm -rf $SRS_NAME && unzip -q $tgzFile && \
sudo bash $SRS_NAME/scripts/setup-lighthouse/setup_lighthouse.sh &&
if [[ $cleanup == yes ]]; then
sudo bash $SRS_NAME/scripts/setup-lighthouse/post_build.sh &&
Expand Down
26 changes: 21 additions & 5 deletions scripts/setup-lighthouse/setup_lighthouse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ if [[ ! -d ~lighthouse ]]; then
fi

########################################################################################################################
# Install depends services.
apt-get update -y &&
apt-get install -y git gcc g++ gdb make tree dstat docker docker.io nginx curl net-tools &&
apt-get -qqy clean
if [[ $? -ne 0 ]]; then echo "Install dependencies failed"; exit 1; fi
# Install depends services. Retry because apt-get might be busy.
for ((i=0; i<3; i++)); do
apt-get update -y &&
apt-get install -y git gcc g++ gdb make tree dstat docker docker.io nginx curl net-tools &&
apt-get -qqy clean
ret=$?; if [[ $ret -eq 0 ]]; then break; fi
sleep 5;
done
if [[ $ret -ne 0 ]]; then echo "Install dependencies failed"; exit 1; fi

echo "Enable service" &&
systemctl enable docker nginx &&
Expand Down Expand Up @@ -99,6 +103,18 @@ touch ${DATA_HOME}/config/nginx.server.conf
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi
echo "Create data and config files ok"

# TODO: FIXME: Move to code.
echo "Start to setup nginx.http.conf"
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
echo "The nginx.http.conf already exists, skip"
else
cat << END > ${DATA_HOME}/config/nginx.http.conf
# Limit for upload file size
client_max_body_size 100g;
END
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
fi

# Setup the nginx configuration.
rm -f /etc/nginx/nginx.conf &&
cp ${SOURCE}/platform/containers/conf/nginx.conf /etc/nginx/nginx.conf &&
Expand Down
13 changes: 10 additions & 3 deletions scripts/tools/tencent-cloud/create-cvm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#coding: utf-8
import dotenv, os, time, sys, tools
import dotenv, os, time, sys, tools, argparse

parser = argparse.ArgumentParser(description="TencentCloud")
parser.add_argument("--id", type=str, required=False, help="Write ID result to this file")

args = parser.parse_args()

if os.path.exists(f'{os.getenv("HOME")}/.lighthouse/.env'):
dotenv.load_dotenv(dotenv.find_dotenv(filename=f'{os.getenv("HOME")}/.lighthouse/.env'))
Expand All @@ -16,6 +21,7 @@
exit(1)

region = "ap-beijing"
print(f"Run with region={region}, id={args.id}")

images = tools.get_images(region, "Ubuntu")['ImageSet']
image = None
Expand Down Expand Up @@ -71,5 +77,6 @@
instance_detail = instance_details[0]
print(f"Instance {instance_id}, public ip={instance_detail['PublicIpAddresses'][0]}, private ip={instance_detail['PrivateIpAddresses'][0]}")

# print the instance id to stderr.
print(instance_id, file=sys.stderr)
if args.id != None:
with open(args.id, 'w') as f:
print(instance_id, file=f)
24 changes: 19 additions & 5 deletions scripts/tools/tencent-cloud/create-image.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#coding: utf-8
import dotenv, os, tools, argparse, sys
import dotenv, os, tools, argparse, sys, time, datetime

parser = argparse.ArgumentParser(description="TencentCloud")
parser.add_argument("--instance", type=str, required=False, help="The CVM instance id")
parser.add_argument("--id", type=str, required=False, help="Write ID result to this file")

args = parser.parse_args()

Expand All @@ -26,11 +27,24 @@
region = "ap-beijing"
image_name = "srs"
instance_id = args.instance
print(f"Create CVM instance={instance_id}, region={region}, image={image_name}")
image_desc = f"{image_name} from {instance_id} at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
print(f"Create CVM instance={instance_id}, region={region}, image={image_name}, desc={image_desc}, id={args.id}")

r0 = tools.create_image(region, instance_id, image_name)
r0 = tools.create_image(region, instance_id, image_name, image_desc)
image_id = r0['ImageId']
print(f"Image {image_name} created id={image_id}")

# print the instance public ip to stderr.
print(image_id, file=sys.stderr)
while True:
info = tools.query_image(region, image_id)['ImageSet']
if len(info) != 1:
raise Exception(f"Image {image_id} not found")

if info[0]['ImageState'] == 'NORMAL':
break

print(f"Image {image_id} state is {info[0]['ImageState']}, wait 5 seconds")
time.sleep(5)

if args.id != None:
with open(args.id, 'w') as f:
print(image_id, file=f)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

parser = argparse.ArgumentParser(description="TencentCloud")
parser.add_argument("--image", type=str, required=False, help="The CVM image id")
parser.add_argument("--id", type=str, required=False, help="Write ID result to this file")

args = parser.parse_args()

Expand All @@ -28,7 +29,7 @@

region = "ap-beijing"
image_id = args.image
print(f"Select image: {image_id}, {region}")
print(f"Select image: {image_id}, {region}, id={args.id}")

instance_quotas = tools.get_zone_instance(region)['InstanceTypeQuotaSet']
if len(instance_quotas) == 0:
Expand Down Expand Up @@ -72,5 +73,6 @@
instance_detail = instance_details[0]
print(f"Instance {instance_id}, public ip={instance_detail['PublicIpAddresses'][0]}, private ip={instance_detail['PrivateIpAddresses'][0]}")

# print the instance id to stderr.
print(instance_id, file=sys.stderr)
if args.id != None:
with open(args.id, 'w') as f:
print(instance_id, file=f)
8 changes: 5 additions & 3 deletions scripts/tools/tencent-cloud/query-cvm-ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

parser = argparse.ArgumentParser(description="TencentCloud")
parser.add_argument("--instance", type=str, required=False, help="The CVM instance id")
parser.add_argument("--id", type=str, required=False, help="Write ID result to this file")

args = parser.parse_args()

Expand All @@ -25,7 +26,7 @@

region = "ap-beijing"
instance_id = args.instance
print(f"Query CVM instance={instance_id}, region={region}")
print(f"Query CVM instance={instance_id}, region={region}, id={args.id}")

instance_details = tools.query_instance_detail(region, instance_id)['InstanceSet']
if len(instance_details) != 1:
Expand All @@ -35,5 +36,6 @@
private_ip = instance_detail['PrivateIpAddresses'][0]
print(f"Instance {instance_id}, public ip={public_ip}, private ip={private_ip}")

# print the instance public ip to stderr.
print(public_ip, file=sys.stderr)
if args.id != None:
with open(args.id, 'w') as f:
print(public_ip, file=f)
13 changes: 1 addition & 12 deletions scripts/tools/tencent-cloud/share-image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#coding: utf-8
import dotenv, os, tools, argparse, time
import dotenv, os, tools, argparse

parser = argparse.ArgumentParser(description="TencentCloud")
parser.add_argument("--image", type=str, required=False, help="The CVM image id")
Expand Down Expand Up @@ -31,16 +31,5 @@
account_id = os.getenv("LH_ACCOUNT")
print(f"Share image id={image_id}, region={region} to account={account_id}")

while True:
info = tools.query_image(region, image_id)['ImageSet']
if len(info) != 1:
raise Exception(f"Image {image_id} not found")

if info[0]['ImageState'] == 'NORMAL':
break

print(f"Image {image_id} state is {info[0]['ImageState']}, wait 5 seconds")
time.sleep(5)

tools.share_image(region, image_id, account_id)
print(f"Image {image_id} shared to account {account_id}")
6 changes: 4 additions & 2 deletions scripts/tools/tencent-cloud/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def delete_snapshot_and_image(region, snapshot_id):
resp = client.DeleteSnapshots(req)
return json.loads(resp.to_json_string())

def create_image(region, instance_id, image_name):
def create_image(region, instance_id, image_name, image_desc):
cred = credential.Credential(os.getenv("SECRET_ID"), os.getenv("SECRET_KEY"))
httpProfile = HttpProfile()
httpProfile.endpoint = "cvm.tencentcloudapi.com"
Expand All @@ -347,7 +347,9 @@ def create_image(region, instance_id, image_name):
req = cvm_models.CreateImageRequest()
params = {
"InstanceId": instance_id,
"ImageName": image_name
"ImageName": image_name,
"ImageDescription": image_desc,
"ForcePoweroff": "TRUE"
}
req.from_json_string(json.dumps(params))

Expand Down

0 comments on commit c5e4ebf

Please sign in to comment.