Skip to content

Commit c5e4ebf

Browse files
committed
Set nginx max body to 100GB. v1.0.303
1 parent e3d99e8 commit c5e4ebf

File tree

12 files changed

+126
-62
lines changed

12 files changed

+126
-62
lines changed

DEVELOPER.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,40 +302,37 @@ Create a CVM instance:
302302

303303
```bash
304304
rm -f /tmp/lh-*.txt &&
305-
VM_TOKEN=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 16) && echo "$VM_TOKEN" >/tmp/lh-token.txt &&
306-
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) &&
307-
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) &&
308-
echo "Instance: $VM_INSTANCE, IP: ubuntu@$VM_IP"
305+
echo $(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32) >/tmp/lh-token.txt &&
306+
VM_TOKEN=$(cat /tmp/lh-token.txt) bash scripts/tools/tencent-cloud/helper.sh create-cvm.py --id /tmp/lh-instance.txt
307+
bash scripts/tools/tencent-cloud/helper.sh query-cvm-ip.py --instance $(cat /tmp/lh-instance.txt) --id /tmp/lh-ip.txt &&
308+
echo "Instance: $(cat /tmp/lh-instance.txt), IP: ubuntu@$(cat /tmp/lh-ip.txt), Password: $(cat /tmp/lh-token.txt)" && sleep 5 &&
309+
bash scripts/setup-lighthouse/build.sh --ip $(cat /tmp/lh-ip.txt) --os ubuntu --user ubuntu --password $(cat /tmp/lh-token.txt) &&
310+
bash scripts/tools/tencent-cloud/helper.sh create-image.py --instance $(cat /tmp/lh-instance.txt) --id /tmp/lh-image.txt &&
311+
bash scripts/tools/tencent-cloud/helper.sh share-image.py --image $(cat /tmp/lh-image.txt) &&
312+
echo "Image: $(cat /tmp/lh-image.txt) created and shared." &&
313+
bash scripts/tools/tencent-cloud/helper.sh remove-cvm.py --instance $(cat /tmp/lh-instance.txt)
309314
```
310315

311-
Run blueprint script:
316+
Next, create a test CVM instance with the image:
312317

313318
```bash
314-
VM_IP=$(cat /tmp/lh-ip.txt) && VM_TOKEN=$(cat /tmp/lh-token.txt) && VM_INSTANCE=$(cat /tmp/lh-instance.txt) &&
315-
bash scripts/setup-lighthouse/build.sh --ip $VM_IP --os ubuntu --user ubuntu --password $VM_TOKEN &&
316-
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) &&
317-
bash scripts/tools/tencent-cloud/helper.sh share-image.py --image $VM_IMAGE &&
318-
echo "Image: $VM_IMAGE created and shared."
319+
echo $(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32) >/tmp/lh-token2.txt &&
320+
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 &&
321+
bash scripts/tools/tencent-cloud/helper.sh query-cvm-ip.py --instance $(cat /tmp/lh-test.txt) --id /tmp/lh-ip2.txt &&
322+
echo "IP: ubuntu@$(cat /tmp/lh-ip2.txt), Password: $(cat /tmp/lh-token2.txt)" &&
323+
echo "http://$(cat /tmp/lh-ip2.txt)"
319324
```
320325

321-
Next, create a test CVM instance with the image:
326+
Verify then cleanup the test CVM instance:
322327

323328
```bash
324-
TEST_TOKEN=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 16) && VM_IMAGE=$(cat /tmp/lh-image.txt) &&
325-
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) &&
326-
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) &&
327-
echo "Instance: $TEST_INSTANCE, IP: ubuntu@$TEST_IP, Password: $TEST_TOKEN" &&
328-
echo "http://$TEST_IP"
329+
bash scripts/tools/tencent-cloud/helper.sh remove-cvm.py --instance $(cat /tmp/lh-test.txt)
329330
```
330331

331-
Then run the script to remove all the CVM, disk images, and snapshots:
332+
After publish to lighthouse, cleanup the CVM, disk images, and snapshots:
332333

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

341338
# Tips

scripts/setup-aapanel/do_install.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ Install() {
5050
touch ${DATA_HOME}/config/nginx.server.conf
5151
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi
5252

53+
# TODO: FIXME: Move to code.
54+
echo "Start to setup nginx.http.conf"
55+
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
56+
echo "The nginx.http.conf already exists, skip"
57+
else
58+
cat << END > ${DATA_HOME}/config/nginx.http.conf
59+
# Limit for upload file size
60+
client_max_body_size 100g;
61+
END
62+
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
63+
fi
64+
5365
# Allow network forwarding, required by docker.
5466
# See https://stackoverflow.com/a/41453306/17679565
5567
echo "Controls IP packet forwarding"

scripts/setup-bt/do_install.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ Install() {
5050
touch ${DATA_HOME}/config/nginx.server.conf
5151
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi
5252

53+
# TODO: FIXME: Move to code.
54+
echo "Start to setup nginx.http.conf"
55+
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
56+
echo "The nginx.http.conf already exists, skip"
57+
else
58+
cat << END > ${DATA_HOME}/config/nginx.http.conf
59+
# Limit for upload file size
60+
client_max_body_size 100g;
61+
END
62+
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
63+
fi
64+
5365
# Allow network forwarding, required by docker.
5466
# See https://stackoverflow.com/a/41453306/17679565
5567
echo "Controls IP packet forwarding"

scripts/setup-droplet/scripts/01-srs.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ touch ${DATA_HOME}/config/nginx.server.conf
3737
if [[ $? -ne 0 ]]; then echo "Create /data/config failed"; exit 1; fi
3838
echo "Create data and config files ok"
3939

40+
# TODO: FIXME: Move to code.
41+
echo "Start to setup nginx.http.conf"
42+
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
43+
echo "The nginx.http.conf already exists, skip"
44+
else
45+
cat << END > ${DATA_HOME}/config/nginx.http.conf
46+
# Limit for upload file size
47+
client_max_body_size 100g;
48+
END
49+
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
50+
fi
51+
4052
# Setup the nginx configuration.
4153
rm -f /etc/nginx/nginx.conf &&
4254
cp ${SOURCE}/platform/containers/conf/nginx.conf /etc/nginx/nginx.conf &&

scripts/setup-lighthouse/build.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ echo "SOURCE=$SOURCE, ip=$ip, os=$os, user=$user, password=${#password}B, cleanu
4747
sshCmd="sshpass -p $password ssh -o StrictHostKeyChecking=no"
4848
scpCmd="sshpass -p $password scp -o StrictHostKeyChecking=no"
4949

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

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

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

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

8483
$sshCmd -t $user@$ip "
85-
rm -rf $SRS_NAME && tar xf $tgzFile && \
84+
rm -rf $SRS_NAME && unzip -q $tgzFile && \
8685
sudo bash $SRS_NAME/scripts/setup-lighthouse/setup_lighthouse.sh &&
8786
if [[ $cleanup == yes ]]; then
8887
sudo bash $SRS_NAME/scripts/setup-lighthouse/post_build.sh &&

scripts/setup-lighthouse/setup_lighthouse.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ if [[ ! -d ~lighthouse ]]; then
6262
fi
6363

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

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

106+
# TODO: FIXME: Move to code.
107+
echo "Start to setup nginx.http.conf"
108+
if [[ -f ${DATA_HOME}/config/nginx.http.conf && -s ${DATA_HOME}/config/nginx.http.conf ]]; then
109+
echo "The nginx.http.conf already exists, skip"
110+
else
111+
cat << END > ${DATA_HOME}/config/nginx.http.conf
112+
# Limit for upload file size
113+
client_max_body_size 100g;
114+
END
115+
if [[ $? -ne 0 ]]; then echo "Setup nginx.http.conf failed"; exit 1; fi
116+
fi
117+
102118
# Setup the nginx configuration.
103119
rm -f /etc/nginx/nginx.conf &&
104120
cp ${SOURCE}/platform/containers/conf/nginx.conf /etc/nginx/nginx.conf &&

scripts/tools/tencent-cloud/create-cvm.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#coding: utf-8
2-
import dotenv, os, time, sys, tools
2+
import dotenv, os, time, sys, tools, argparse
3+
4+
parser = argparse.ArgumentParser(description="TencentCloud")
5+
parser.add_argument("--id", type=str, required=False, help="Write ID result to this file")
6+
7+
args = parser.parse_args()
38

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

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

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

74-
# print the instance id to stderr.
75-
print(instance_id, file=sys.stderr)
80+
if args.id != None:
81+
with open(args.id, 'w') as f:
82+
print(instance_id, file=f)

scripts/tools/tencent-cloud/create-image.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#coding: utf-8
2-
import dotenv, os, tools, argparse, sys
2+
import dotenv, os, tools, argparse, sys, time, datetime
33

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

78
args = parser.parse_args()
89

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

31-
r0 = tools.create_image(region, instance_id, image_name)
33+
r0 = tools.create_image(region, instance_id, image_name, image_desc)
3234
image_id = r0['ImageId']
3335
print(f"Image {image_name} created id={image_id}")
3436

35-
# print the instance public ip to stderr.
36-
print(image_id, file=sys.stderr)
37+
while True:
38+
info = tools.query_image(region, image_id)['ImageSet']
39+
if len(info) != 1:
40+
raise Exception(f"Image {image_id} not found")
41+
42+
if info[0]['ImageState'] == 'NORMAL':
43+
break
44+
45+
print(f"Image {image_id} state is {info[0]['ImageState']}, wait 5 seconds")
46+
time.sleep(5)
47+
48+
if args.id != None:
49+
with open(args.id, 'w') as f:
50+
print(image_id, file=f)

scripts/tools/tencent-cloud/create-verify-cvm.py renamed to scripts/tools/tencent-cloud/create-verify.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

78
args = parser.parse_args()
89

@@ -28,7 +29,7 @@
2829

2930
region = "ap-beijing"
3031
image_id = args.image
31-
print(f"Select image: {image_id}, {region}")
32+
print(f"Select image: {image_id}, {region}, id={args.id}")
3233

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

75-
# print the instance id to stderr.
76-
print(instance_id, file=sys.stderr)
76+
if args.id != None:
77+
with open(args.id, 'w') as f:
78+
print(instance_id, file=f)

scripts/tools/tencent-cloud/query-cvm-ip.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

78
args = parser.parse_args()
89

@@ -25,7 +26,7 @@
2526

2627
region = "ap-beijing"
2728
instance_id = args.instance
28-
print(f"Query CVM instance={instance_id}, region={region}")
29+
print(f"Query CVM instance={instance_id}, region={region}, id={args.id}")
2930

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

38-
# print the instance public ip to stderr.
39-
print(public_ip, file=sys.stderr)
39+
if args.id != None:
40+
with open(args.id, 'w') as f:
41+
print(public_ip, file=f)

scripts/tools/tencent-cloud/share-image.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#coding: utf-8
2-
import dotenv, os, tools, argparse, time
2+
import dotenv, os, tools, argparse
33

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

34-
while True:
35-
info = tools.query_image(region, image_id)['ImageSet']
36-
if len(info) != 1:
37-
raise Exception(f"Image {image_id} not found")
38-
39-
if info[0]['ImageState'] == 'NORMAL':
40-
break
41-
42-
print(f"Image {image_id} state is {info[0]['ImageState']}, wait 5 seconds")
43-
time.sleep(5)
44-
4534
tools.share_image(region, image_id, account_id)
4635
print(f"Image {image_id} shared to account {account_id}")

scripts/tools/tencent-cloud/tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def delete_snapshot_and_image(region, snapshot_id):
335335
resp = client.DeleteSnapshots(req)
336336
return json.loads(resp.to_json_string())
337337

338-
def create_image(region, instance_id, image_name):
338+
def create_image(region, instance_id, image_name, image_desc):
339339
cred = credential.Credential(os.getenv("SECRET_ID"), os.getenv("SECRET_KEY"))
340340
httpProfile = HttpProfile()
341341
httpProfile.endpoint = "cvm.tencentcloudapi.com"
@@ -347,7 +347,9 @@ def create_image(region, instance_id, image_name):
347347
req = cvm_models.CreateImageRequest()
348348
params = {
349349
"InstanceId": instance_id,
350-
"ImageName": image_name
350+
"ImageName": image_name,
351+
"ImageDescription": image_desc,
352+
"ForcePoweroff": "TRUE"
351353
}
352354
req.from_json_string(json.dumps(params))
353355

0 commit comments

Comments
 (0)