前言:
此时朋友们对“centos443”可能比较关心,我们都想要分析一些“centos443”的相关知识。那么小编在网摘上收集了一些对于“centos443””的相关知识,希望咱们能喜欢,兄弟们快快来了解一下吧!最近很多博友私聊我说,文章写得简单易懂,也运行起来了,但是还是觉得麻烦,希望一个命令就部署完服务器环境。整合爬坑不易,您的点赞和关注是最大的动力。更多干货在来的路上,谢谢您的支持
1. 主题整合 nginx:1.18.0整合 mysql:5.7.30整合 redis:5.0.9整合 mongodb:4.4.0整合 jdk:82. 事前准备可联网且干净的centos7环境,centos7 镜像下载链接:提前下载百度云已下载好的文件,我已经将主题内的软件包下载并上传到了百度云: 密码: dq7n下载好后,把 sh文件夹和service文件夹 放在 /home 目录下面3.文件包含
4.执行脚本(执行2步命令,等待运行完成,服务器环境就安装完啦)
sh /home/sh/install.sh jdk nginx redis mysql mongodbsource /etc/profile5.安装效果显示图目录解说
config(配置文件)(统一配置更方便)
logs(日志文件)(统一查看更方便)6.题外话jdk 安装脚本
#!/bin/bash# 这里要的jdk要写成你自己的版本,要和上传的对应tar -zxvf /home/service/jdk-8u161-linux-x64.tar.gz -C /home/servicemv /home/service/jdk1.8.0_161 /home/service/java # 文件追加,注意$PATH会被解析,# 方案1:加转义字符,例子(\$PATH)# 方案2:EOF 加反斜杠,或用单引号、双引号包围 。适用变量多的情况cat <<'EOF'>> /etc/profile# 设置java 环境export JAVA_HOME=/home/service/javaexport JRE_HOME=/home/service/java/jreexport CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libexport PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binEOFnginx 安装脚本
#!/bin/bashyum -y install gcc pcre pcre-devel zlib openssl openssl-develtar -xzvf /home/service/nginx-1.18.0.tar.gz -C /home/servicecd /home/service/nginx-1.18.0./configure --prefix=/home/service/nginx --with-http_ssl_modulemake installmkdir -p /home/service/nginx/myconfig/mkdir -p /home/service/nginx/myconfig/conf.dmkdir -p /home/service/nginx/mylogs/# 创建nginx配置文件ln -s /home/service/nginx/conf/nginx.conf /home/service/nginx/myconfig/nginx.confcat <<'EOF'> /home/service/nginx/myconfig/nginx.conf#user nginx nginx;#user root;worker_processes auto; error_log /home/service/nginx/mylogs/error.log warn;#pid /var/run/nginx.pid; worker_rlimit_nofile 65535;events { use epoll; worker_connections 65535;} http { include mime.types; default_type application/octet-stream; fastcgi_intercept_errors on; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /home/service/nginx/mylogs/access.log main; limit_conn_zone $binary_remote_addr zone=conn:10m; limit_req_zone $binary_remote_addr zone=allips:10m rate=50r/s; server_names_hash_bucket_size 128; client_header_buffer_size 128k; large_client_header_buffers 4 128k; client_max_body_size 20m; client_body_timeout 120; server_tokens off; sendfile on; tcp_nopush on; keepalive_timeout 65; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_comp_level 2; gzip_vary on; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; include /home/service/nginx/myconfig/conf.d/*.conf;}EOF # 软链mkdir -p /home/configln -s /home/service/nginx/myconfig /home/config/nginxmkdir -p /home/logsln -s /home/service/nginx/mylogs /home/logs/nginxcat <<'EOF'> /home/service/nginx/myconfig/conf.d/nginx.conf#此配置文件为websocketmap $http_upgrade $connection_upgrade { default upgrade; '' close;} #upstream dist { #server 127.0.0.1:8123;#} #80端口转向443#server { #listen 80; #server_name 域名.com,www.域名.com; #return 301 .域名.com$request_uri;#} #非www重定向www#server { #listen 443; #server_name 域名.com; #return 301 .域名.com$request_uri;#} server { listen 80; #listen 443 default_server ssl; #server_name www.域名.com; server_name localhost; root /home/service/nginx/html; index index.html index.htm; #location ~*\.(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ { # root /home/service/nginx/html; #} #下载目录 #location /download { #rewrite ^/download/(.*)$ /$1 break; #add_header Content-Type "application/octet-stream;charset=utf-8"; #add_header Content-Disposition "attachment; filename*=utf-8'zh_cn'$arg_n"; #root /home/www/html/downloadF; #autoindex on; #autoindex_exact_size off; #} #配置https #ssl_certificate /home/config/nginx/sslfile/1_www.域名.com_bundle.crt; #ssl_certificate_key /home/config/nginx/sslfile/2_www.域名.com.key; #ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; #ssl_prefer_server_ciphers on; #ssl_session_cache shared:SSL:10m; #ssl_session_timeout 10m; #ssl_buffer_size 1400; location /api { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_connect_timeout 60s; proxy_read_timeout 60s; proxy_send_timeout 60s; proxy_buffer_size 512k; proxy_buffering on; proxy_buffers 8 512k; proxy_busy_buffers_size 1024k; proxy_max_temp_file_size 100M; proxy_pass ; # proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Origin ""; #限制TCP并发连接数100/s limit_conn conn 100; }}EOFcat <<'EOF'> /home/service/nginx/myconfig/nginx.service[Unit]Description=nginxAfter=network.target [Service]Type=forkingExecStart=/home/service/nginx/sbin/nginx -c /home/service/nginx/conf/nginx.confExecReload=/home/service/nginx/sbin/nginx restartExecStop=/home/service/nginx/sbin/nginx stopPrivateTmp=true[Install]WantedBy=multi-user.targetEOFcp /home/config/nginx/nginx.service /lib/systemd/system/nginx.service systemctl enable nginx.servicesystemctl start nginx.serviceservice nginx statusmysql 安装脚本
#!/bin/bash# 解压mysql文件 tar -zxvf /home/service/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /home/servicemv /home/service/mysql-5.7.30-linux-glibc2.12-x86_64 /home/service/mysqlmkdir -p /home/service/mysql/myconfigmkdir -p /home/service/mysql/mylogs# 创建mysql配置文件cat <<'EOF'> /home/service/mysql/myconfig/my.cnf[mysqld]character_set_server=utf8mb4basedir=/home/service/mysqldatadir=/home/service/mysql/dataport = 3306log-error=/home/service/mysql/mylogs/mysqld.log#不开启sql严格模式sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"slow_query_log=ONslow_query_log_file=/home/service/mysql/mylogs/slowquery.loglong_query_time=3log-queries-not-using-indexes=ONlower_case_table_names=1EOFmkdir -p /home/configmkdir -p /home/logsln -s /home/service/mysql/myconfig /home/config/mysqlln -s /home/service/mysql/mylogs /home/logs/mysql# 创建mysql安装脚本groupadd mysqluseradd -r -g mysql mysqlchown -R mysql:mysql /home/service/mysqlcp -rf /home/service/mysql/myconfig/my.cnf /etc/my.cnf/home/service/mysql/bin/mysqld --initialize --user=mysql --datadir=/home/service/mysql/data --basedir=/home/service/mysqlcp /home/service/mysql/support-files/mysql.server /etc/init.d/mysqlsed -i "s/^basedir=$/basedir=\/home\/service\/mysql/g" /etc/init.d/mysqlsed -i "s/^datadir=$/datadir=\/home\/service\/mysql\/data/g" /etc/init.d/mysqlchkconfig --add mysqlchkconfig mysql onchkconfig --level 345 mysql onservice mysql startcat <<'EOF'>> /etc/profileexport MYSQL_HOME=/home/service/mysqlexport PATH=$PATH:$MYSQL_HOME/binEOF# 查看初始密码grep 'password' /home/service/mysql/mylogs/mysqld.logredis 安装脚本
#!/bin/bashyum -y install gcctar -xzvf /home/service/redis-5.0.9.tar.gz -C /home/service/mv /home/service/redis-5.0.9 /home/service/rediscd /home/service/redismakemkdir -p /home/configmkdir -p /home/service/redis/myconfigcp /home/service/redis/redis.conf /home/service/redis/myconfig/ln -s /home/service/redis/myconfig /home/config/redissed -i "s/daemonize no/daemonize yes/g" /home/service/redis/myconfig/redis.confsed -i "s/# requirepass foobared/requirepass 123456/g" /home/service/redis/myconfig/redis.conf cat <<'EOF'> /home/service/redis/myconfig/redis.service[Unit]Description=The redis-server Process ManagerAfter=syslog.target network.target[Service]Type=forkingPIDFile=/var/run/redis_6379.pidExecStart=/home/service/redis/src/redis-server /home/service/redis/myconfig/redis.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPID[Install]WantedBy=multi-user.targetEOF cp /home/service/redis/myconfig/redis.service /lib/systemd/system/redis.servicesystemctl enable redis.servicesystemctl start redis.servicesystemctl status redis.servicecat <<'EOF'>> /etc/profileexport REDIS_HOME=/home/service/redisexport PATH=$PATH:$REDIS_HOME/srcEOFmongodb 安装脚本
#!/bin/bashtar -xzvf /home/service/mongodb-linux-x86_64-rhel70-4.4.0.tgz -C /home/service/mv /home/service/mongodb-linux-x86_64-rhel70-4.4.0 /home/service/mongodbmkdir -p /home/service/mongodb/myconfigln -s /home/service/mongodb/myconfig /home/config/mongodbcat <<'EOF'> /home/service/mongodb/myconfig/mongodb.confdbpath = /home/service/mongodb/data/dblogpath = /home/service/mongodb/data/logs/mongodb.logport = 27017# 测试下可以0.0.0.0,正式环境:127.0.0.1bind_ip=0.0.0.0fork = true#nohttpinterface = trueauth=trueEOF # 软链ln -s /home/service/mongodb/data/logs /home/logs/mongodbmkdir -p /home/service/mongodb/data/dbmkdir -p /home/service/mongodb/data/logs cat <<'EOF'> /home/service/mongodb/myconfig/mongodb.service[Unit]Description=mongodbAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingExecStart=/home/service/mongodb/bin/mongod --config /home/service/mongodb/myconfig/mongodb.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/home/service/mongodb/bin/mongod --shutdown --config /home/service/mongodb/myconfig/mongodb.confPrivateTmp=true[Install]WantedBy=multi-user.targetEOF cp /home/service/mongodb/myconfig/mongodb.service /lib/systemd/system/mongodb.servicesystemctl enable mongodb.servicesystemctl start mongodb.serviceservice mongodb statuscat <<'EOF'>> /etc/profileexport MONGODB_HOME=/home/service/mongodbexport PATH=$PATH:$MONGODB_HOME/binEOFfirewall-cmd --zone=public --add-port=27017/tcp --permanentfirewall-cmd --reload
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #centos443 #centos服务器环境 #centos 65 命令