存档十一月 2020

centos7_初始化脚本.sh

#!/bin/bash

function selinux_close(){
setenforce 0
sed -i 's#^SELINUX=.*#SELINUX=disabled#' /etc/sysconfig/selinux
sed -i 's#^SELINUX=.*#SELINUX=disabled#' /etc/selinux/config
getenforce && echo "selinux run ..." || `echo "selinux is stop";exit 1`
}

function install_tools(){
rm -rf /run/yum.pid
yum clean all
yum install -y yum-axelget net-snmp.x86_64 epel-release lrzsz gcc gcc-c++ make man vim unzip wget curl lua-devel lua-static patch libxml2-devel libxslt libxslt-devel gd gd-devel ntp ntpdate screen sysstat tree rsync lsof openssh-clients iftop net-snmp libuuid-devel.x86_64 uuidd.x86_64 device-mapper-devel.x86_64 popt-devel.x86_64 popt.x86_64 popt-static.x86_64 iptables-services rdate ntp smartmontools iptraf psmisc traceroute net-tools.x86_64 tmux bash-completion
if [ $? -eq 0 ]; then
	echo "yum install is ok!!!"
else
	echo "yum install is fall !!!"
fi
}

function service_close(){
systemctl disable firewalld postfix acpid ip6tables mcelogd mdmonitor rpcbind rpcgssd &> /dev/null
systemctl disable rpcidmapd auditd haldaemon lldpad atd kdump netfs nfslock openct &> /dev/null
systemctl stop firewalld
systemctl restart iptables
systemctl enable iptables.service sshd crond &> /dev/null
echo "systemctl stop and disable some software is ok!!!"
}


function time_zone(){
echo "y"|cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &> /dev/null
echo "1 1 */1 * * ntpdate asia.pool.ntp.org" >>/var/spool/cron/root&&chmod 600 /var/spool/cron/root
echo "system time is Shanghai and ntpdate is ok!!!"
}

function innter_sys_optimization(){
cat > /etc/sysctl.conf <<EOF
net.nf_conntrack_max  = 65536
net.netfilter.nf_conntrack_max = 65536
net.ipv4.ip_forward = 0  
net.ipv4.conf.default.rp_filter = 1  
net.ipv4.conf.default.accept_source_route = 0  
kernel.sysrq = 0  
kernel.core_uses_pid = 1  
net.ipv4.tcp_syncookies = 1  
kernel.msgmnb = 65536  
kernel.msgmax = 65536  
kernel.shmmax = 68719476736  
kernel.shmall = 4294967296  
net.ipv4.tcp_max_tw_buckets = 15000
net.ipv4.tcp_sack = 1  
net.ipv4.tcp_window_scaling = 1  
net.ipv4.tcp_rmem = 4096 87380 4194304   
net.ipv4.tcp_wmem = 4096 16384 4194304   
net.core.wmem_default = 8388608  
net.core.rmem_default = 8388608  
net.core.rmem_max = 16777216  
net.core.wmem_max = 16777216  
net.core.netdev_max_backlog = 262144  
net.core.somaxconn = 262144  
net.ipv4.tcp_max_orphans = 3276800  
net.ipv4.tcp_max_syn_backlog = 262144  
net.ipv4.tcp_timestamps = 0  
net.ipv4.tcp_synack_retries = 1  
net.ipv4.tcp_syn_retries = 1  
net.ipv4.tcp_tw_recycle = 1  
net.ipv4.tcp_tw_reuse = 1  
net.ipv4.tcp_mem = 94500000 915000000 927000000   
net.ipv4.tcp_fin_timeout = 30 
net.ipv4.tcp_keepalive_time = 30  
net.ipv4.ip_local_port_range = 1024 65000
fs.file-max = 13000000 
net.ipv4.tcp_keepalive_probes=5
net.ipv4.tcp_orphan_retries=3
net.ipv4.tcp_synack_retries=2
kernel.printk_ratelimit = 30
kernel.printk_ratelimit_burst = 200
net.ipv6.conf.all.disable_ipv6=0
net.ipv6.conf.default.disable_ipv6=0
net.ipv6.conf.lo.disable_ipv6=0
EOF
sysctl -p &> /dev/null && echo "innter_sys_optimization is ok!!!" || `echo "innter_sys_optimization is fail ... ";exit 1`
}

function limit_file_num(){
cat >> /etc/security/limits.conf <<EOF
* soft nofile 1024000
* hard nofile 1024000
hive   - nofile 1024000
hive   - nproc  1024000
# End of file
EOF

ulimit -n 1024000
ulimit -HSn 102400
echo "limit_file_num is ok!!!" 
}

function history_set(){
cat >> /etc/profile <<EOF
USER_IP=\`who -u am i 2>/dev/null| awk '{print \$NF}'|sed -e 's/[()]//g'\`   
HISTFILESIZE=4000  
HISTSIZE=4000  
HISTTIMEFORMAT="%F %T \${USER_IP} \`whoami\` "  
export HISTTIMEFORMAT 
EOF
echo "history_set is ok!!!" 
}

selinux_close
install_tools
service_close
time_zone
innter_sys_optimization
limit_file_num
history_set

Next Cloud 搭建





Next Cloud 搭建
 
 
 
nginx 安装
    cat > /etc/yum.repos.d/nginx.repo <<-EOF
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    EOF
    # yum install nginx
    # systemctl restart nginx

     
php7.2安装
    # rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
    # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    # yum remove php-common
    # yum install php72w-devel php72w-pear php72w-pecl php72w-gd php72w-opcache php72w-cli php72w-pdo php72w-process php72w-pecl-apcu php72w-mcrypt php72w-mysql php72w-fpm php72w-pecl-memcached php72w-common php72w-xml php72w-mbstring php72w-pecl-igbinary
    # php -v
    # systemctl restart php-fpm
 
 
mysql安装
    # wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    # yum install mysql57-community-release-el7-10.noarch.rpm
    # yum install mysql-community-server
    # systemctl restart mysqld
    # ss -tnl
    # grep "password" /var/log/mysqld.log             \\ 最后的是初始密码
    # mysql -uroot -p
        set global validate_password_policy=LOW;       \\ 安全等级低
        set global validate_password_length=6;          \\ 密码位数6
        alter user user() identified by "123456";        \\ 设置当前登录用户的密码
        grant all privileges on *.* to 'root'@'%' identified by '123456';   \\ 所有权限
        flush privileges;


    nextcloud 安装
        # mysql -u root -p
            create database nextcloud;
            grant all privileges on nextcloud.* to nextcloud@localhost identified by '123456';
            flush privileges;
        # mkdir -p /etc/nginx/ssl/
        # openssl req -new -x509 -days 365 -nodes -out /etc/nginx/ssl/nextcloud.crt -keyout /etc/nginx/ssl/nextcloud.key
        # chmod 600 /etc/nginx/ssl/*
        # chmod 700 /etc/nginx/ssl
        # wget https://download.nextcloud.com/server/releases/nextcloud-20.0.1.zip
        # unzip nextcloud-20.0.1.zip
        # mkdir -p /data/www/
        # mv nextcloud /data/www/
        # mkdir -p /data/www/nextcloud/data/
        # chown nginx:nginx -R /data/www/nextcloud/
        # vim /etc/php-fpm.d/www.conf
            user = nginx                                 \\ 将用户和组都改为nginx
            group = nginx
            listen = 127.0.0.1:9000
            env[HOSTNAME] = $HOSTNAME                     \\ 将以下几行,去掉注释
            env[PATH] = /usr/local/bin:/usr/bin:/bin
            env[TMP] = /tmp
            env[TMPDIR] = /tmp
            env[TEMP] = /tmp
        # vim /etc/php.ini
    opcache.enable=1
    opcache.enable_cli=1
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=10000
    opcache.memory_consumption=128
    opcache.save_comments=1
    opcache.revalidate_freq=1
    upload_max_filesize = 10240M
        # mkdir -p /var/lib/php/session                        \\ 为php创建session文件夹
        # chown nginx:nginx -R /var/lib/php/session/
        # cd /etc/nginx/conf.d/
        # mv default.conf{,.bak}
        # vim nextcloud.conf
    upstream php-handler {
        server 127.0.0.1:9000;
        #server unix:/var/run/php5-fpm.sock;
    }
      
      
    server {
        listen 80;
        server_name localhost;
        # enforce https
        rewrite ^(.*)$ https://$host$1 permanent;
    }
      
      
    server {
        listen 443 ssl;
        server_name localhost;
      
        ssl_certificate /etc/nginx/ssl/nextcloud.crt;
        ssl_certificate_key /etc/nginx/ssl/nextcloud.key;
      
        # Add headers to serve security related headers
        # Before enabling Strict-Transport-Security headers please read into this
        # topic first.
        add_header Strict-Transport-Security "max-age=15768000;
        includeSubDomains; preload;";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
      
        # Path to the root of your installation
        root /data/www/nextcloud/;
      
      
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
      
      
        # The following 2 rules are only needed for the user_webfinger app.
        # Uncomment it if you're planning to use this app.
        #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
        #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
        # last;
      
      
        location = /.well-known/carddav {
          return 301 $scheme://$host/remote.php/dav;
        }
        location = /.well-known/caldav {
          return 301 $scheme://$host/remote.php/dav;
        }
      
      
        # set max upload size
        client_max_body_size 10240M;    # 上传文件最大限制,php.ini中也要修改,最后优化时会提及。
        fastcgi_buffers 64 4K;
      
        # Disable gzip to avoid the removal of the ETag header
        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
      
      
        # Uncomment if your server is build with the ngx_pagespeed module
        # This module is currently not supported.
        #pagespeed off;
      
      
        error_page 403 /core/templates/403.php;
        error_page 404 /core/templates/404.php;
      
      
        location / {
            rewrite ^ /index.php$uri;
        }
      
      
        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }
        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }
      
        location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            #Avoid sending the security headers twice
            fastcgi_param modHeadersAvailable true;
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;
        }
      
      
        location ~ ^/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri/ =404;
            index index.php;
        }
      
      
        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~* \.(?:css|js)$ {
            try_files $uri /index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=7200";
            # Add headers to serve security related headers (It is intended to
            # have those duplicated to the ones above)
            # Before enabling Strict-Transport-Security headers please read into
            # this topic first.
            add_header Strict-Transport-Security "max-age=15768000;includeSubDomains; preload;";
            add_header X-Content-Type-Options nosniff;
            add_header X-Frame-Options "SAMEORIGIN";
            add_header X-XSS-Protection "1; mode=block";
            add_header X-Robots-Tag none;
            add_header X-Download-Options noopen;
            add_header X-Permitted-Cross-Domain-Policies none;
            # Optional: Don't log access to assets
            access_log off;
        }
      
        location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
            try_files $uri /index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
        # systemctl start nginx
        # systemctl enable nginx
        # systemctl restart php-fpm
        # systemctl enable php-fpm
     
        http://192.168.10.13
     
            应用 --> 搜索 --> group folders --> 添加
            用户 --> 添加用户 添加组
            设置 --> 组文件夹