linux服务器部署整体流程

2021-03-04  本文已影响0人  _WhatsUp_

0,最好先查看系统版本,再去找对应版本的相关教程
cat /etc/redhat-release 查看CentOS版本

1,安装nginx

sudo yum install epel-release -y

安装仓库

sudo yum install https://centos7.iuscommunity.org/ius-release.rpm -y

查看仓库里的nginx版本

yum list nginx*
image.png

安装nginx

sudo yum install nginx

开机自启动

sudo systemctl enable nginx

启动

sudo systemctl start nginx

重新载入配置

nginx -s reload
service nginx restart 重启
service nginx stop 停止
service nginx start 启动

修改/etc/nginx/conf/nginx.conf

user  nginx;
worker_processes  2;#CPU内核数

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 65535;

events {
    worker_connections  65535;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  650;
    types_hash_max_size 2048;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    
    client_max_body_size 5m;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    
    #隐藏版本号
    server_tokens off;
}

站点配置

#非www域名301跳转到www域名
server {
  listen 80;
  listen 443;
  server_name site.com;
  return 301 http://www.site.com$request_uri;
}




server {

  listen 80;
  listen 443;
  server_name  www.site.com;
  root /data/site.com/;
  index index.php index.html;
  charset utf-8;
  
#日志按日期分割
  if ($time_iso8601 ~ "(\d{4})-(\d{2})-(\d{2})") { set $time $1$2$3; }
  access_log  /var/log/nginx/access_www.site.com_${time}.log;
  error_log  /var/log/nginx/error_www.site.com_${time}.log;

  location = /robots.txt { allow all; access_log off; log_not_found off; }
  location = /favicon.ico { allow all; access_log off; log_not_found off; }

  error_page 401 /401.html;
  error_page 403 /403.html;
  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location /
  {
        #CI框架去掉index.php
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php/$1 last;
        break;
        }
    }
  
  location ~ .*\.(php|php5)?($|/)
  {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }

  location ~ /\.ht {
    deny  all;
  }

}

2,安装php5.6

切换源

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

查看仓库里的php版本

yum list php56w*
sudo yum -y install php56w php56w-mysql php56w-gd libjpeg* php56w-ldap php56w-odbc php56w-pear php56w-xml php56w-xmlrpc php56w-mbstring php56w-bcmath 
sudo yum -y install httpd php-gd56w php-intl56w php-mysql56w mod_ssl openssl mcrypt php5-mcrypt56w
sudo yum -y install php56w-mcrypt php56w-soap php56w-intl  php56w-pdo
sudo yum -y install php56w-gd  php56w-mysqlnd php56w-pdo php56w-mcrypt php56w-mbstring php56w-json php56w-opcache php56w-xml
sudo yum -y install php56w-fpm

开机自启动

sudo systemctl enable php-fpm

启动

sudo systemctl start php-fpm

停止PHP

pkill php-fpm

重启PHP的

service php-fpm restart

修改etc/php.ini文件配置
a,修改expose_php = On为expose_php = Off,功能为隐藏response里的php语言和版本的显示,提高安全性
b,修改memory_limit = 128M为想要的内存限制
c,修改post_max_size = 3M为想要的最大post长度
d,修改upload_max_filesize = 6M为想要的最大upload长度

3,安装mysql

切换源

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm

安装MySQL服务器

yum install mysql-community-server

启动MySQL

systemctl start  mysqld.service

查看MySQL运行状态

systemctl status mysqld.service

此时MySQL已经开始正常运行,需要找出root的密码

grep "password" /var/log/mysqld.log

输入初始密码,此时不能做任何事情,因为MYSQL默认必须修改密码才能正常使用

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

可通过如下命令查看完整的初始密码规则

show variables like 'validate_password';

可通过如下命令修改

set global validate_password_policy=0;
set global validate_password_length=1;

还有一个问题就是Yum Repository,以后每次 yum 操作都会自动更新,需要把这个卸载掉

yum -y remove mysql57-community-release-el7-10.noarch

登录mysql

mysql -h 主机 -P 端口 -u 用户名 -p

导出数据库.gz格式

mysqldump -hlocalhost -P3306 -u用户名 -p密码 数据库名 |gzip >文件名.sql.gz

导入.gz格式数据库

gunzip < /data/文件名.gz | mysql -u用户名 -p密码 数据库名

4,安装redis

查看仓库里的redis版本

yum list | grep redis

安装

yum install redis

查看redis的配置文件

whereis redis

查看redis的相关执行文件路径

which is redis

修改密码在redis.conf中修改。找到requirepass 把后面的密码改掉。

重启

systemctl start redis.service

设置redis服务器端开机自启(只需要设置一次即可)

systemctl enable(disable则为取消) redis.service

其他相关操作

systemctl status(查看运行状态)、stop(停止运行) redis.service

5,安装SVN

安装

yum install subversion

创建SVN主目录

mkdir  -p /svndata

创建SVN分目录

mkdir  -p /svndata/project1

svnadmin create /svndata/project1
svnadmin create /svndata/project2
svnadmin create /svndata/project3
...

创建完之后,/svndata/project1目录下会生成conf文件夹

修改authz文件:

[groups]
group1 = harry,sally,&joe
[/]
@group1 = rw
* =

修改passwd文件:

[users]
harry = harryssecret

将authz文件和passwd文件移动到SVN主目录/svndata下

只保留svnserve.conf文件并修改:

anon-access = none
auth-access = write
password-db = ../../conf/passwd
authz-db = ../../conf/authz

启动SVN,后边可以修改端口号

svnserve -d -r "/svndata" --listen-port 8443

停止SVN

killall svnserve

SVN服务器路径为:

svn://IP地址:8443/project1/

如果要设置服务器文件自动更新到站点,则要先迁出到服务器

svn checkout svn://IP地址:8443/project1/ /data/project1/

设置钩子文件
/svndata/project1/hooks/目录新建post-commit文件,并设置777权限,很重要

#!/bin/sh
export LANG=en_US.UTF-8
SVN_PATH=/usr/bin/svn
WEB_PATH=/data/project1/
$SVN_PATH update $WEB_PATH --username 用户名 --password 密码

更新文件:

svn update

清理:

svn cleanup

要先cd到站点目录

上一篇下一篇

猜你喜欢

热点阅读