Nginx环境搭建

linux:

1、查看特定程序的运行端口 ps -ef|grep XXX
		XXX 如果是pid ---> 可查看运行程序
			若是运行程序 ---> 可查看端口号
2、查看所有程序的运行端口 ps aux|less
3、强制关闭程序 kill -9 端口号


4top  M - 以内存占用率大小的顺序排列进程列表 
	  q - 退出 top

5、netstat -ntlp 查看进程

搭建环境:

CentOS 7 安装后 :

yum 更新为网易源 :

http://www.cnblogs.com/xcb0730/p/6973613.html
        第一步:进入yum配置文件目录:
                cd /etc/yum.repos.d/
        第二步:备份配置文件:
                mv CentOS-Base.repo CentOS-Base.repo.bak
        第三步:下载网易的配置(或其他源配置文件):
                wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
                下载下来的文件名为 CentOS6-Base-163.repo
        第四步:重命名(重命名成配置文件中要求的文件名)
                mv CentOS6-Base-163.repo CentOS-Base.repo
        第五步:更新:
                yum update 最终完成。

安装Sun JDK:

1、centos7通过yum安装JDK1.8 ,安装之前先检查一下系统有没有自带open-jdk
      命令:
        rpm -qa |grep java
        rpm -qa |grep jdk
        rpm -qa |grep gcj
      如果没有输入信息表示没有安装。
      如果安装可以使用rpm -qa | grep java | xargs rpm -e --nodeps 批量卸载所有带有Java的文件   这句命令的关键字是java
  2、首先检索包含java的列表:yum list java*
      检索1.8的列表:yum list java-1.8*   
  3、导入jdk-8u131-linux-x64.tar.gz 
	解压 tar -zxvf jdk-8u131-linux-x64.tar.gz
  4、vim /etc/profile
	source /etc/profile
	使用命令检查是否安装成功

  5、java -version

mysql安装:

1、 下载mysql57-community-release-el7-11.noarch.rpm放到/etc/yum.repos.d 
2、 解析rpm -ivh mysql57-community-release-el7-11.noarch.rpm 
3、 生成mysql-community.repo  mysql-community-source.repo
4、more mysql-community.repo 内容:
	# Enable to use MySQL 5.6
	[mysql56-community]
	name=MySQL 5.6 Community Server
	baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
	enabled=0
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


	[mysql57-community]
	name=MySQL 5.7 Community Server
	baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
	//使用那个版本就修改
	enabled=1
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

	[mysql80-community]
	name=MySQL 8.0 Community Server
	baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
	enabled=0
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
5、安装 yum install mysql-community-server

6、删除组件 rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps 
7、查找之前老版本mysql的目录、并且删除老版本mysql的文件和库 
   find / -name mysql修改字符集在/etc/my.cnf
	1、在[mysqld]字段里加入character-set-server=utf8,如下:   
		[mysqld]  
		port = 3306  
		socket = /var/lib/mysql/mysql.sock  
		character-set-server=utf8  	
	2.查看mysql状态:systemctl status mysqld 
	   MySQL 5.7 在初始安装后(CentOS7 操作系统)会生成随机初始密码,并在 /var/log/mysqld.log 中有记录  找 password 关键字,通过 alter user 'root'@'localhost' identified by 'root' 命令,修改 root 用户的密码为 root,然后退出,重新以root用户和刚设置的密码进行登录即可。
	3.登录 mysql -u root -p
	4.创建新的用户名和密码:create user username identified by password
	5.给用户分配所有权限:grant all privileges on *.* to 'username'@'localhost' identified by 'password'
	6.5.给用户分配只读权限:grant select privileges on *.* to 'username'@'localhost' identified by 'password'
	7.允许远程访问:grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
	8.刷新:flush privileges;
	9.删除权限:REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'localhost';
	10、查看已存在的用户:
	   use mysql;
	   select user,host from user;

redis 安装:

1、centos默认的安装源在官方centos.org上,而Redis在第三方的yum源里,所以无法安装,非官方的yum推荐用fedora的epel仓库

2、使用如下命令安装第三方库: 
  yum install epel-release
3、安装redis:yum -y install redis
4、启动/停止/重启 Redis
	启动服务:systemctl start redis.service
	停止服务:systemctl stop redis.service
	重启服务:systemctl restart redis.service
	检查状态:systemctl status redis.service
	随系统启动服务:systemctl enable redis.service
	关闭随机启动:systemctl disable redis.service
5、开启远程访问:
    vim /etc/redis.conf
    #bind 0.0.0.0
    protected-mode no
    daemonize yes

zookeeper安装:

1、解压缩 zookeeper-3.4.9.tar.gz:
  tar -zxvf zookeeper-3.4.9.tar.gz
2、进入到 /usr/local/zookeeper/zookeeper-3.4.9/conf 目录中:
   cd zookeeper-3.4.9/conf/
3、复制 zoo_sample.cfg 文件的并命名为为 zoo.cfg:
   cp zoo_sample.cfg zoo.cfg
4、用 vim 打开 zoo.cfg 文件并修改其内容为如下:
# The number of milliseconds of each tick

# zookeeper 定义的基准时间间隔,单位:毫秒
tickTime=2000

# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
# dataDir=/tmp/zookeeper

# 数据文件夹
dataDir=/usr/local/services/zookeeper/zookeeper-3.4.9/data

# 日志文件夹
dataLogDir=/usr/local/services/zookeeper/zookeeper-3.4.9/logs

# the port at which the clients will connect
# 客户端访问 zookeeper 的端口号
clientPort=2181

# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

5、保存并关闭 zoo.cfg 文件:

6、进入到 /usr/local/zookeeper/zookeeper-3.4.9/bin 目录中:
   cd ../bin/

7、用 vim 打开 /etc/ 目录下的配置文件 profile:
	 vim /etc/profile
	 并在其尾部追加如下内容:
	 export ZOOKEEPER_HOME=/usr/local/services/zookeeper/zookeeper-3.4.9/
	 export PATH=$ZOOKEEPER_HOME/bin:$PATH
	 export PATH


8、使 /etc/ 目录下的 profile 文件即可生效:
	  source /etc/profile

9、启动 zookeeper 服务:
	 zkServer.sh start
	 如打印如下信息则表明启动成功:
	 ZooKeeper JMX enabled by default
	 Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
	 Starting zookeeper ... STARTED

10、查询 zookeeper 状态:
	 zkServer.sh status

11、关闭 zookeeper 服务:
	  zkServer.sh stop
	  如打印如下信息则表明成功关闭:
	  ZooKeeper JMX enabled by default
	  Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
	  Stopping zookeeper ... STOPPED

12、重启 zookeeper 服务:
zkServer.sh restart
如打印如下信息则表明重启成功:
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

防火墙

systemctl status firewalld.service

jenkins:

http://www.cnblogs.com/qixing/p/5896512.html

nexus(Maven仓库私服)的安装、配置、使用和仓库迁移

http://blog.csdn.net/kinglyjn/article/details/53585721

nginx 安装

1.http://nginx.org/en/linux_packages.html#stable稳定版本
2.在vim /etc/yum.repos.d/nginx.repo 添加
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/
    gpgcheck=0
    enabled=1
   ,记得修改OS/OSRELEASE为centos/7 
3.执行yum -y install nginx
4.rpm -ql nginx 查询nginx文件布局
5.主配置文件
    /etc/nginx
    /etc/nginx/conf.d
    /etc/nginx/conf.d/default.conf
    /etc/nginx/nginx.conf
6.缓存目录 /var/cache/nginx
7.nginx 配置参数configure arguments: 
(1)、安装目的目录或路径
    --prefix=/etc/nginx 
    --sbin-path=/usr/sbin/nginx 
    --modules-path=/usr/lib64/nginx/modules 
    --conf-path=/etc/nginx/nginx.conf 
    --error-log-path=/var/log/nginx/error.log 
    --http-log-path=/var/log/nginx/access.log 
    --pid-path=/var/run/nginx.pid 
    --lock-path=/var/run/nginx.lock
 (2)临时文件  
    --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp
 (3)设定nginx进程启动的用户和用户组    
    --user=nginx 
    --group=nginx 
 ()    
    --with-compat 
    --with-file-aio 
    --with-threads 
    --with-http_addition_module 
    --with-http_auth_request_module 
    --with-http_dav_module 
    --with-http_flv_module 
    --with-http_gunzip_module 
    --with-http_gzip_static_module 
    --with-http_mp4_module 
    --with-http_random_index_module 
    --with-http_realip_module 
    --with-http_secure_link_module 
    --with-http_slice_module 
    --with-http_ssl_module 
    --with-http_stub_status_module 
    --with-http_sub_module 
    --with-http_v2_module 
    --with-mail 
    --with-mail_ssl_module 
    --with-stream 
    --with-stream_realip_module 
    --with-stream_ssl_module 
    --with-stream_ssl_preread_module
    --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC'
()设置额外的参数将被添加到CFLASS变量
    --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong 
()设置附加的参数,连接系统库
    --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

8.  more nginx.conf 

user  nginx;  //运行用户
worker_processes  1;#启动进程,通常设置成和cpu的数量相等


#全局错误日志及PID文件
error_log  /var/log/nginx/error.log warn;//nginx错误日志
pid        /var/run/nginx.pid;


#工作模式及连接数上限
events {
  
   use   epoll;  #epoll是多路复用IO(I/O Multiplexing)中的一种方式,仅用于linux2.6以上内核,可以大大提高nginx的性能
   worker_connections  1024;#单个后台worker process进程的最大并发链接数   
   
   # 并发总数是 worker_processes 和 worker_connections 的乘积
    # 即 max_clients = worker_processes * worker_connections
    # 在设置了反向代理的情况下,max_clients = worker_processes * worker_connections / 4  为什么
     # 为什么上面反向代理要除以4,应该说是一个经验值
    # 根据以上条件,正常情况下的Nginx Server可以应付的最大连接数为:4 * 8000 = 32000
    # worker_connections 值的设置跟物理内存大小有关
    # 因为并发受IO约束,max_clients的值须小于系统可以打开的最大文件数
    # 而系统可以打开的最大文件数和内存大小成正比,一般1GB内存的机器上可以打开的文件数大约是10万左右
    # 我们来看看360M内存的VPS可以打开的文件句柄数是多少:
    # $ cat /proc/sys/fs/file-max
    # 输出 34336
    # 32000 < 34336,即并发连接总数小于系统可以打开的文件句柄总数,这样就在操作系统可以承受的范围之内
    # 所以,worker_connections 的值需根据 worker_processes 进程数目和系统可以打开的最大文件总数进行适当地进行设置
    # 使得并发总数小于操作系统可以打开的最大文件数目
    # 其实质也就是根据主机的物理CPU和内存进行配置
    # 当然,理论上的并发总数可能会和实际有所偏差,因为主机还有其他的工作进程需要消耗系统资源。
    # ulimit -SHn 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;//每次http请求

    sendfile        on;
     #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
     #对于普通应用,必须设为 on,
     #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
     #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
     
    #tcp_nopush     on;

    #连接超时时间
    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

#设定请求缓冲 client_header_buffer_size 128k; large_client_header_buffers 4 128k;

#设定虚拟主机配置
server {
    #侦听80端口
    listen    80;
    #定义使用 www.nginx.cn访问
    server_name  www.nginx.cn;

    #定义服务器的默认网站根目录位置
    root html;

    #设定本虚拟主机的访问日志
    access_log  logs/nginx.access.log  main;

    #默认请求
    location / {
        
        #定义首页索引文件的名称
        index index.php index.html index.htm;   

    }

    # 定义错误提示页面
    error_page   500 502 503 504 /50x.html;
    location = /50x.html {
    }

    #静态文件,nginx自己处理
    location ~ ^/(images|javascript|js|css|flash|media|static)/ {
        
        #过期30天,静态文件不怎么更新,过期可以设大一点,
        #如果频繁更新,则可以设置得小一点。
        expires 30d;
    }

    #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
    location ~ .php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    #禁止访问 .htxxx 文件
        location ~ /.ht {
        deny all;
    }

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值