可选:查找已安装的安装包
rpm -qa 或者 rpm -qa |grep 包名
yum list installed 或者 yum list installed | grep ruby
查找yum和rpm的安装目录:yum安装,实质上是用RPM安装
rpm -qc 包名
-l 显示软件包中的文件列表
-c 显示配置文件列表
RPM默认安装路径如下:
/etc 一些配置文件的目录,例如/etc/init.d/mysql
/usr/bin 一些可执行文件
/usr/lib 一些程序使用的动态函数库
/usr/share/doc 一些基本的软件使用手册与帮助文档
/usr/share/man 一些man page文件
apache:
如果采用RPM包安装,安装路径应在 /etc/httpd目录下
apache配置文件:/etc/httpd/conf/httpd.conf
Apache模块路径:/usr/sbin/apachectl
web目录:/var/www/html
如果采用源代码安装,一般默认安装在/usr/local/apache2目录下
PHP:
如果采用RPM包安装,安装路径应在 /etc/目录下
php的配置文件:/etc/php.ini
如果采用源代码安装,一般默认安装在/usr/local/lib目录下
php配置文件: /usr/local/lib/php.ini
或/usr/local/php/etc/php.ini
MySQL:
如果采用RPM包安装,安装路径应在/usr/share/mysql目录下
mysqldump(备份)文件位置:/usr/bin/mysqldump
mysqli配置文件:
/etc/my.cnf或/usr/share/mysql/my.cnf
mysql数据目录在/var/lib/mysql目录下
如果采用源代码安装,一般默认安装在/usr/local/mysql目录下
1、安装工具(非必须(gcc除外)自行删减)
这里用yum安装一下在编译过程中所需要的编译工具和小程序,如:gcc、gd库、cmake等等。这么多小软件,我们不需要编译安装,因为这些软件安装后,以后并不会修改操作,只是一个工具而已。
yum install -y gcc gcc-c++ make sudo autoconf libtool-ltdl-devel gd-devel \
freetype-devel libxml2-devel libjpeg-devel libpng-devel \
openssl-devel curl-devel patch libmcrypt-devel \
libmhash-devel ncurses-devel bzip2 \
libcap-devel ntp sysklogd diffutils sendmail iptables unzip cmake
nginx安装
nginx安装:
http://nginx.org/en/download.html 寻找nginx的版本
下载到任一目录
安装依赖包:(必须:openssl、pcre、zlib ,gcc是所有安装包都依赖的)
检查openssl是否安装:rpm -qa openssl openssl-devel
检查pcre是否安装:rpm -qa pcre-devel pcre
检查zlib是否安装:rpm -qa zlib-devel zlib
关于zlib与zlib-devel的区别:
如果你安装基于 zlib 开发的程序,只需要安装 zlib 包就行了。
但是如果你要编译使用了 zlib 的源代码,则需要安装 zlib-devel。
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
wget http://nginx.org/download/nginx-1.17.1.tar.gz
解压并进入解压后的目录:tar -zxvf nginx-1.17.1.tar.gz
创建运行的用户和组:
groupadd nginx useradd -M -s /sbin/nologin -g nginx nginx 或者useradd -M -s /sbin/nologin nginx (这样也没问题:useradd nginx -M -s /sbin/nologin)
查看创建的用户 cat /etc/passwd
nginx:x:1001:1001::/home/nginx:/sbin/nologin
格式: 用户名:密码:用户id:用户所在组的id:备注:家目录:执行shell类型可执行文件命令的目录
重新赋予权限:
mkdir /usr/local/nginx chmod -R 755 /usr/local/nginx/ chown nginx:nginx /usr/local/nginx/
配置:
参数之间至少有一个空格隔开且不能有\r\n换行符
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/config/nginx.conf --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-email
./configure --prefix=/usr/loacl/nginx
--sbin-path=/usr/local/nginx
--conf-path=/usr/local/nginx/config/nginx.conf
--pid-path=/usr/local/nginx/nginx.pid
--with-http_ssl_module
--with-http_perl_module
--with-zlib=/tmp/zlib-1.2.11 非yum安装的需要指定安装目录
--with-pcre=/tmp/pcre-8.41 同上
--with-openssl=/tmp/openssl-1.0.21 同上
############
--prefix=PATH 要安装到的目录
--sbin-path=PATH 指定nginx二进制文件的路径,没指定的话这个路径依赖 --prefix 选项
--conf-path=PATH 如果在命令行未指定配置文件,那么将会通过 --prefix 指定的路径去查找配置文件
--error-log-path=PATH 错误文件路径,nginx写入错误日志文件地址
--pid-path=<path> nginx master进程pid写入的文件位置,通常在var/run下
--user=<user> worker进程运行的用户
--group=<group> worker进程运行的组
--with-http_ssl_module 开启 ssl 模块
--with-zlib=DIR 设置 指向zlib 的源码目录
--with-openssl=DIR 设置 指向openssl 的源码目录
--with-pcre=DIR设置 指向pcre 的源码目录
--with-http_stub_status_module
make && make install
安装完成可执行文件是/usr/local/nginx/sbin/nginx
校验配置文件:
/usr/local/nginx/sbin/nginx -t # 校验默认的配置文件
/usr/local/nginx/sbin/nginx -t -c /path/to/configfile # 校验指定配置文件
启动:
/usr/local/nginx/sbin/nginx #自动读取配置文件目录下的“nginx.conf”配置文件
/usr/local/nginx/sbin/nginx -c /path/to/configfile #指定配置文件启动
停止:
/usr/local/nginx/sbin/nginx -s stop # 快速关闭
/usr/local/nginx/sbin/nginx -s quit # 安全关闭
重载
/usr/local/nginx/sbin/nginx -s reload # 重载配置文件
查看版本
/usr/local/nginx/sbin/nginx -V
设置全局命令
export PATH=$PATH:/usr/local/nginx/sbin/ #PATH变量后裔可定义多个以:分割。例: PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin exprot PATH
切割日志
nginx -s reload #重新打开一个log文件,用于日志切割
防火墙放行80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙:
systemctl restart firewalld.service(centos7之前使用service iptables restart)
浏览器访问ip地址成功!
可选配置参数(官方参考)
中文翻译nginx编译安装之-./configure 参数详解
在你当前版本的解压后nginx目录下执行 ./configure --help 命令时户出现下面好多选项注意with与without:
--with开头的,默认是禁用的(没启动的,想使用的话需要在编译的时候加上)
--without开头的,默认是启用的(不想启用此模块时,可以在编译的时候加上这个参数)
--prefix=PATH 配置软件的安装目录 --sbin-path=PATH 设置可执行文件目录 --modules-path=PATH set modules path --conf-path=PATH 设置nginx.conf配件文件的路径--error-log-path=PATH 设置主请求的错误、警告、诊断的access.log日志文件的名称--pid-path=PATH 设置存储主进程id的文件名称--lock-path=PATH 设定lock文件(nginx.lock)目录--user=USER 设置工作进程使用的非特权用户的用户名,默认为nobody--group=GROUP 设置工作进程使用的非特权用户组的名称--build=NAME 设定程序编译目录 --builddir=DIR set build directory --with-select_module 允许select模块(一种轮询模式,不推荐用在高载环境) --without-select_module 不使用select模块 --with-poll_module 允许poll模块(一种轮询模式,不推荐用在高载环境)现在已经被更好的epoll(事件通知)代替了 --without-poll_module 禁用poll模块 --with-threads enable thread pool support --with-file-aio enable file AIO support --with-http_ssl_module 启用添加HTTPS协议支持到HTTP服务器的模块,该模块默认不启用。构建和运行该模块需要OpenSSL库(Apache对应:mod_ssl)--with-http_v2_module enable ngx_http_v2_module --with-http_realip_module enable ngx_http_realip_module --with-http_addition_module enable ngx_http_addition_module --with-http_xslt_module enable ngx_http_xslt_module --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module --with-http_image_filter_module enable ngx_http_image_filter_module --with-http_image_filter_module=dynamic enable dynamic ngx_http_image_filter_module --with-http_geoip_module enable ngx_http_geoip_module --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module --with-http_sub_module enable ngx_http_sub_module --with-http_dav_module enable ngx_http_dav_module --with-http_flv_module enable ngx_http_flv_module --with-http_mp4_module enable ngx_http_mp4_module --with-http_gunzip_module enable ngx_http_gunzip_module --with-http_gzip_static_module enable ngx_http_gzip_static_module --with-http_auth_request_module enable ngx_http_auth_request_module --with-http_random_index_module enable ngx_http_random_index_module --with-http_secure_link_module enable ngx_http_secure_link_module --with-http_degradation_module enable ngx_http_degradation_module --with-http_slice_module enable ngx_http_slice_module --with-http_stub_status_module enable ngx_http_stub_status_module 记录nginx基本访问状态信息等模块 --without-http_charset_module disable ngx_http_charset_module --without-http_gzip_module 禁用构建gzip压缩模块。构建和运行该模块需要zlib库 --without-http_ssi_module disable ngx_http_ssi_module --without-http_userid_module disable ngx_http_userid_module --without-http_access_module 禁用 ngx_http_access_module(控制用户对nginx的访问) --without-http_auth_basic_module disable ngx_http_auth_basic_module --without-http_mirror_module disable ngx_http_mirror_module --without-http_autoindex_module disable ngx_http_autoindex_module --without-http_geo_module disable ngx_http_geo_module --without-http_map_module disable ngx_http_map_module --without-http_split_clients_module disable ngx_http_split_clients_module --without-http_referer_module disable ngx_http_referer_module --without-http_rewrite_module 禁止构建允许HTTP服务器重定向和变更请求URI的模块。构建和运行该模块需要PCRE库 --without-http_proxy_module 禁用HTTP服务器代理模块 --without-http_fastcgi_module 禁用 ngx_http_fastcgi_module --without-http_uwsgi_module disable ngx_http_uwsgi_module --without-http_scgi_module disable ngx_http_scgi_module --without-http_grpc_module disable ngx_http_grpc_module --without-http_memcached_module disable ngx_http_memcached_module --without-http_limit_conn_module 禁用 ngx_http_limit_conn_module 限制用户并发连接数 --without-http_limit_req_module 禁用 ngx_http_limit_req_module 限制用户并发请求数 --without-http_empty_gif_module disable ngx_http_empty_gif_module --without-http_browser_module disable ngx_http_browser_module --without-http_upstream_hash_module disable ngx_http_upstream_hash_module 负载均衡相关模块 --without-http_upstream_ip_hash_module disable ngx_http_upstream_ip_hash_module --without-http_upstream_least_conn_module disable ngx_http_upstream_least_conn_module --without-http_upstream_random_modul disable ngx_http_upstream_random_module --without-http_upstream_keepalive_module disable ngx_http_upstream_keepalive_module --without-http_upstream_zone_module disable ngx_http_upstream_zone_module --with-http_perl_module 启用ngx_http_perl_module 在ngnx启用perl语言 --with-http_perl_module=dynamic enable dynamic ngx_http_perl_module --with-perl_modules_path=PATH 设置perl模块路径 --with-perl=PATH 设置perl库文件路径 --http-log-path=PATH 设置HTTP服务器的主请求的日志文件的名称--http-client-body-temp-path=PATH 设置客户端请求临时文件路径 --http-proxy-temp-path=PATH 设置http proxy临时文件路径 --http-fastcgi-temp-path=PATH 设置http fastcgi临时文件路径 --http-uwsgi-temp-path=PATH set path to store http uwsgi temporary files --http-scgi-temp-path=PATH set path to store http scgi temporary files --without-http 不使用HTTP server功能 --without-http-cache disable HTTP cache --with-mail 允许POP3/IMAP4/SMTP代理模块--with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module --with-mail_ssl_module enable ngx_mail_ssl_module --without-mail_pop3_module disable ngx_mail_pop3_module --without-mail_imap_module disable ngx_mail_imap_module --without-mail_smtp_module disable ngx_mail_smtp_module --with-stream enable TCP/UDP proxy module --with-stream=dynamic enable dynamic TCP/UDP proxy module --with-stream_ssl_module enable ngx_stream_ssl_module --with-stream_realip_module enable ngx_stream_realip_module --with-stream_geoip_module enable ngx_stream_geoip_module --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module --with-stream_ssl_preread_module enable ngx_stream_ssl_preread_module --without-stream_limit_conn_module disable ngx_stream_limit_conn_module --without-stream_access_module disable ngx_stream_access_module --without-stream_geo_module disable ngx_stream_geo_module --without-stream_map_module disable ngx_stream_map_module --without-stream_split_clients_module disable ngx_stream_split_clients_module --without-stream_return_module disable ngx_stream_return_module --without-stream_upstream_hash_module disable ngx_stream_upstream_hash_module --without-stream_upstream_least_conn_module disable ngx_stream_upstream_least_conn_module --without-stream_upstream_random_module disable ngx_stream_upstream_random_module --without-stream_upstream_zone_module disable ngx_stream_upstream_zone_module --with-google_perftools_module 允许ngx_google_perftools_module模块(调试用) --with-cpp_test_module enable ngx_cpp_test_module --add-module=PATH enable external module --add-dynamic-module=PATH enable dynamic external module --with-compat dynamic modules compatibility --with-cc=PATH 设置C编译器路径 --with-cpp=PATH 设置C预处理路径 --with-cc-opt=OPTIONS 设置C编译器参数 --with-ld-opt=OPTIONS 设置连接文件参数 --with-cpu-opt=CPU 为指定CPU优化,可选参数有: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, sparc32, sparc64, ppc64 --without-pcre 不使用pcre库文件 --with-pcre 设置PCRE库的路径,该库需要从PCRE网站下载。location指令的正则表达支持需要该库 --with-pcre=DIR set path to PCRE library sources --with-pcre-opt=OPTIONS 设置PCRE运行参数--with-pcre-jit build PCRE with JIT compilation support --with-zlib=DIR 设置zlib库的路径,ngx_http_gzip_module模块需要该库 --with-zlib-opt=OPTIONS 设置zlib运行参数--with-zlib-asm=CPU 使zlib对特定的CPU进行优化,可选参数: pentium, pentiumpro --with-libatomic force libatomic_ops library usage --with-libatomic=DIR set path to libatomic_ops library sources --with-openssl=DIR 设定OpenSSL库文件路径 --with-openssl-opt=OPTIONS 设置OpenSSL运行参数--with-debug 允许调试日志
安装MSQL(先装mysql的原因是安装过成中生成了mysql.so在安装php时直接指定mysq这个扩展,先装php后装mysql的请戳这里mysql.so的安装)
mysql安装
关掉防火墙:chkconfig iptables off
检测mysql是否默认安装了
rpm -qa | grep mysql
卸载
rpm -e mysql
yum源安装 :
https://dev.mysql.com/downloads/repo/yum/下载yum源文件 #下载后的文件名为: mysql80-community-release-el7-1.noarch.rpm #执行如下命令: rpm -ivh mysql80-community-release-el7-1.noarch.rpm #查看 yum repolist|grep mysql #安装: yum install mysql-community-server 上面默认安装的是最新的版本(8.0) 修改默认安装的版本:http://repo.mysql.com/yum里有5.5~8.0的所有源 修改下面文件的内容 vim /etc/yum.repos.d/mysql-community.repo 将[mysql80-community]下修改enabled=0 然后将你要默然安装的改为enabled=1 就ok 文件内容如下:
# Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # 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 # Enable to use MySQL 5.7 [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=0 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=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-preview] name=MySQL Tools Preview baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-cluster-7.5-community] name=MySQL Cluster 7.5 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-cluster-7.6-community] name=MySQL Cluster 7.6 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [myql-scluster-8.0-community] name=MySQL Cluster 8.0 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
启动:
service mysqld start
systemctl start mysqld.service
查看状态
service mysqld status
systemctl status mysqld.service