Skip to content

Commit 5dc233f

Browse files
committed
更新脚本
1 parent 8723890 commit 5dc233f

7 files changed

Lines changed: 217 additions & 17 deletions

File tree

codes/linux/soft/config/fastdfs/storage.conf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ store_path_count=1
110110
store_path0=/home/fdfs
111111
#store_path1=/home/fdfs2
112112

113-
# subdir_count * subdir_count directories will be auto created under each
113+
# subdir_count * subdir_count directories will be auto created under each
114114
# store_path (disk), value can be 1 to 256, default value is 256
115115
subdir_count_per_path=256
116116

@@ -129,7 +129,7 @@ tracker_server=127.0.0.1:22122
129129
### debug
130130
log_level=info
131131

132-
#unix group name to run this program,
132+
#unix group name to run this program,
133133
#not set (empty) means run by the group of current user
134134
run_by_group=
135135

@@ -152,7 +152,7 @@ allow_hosts=*
152152
# 1: random, distributted by hash code
153153
file_distribute_path_mode=0
154154

155-
# valid when file_distribute_to_path is set to 0 (round robin),
155+
# valid when file_distribute_to_path is set to 0 (round robin),
156156
# when the written file count reaches this number, then rotate to next path
157157
# default value is 100
158158
file_distribute_rotate_count=100
@@ -210,8 +210,8 @@ key_namespace=FastDFS
210210
# default value is 0 (short connection)
211211
keep_alive=0
212212

213-
# you can use "#include filename" (not include double quotes) directive to
214-
# load FastDHT server list, when the filename is a relative path such as
213+
# you can use "#include filename" (not include double quotes) directive to
214+
# load FastDHT server list, when the filename is a relative path such as
215215
# pure filename, the base path is the base path of current/this config file.
216216
# must set FastDHT server list when check_file_duplicate is true / on
217217
# please see INSTALL of FastDHT for detail
@@ -282,5 +282,4 @@ connection_pool_max_idle_time = 3600
282282
http.domain_name=
283283

284284
# the port of the web server on this storage server
285-
http.server_port=9999
286-
285+
http.server_port=7001

codes/linux/soft/config/fastdfs/tracker.conf

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ store_path=0
7171
download_server=0
7272

7373
# reserved storage space for system or other applications.
74-
# if the free(available) space of any stoarge server in
75-
# a group <= reserved_storage_space,
74+
# if the free(available) space of any stoarge server in
75+
# a group <= reserved_storage_space,
7676
# no file can be uploaded to this group.
7777
# bytes unit can be one of follows:
7878
### G or g for gigabyte(GB)
@@ -93,7 +93,7 @@ reserved_storage_space = 10%
9393
### debug
9494
log_level=info
9595

96-
#unix group name to run this program,
96+
#unix group name to run this program,
9797
#not set (empty) means run by the group of current user
9898
run_by_group=
9999

@@ -139,7 +139,7 @@ storage_sync_file_max_time = 300
139139
# if use a trunk file to store several small files
140140
# default value is false
141141
# since V3.00
142-
use_trunk_file = false
142+
use_trunk_file = false
143143

144144
# the min slot size, should <= 4KB
145145
# default value is 256 bytes
@@ -174,7 +174,7 @@ trunk_create_file_time_base = 02:00
174174
trunk_create_file_interval = 86400
175175

176176
# the threshold to create trunk file
177-
# when the free trunk file size less than the threshold, will create
177+
# when the free trunk file size less than the threshold, will create
178178
# the trunk files
179179
# default value is 0
180180
# since V3.06
@@ -184,7 +184,7 @@ trunk_create_file_space_threshold = 20G
184184
# the occupied spaces will be ignored
185185
# default value is false
186186
# since V3.09
187-
# NOTICE: set this parameter to true will slow the loading of trunk spaces
187+
# NOTICE: set this parameter to true will slow the loading of trunk spaces
188188
# when startup. you should set this parameter to true when neccessary.
189189
trunk_init_check_occupying = false
190190

@@ -258,15 +258,15 @@ use_connection_pool = false
258258
connection_pool_max_idle_time = 3600
259259

260260
# HTTP port on this tracker server
261-
http.server_port=8080
261+
http.server_port=7000
262262

263263
# check storage HTTP server alive interval seconds
264264
# <= 0 for never check
265265
# default value is 30
266266
http.check_alive_interval=30
267267

268268
# check storage HTTP server alive type, values are:
269-
# tcp : connect to the storge server with HTTP port only,
269+
# tcp : connect to the storge server with HTTP port only,
270270
# do not request and get response
271271
# http: storage check alive url must return http status 200
272272
# default value is tcp
@@ -275,4 +275,3 @@ http.check_alive_type=tcp
275275
# check storage HTTP server alive uri/url
276276
# NOTE: storage embed HTTP server support uri: /status.html
277277
http.check_alive_uri=/status.html
278-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 7001; ## 该端口为storage.conf中的http.server_port相同
3+
server_name localhost;
4+
location ~/group[0-9]/ {
5+
ngx_fastdfs_module;
6+
}
7+
error_page 500 502 503 504 /50x.html;
8+
location = /50x.html {
9+
root html;
10+
}
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
worker_processes 1;
2+
3+
#error_log logs/error.log;
4+
#error_log logs/error.log notice;
5+
#error_log logs/error.log info;
6+
pid /usr/local/nginx/logs/nginx.pid;
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
http {
13+
default_type application/octet-stream;
14+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
15+
'$status $body_bytes_sent "$http_referer" '
16+
'"$http_user_agent" "$http_x_forwarded_for"';
17+
#access_log logs/nginx-http-access.log;
18+
sendfile on;
19+
rewrite_log on;
20+
keepalive_timeout 65;
21+
22+
client_max_body_size 20m;
23+
client_body_buffer_size 128k;
24+
25+
#common header set
26+
proxy_http_version 1.1;
27+
proxy_set_header Host $host;
28+
proxy_set_header X-Real-IP $remote_addr;
29+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
30+
proxy_set_header X-Forwarded-Proto $scheme;
31+
proxy_set_header Upgrade $http_upgrade;
32+
proxy_set_header Connection "upgrade";
33+
34+
include mime.types;
35+
include conf/*.conf;
36+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=The NGINX HTTP and reverse proxy server
3+
After=syslog.target network.target remote-fs.target nss-lookup.target
4+
5+
[Service]
6+
Type=forking
7+
PIDFile=/usr/local/nginx/logs/nginx.pid
8+
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
9+
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
10+
ExecReload=/usr/local/nginx/sbin/nginx -s reload
11+
ExecStop=/bin/kill -s QUIT $MAINPID
12+
PrivateTmp=true
13+
14+
[Install]
15+
WantedBy=multi-user.target
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env bash
2+
3+
##############################################################################
4+
# console color
5+
BLACK="\033[1;30m"
6+
RED="\033[1;31m"
7+
GREEN="\033[1;32m"
8+
YELLOW="\033[1;33m"
9+
BLUE="\033[1;34m"
10+
PURPLE="\033[1;35m"
11+
CYAN="\033[1;36m"
12+
RESET="$(tput sgr0)"
13+
##############################################################################
14+
15+
printf "${PURPLE}"
16+
cat << EOF
17+
18+
###################################################################################
19+
# 安装 FastDFS 脚本
20+
# FastDFS 会被安装到 /opt/fdfs 路径。
21+
# @system: 适用于 CentOS
22+
# @author: Zhang Peng
23+
###################################################################################
24+
25+
EOF
26+
printf "${RESET}"
27+
28+
command -v yum >/dev/null 2>&1 || { echo >&2 -e "${RED}Require yum but it's not installed. Aborting.${RESET}"; exit 1; }
29+
command -v git >/dev/null 2>&1 || { echo >&2 -e "${RED}Require git but it's not installed. Aborting.${RESET}"; exit 1; }
30+
31+
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
32+
33+
root=/opt/fdfs
34+
if [[ -n $1 ]]; then
35+
root=$1
36+
fi
37+
38+
version=1.16.0
39+
if [[ -n $2 ]]; then
40+
version=$2
41+
fi
42+
43+
nginx_path=/opt/nginx
44+
if [[ -n $3 ]]; then
45+
root=$3
46+
fi
47+
48+
mkdir -p ${root}
49+
50+
echo -e "\n${GREEN}>>>>>>>>> 安装 libfastcommon${RESET}"
51+
mkdir -p ${root}/libfastcommon
52+
git clone https://github.com/happyfish100/libfastcommon.git "${root}/libfastcommon"
53+
cd ${root}/libfastcommon
54+
./make.sh && ./make.sh install
55+
56+
echo -e "\n${GREEN}>>>>>>>>> 安装 fastdfs${RESET}"
57+
mkdir -p ${root}/fastdfs
58+
git clone https://github.com/happyfish100/fastdfs.git "${root}/fastdfs"
59+
cd ${root}/fastdfs
60+
./make.sh && ./make.sh install
61+
62+
echo -e "\n${GREEN}>>>>>>>>> 安装 fastdfs-nginx-module${RESET}"
63+
mkdir -p ${root}/fastdfs-nginx-module
64+
git clone https://github.com/happyfish100/fastdfs-nginx-module.git "${root}/fastdfs-nginx-module"
65+
66+
echo -e "\n${GREEN}>>>>>>>>> 安装 nginx${RESET}"
67+
mkdir -p ${nginx_path}
68+
wget -O ${nginx_path}/nginx-${version}.tar.gz http://nginx.org/download/nginx-${version}.tar.gz
69+
tar zxf ${nginx_path}/nginx-${version}.tar.gz -C ${nginx_path}
70+
cd ${nginx_path}/nginx-${version}
71+
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=${root}/fastdfs-nginx-module/src/
72+
make && make install
73+
74+
echo -e "\n${GREEN}>>>>>>>>> fastdfs 配置文件准备${RESET}"
75+
# 配置修改参考:https://github.com/happyfish100/fastdfs/wiki
76+
77+
cp ${root}/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用
78+
cp ${root}/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用
79+
cp ${root}/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
80+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/fastdfs/tracker.conf -O /etc/fdfs/tracker.conf
81+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/fastdfs/storage.conf -O /etc/fdfs/storage.conf
82+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/fastdfs/client.conf -O /etc/fdfs/client.conf
83+
# fdfs 存储路径和服务端口(以默认形式配置)
84+
fdfs_store_path=/home/fdfs
85+
fdfs_server_port=7001
86+
ip=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')
87+
echo -e "\n${GREEN} - 修改 tracker.conf 配置${RESET}"
88+
sed -i "s#^base_path=.*#base_path=${fdfs_store_path}#g" /etc/fdfs/tracker.conf
89+
echo -e "\n${GREEN} - 修改 storage.conf 配置${RESET}"
90+
sed -i "s#^base_path=.*#base_path=${fdfs_store_path}#g" /etc/fdfs/storage.conf
91+
sed -i "s#^store_path0=.*#store_path0=${fdfs_store_path}#g" /etc/fdfs/storage.conf
92+
sed -i "s#^tracker_server=.*#tracker_server=${ip}:22122#g" /etc/fdfs/storage.conf
93+
sed -i "s#^http.server_port=.*#http.server_port=${fdfs_server_port}#g" /etc/fdfs/storage.conf
94+
echo -e "\n${GREEN} - 修改 client.conf 配置${RESET}"
95+
sed -i "s#^base_path=.*#base_path=${fdfs_store_path}#g" /etc/fdfs/client.conf
96+
sed -i "s#^tracker_server=.*#tracker_server=${ip}:22122#g" /etc/fdfs/client.conf
97+
echo -e "\n${GREEN} - 修改 mod_fastdfs.conf 配置${RESET}"
98+
sed -i "s#^url_have_group_name=.*#url_have_group_name=true#g" /etc/fdfs/mod_fastdfs.conf
99+
sed -i "s#^tracker_server=.*#tracker_server=${ip}:22122#g" /etc/fdfs/mod_fastdfs.conf
100+
sed -i "s#^store_path0=.*#store_path0=${fdfs_store_path}#g" /etc/fdfs/mod_fastdfs.conf
101+
echo -e "\n${GREEN} - 修改 nginx.conf 配置${RESET}\n"
102+
mkdir -p /usr/local/nginx/conf/conf
103+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/nginx.conf -O /usr/local/nginx/conf/nginx.conf
104+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/conf/fdfs.conf -O /usr/local/nginx/conf/conf/fdfs.conf
105+
106+
echo -e "\n${GREEN}>>>>>>>>> 启动 fastdfs ${RESET}"
107+
/etc/init.d/fdfs_trackerd start #启动tracker服务
108+
#/etc/init.d/fdfs_trackerd restart #重启动tracker服务
109+
#/etc/init.d/fdfs_trackerd stop #停止tracker服务
110+
chkconfig fdfs_trackerd on #自启动tracker服务
111+
112+
/etc/init.d/fdfs_storaged start #启动storage服务
113+
#/etc/init.d/fdfs_storaged restart #重动storage服务
114+
#/etc/init.d/fdfs_storaged stop #停止动storage服务
115+
chkconfig fdfs_storaged on #自启动storage服务
116+
117+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/nginx.service -O /usr/lib/systemd/system/nginx.service
118+
chmod +x /usr/lib/systemd/system/nginx.service
119+
#设置nginx.service为系统服务
120+
systemctl enable nginx.service
121+
##通过系统服务操作nginx
122+
systemctl start nginx.service
123+
#systemctl reload nginx.service
124+
#systemctl restart nginx.service
125+
#systemctl stop nginx.service
126+
127+
echo -e "\n>>>>>>>>> add fastdfs port"
128+
firewall-cmd --zone=public --add-port=${fdfs_server_port}/tcp --permanent
129+
firewall-cmd --zone=public --add-port=22122/tcp --permanent
130+
firewall-cmd --reload

codes/linux/soft/nginx-install.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,15 @@ tar zxf ${root}/nginx-${version}.tar.gz -C ${root}
4141
cd ${root}/nginx-${version}
4242
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
4343
make && make install
44-
/usr/local/nginx/sbin/nginx -v
44+
45+
# 设置 service
46+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/soft/config/nginx/nginx.service -O /usr/lib/systemd/system/nginx.service
47+
chmod +x /usr/lib/systemd/system/nginx.service
48+
#设置nginx.service为系统服务
49+
systemctl enable nginx.service
50+
##通过系统服务操作nginx
51+
systemctl start nginx.service
52+
#systemctl reload nginx.service
53+
#systemctl restart nginx.service
54+
#systemctl stop nginx.service
4555
cd -

0 commit comments

Comments
 (0)