centos7编译安装nginx
安装nginx编译所需的lib库
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
yum -y install pcre pcre-devel
查看pcre(正则库)版本
pcre-config --version
进入编译目录
cd /usr/local/src
从官网下载最新的nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz
解压nginx压缩包
tar -zxvf nginx-1.16.1.tar.gz
进入解压目录
cd nginx-1.16.1
运行配置脚本(--prefix参数指定nginx安装的目录,默认安装在/usr/local/nginx )
./configure --prefix=/usr/local/nginx
编译安装nginx
make && make install
将nginx执行命令软链接到/usr/bin
ln -s /usr/local/nginx/sbin/nginx /usr/bin
启动nginx
nginx
设置开机自启动
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.l
执行nginx -h查看相关命令
[root@localhost ~]# nginx -h
nginx version: nginx/1.16.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
复制代码
查看nginx安装目录
1. 要安装 PHP 5.6,您必须使用以下命令在 CentOS 7 系统中安装并启用 EPEL 和 Remi 存储库。
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2.接下来,安装 yum-utils,它是与 yum 集成的各种实用程序,以增强其默认功能,为其提供更高级的包管理选项并使其更易于使用。它的一些重要功能包括操作存储库、随时随地启用或禁用包等等,无需任何手动配置。
# yum install yum-utils
3. yum-utils 提供的最重要的程序之一是 yum-config-manager,您可以使用它来激活 Remi 存储库作为安装各种 PHP 版本的默认存储库。例如,如果您想在 CentOS 7 上安装 PHP 5.5、PHP 5.6 或 PHP 7.2,只需启用它并如图所示安装即可
# yum-config-manager --enable remi-php55 [Install PHP 5.5]
# yum-config-manager --enable remi-php56 [Install PHP 5.6]
# yum-config-manager --enable remi-php72 [Install PHP 7.2]
4. 现在您已经启用了选定版本的 PHP,您可以安装 PHP(这里,我们选择安装 PHP 5.6)以及所有需要的模块,如下所示
# yum-config-manager --enable remi-php56 [Install PHP 5.6]
# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
需要注意的重要事项:
如果出于某种原因要降级 PHP 版本,则需要删除现有的 PHP 版本,然后重新安装带有所需模块的新 PHP。
您也可以在 Linux 上安装多个版本的 PHP,并手动选择默认使用的版本。
然后,仔细检查系统上已安装的 PHP 版本。
# php -v
安装mysql前先配置 yum 源
在
https://dev.mysql.com/downloads/repo/yum/ 找到 yum 源 rpm 安装包
rpm 安装包
安装 mysql 源
# 下载
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
用下面的命令检查 mysql 源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
mysql 源安装成功
安装 MySQL
使用 yum install 命令安装
shell> yum install -y mysql-community-server
启动 MySQL 服务
在 CentOS 7 下,新的启动/关闭服务的命令是 systemctl start|stop
shell> systemctl start mysqld
用 systemctl status 查看 MySQL 状态
shell> systemctl status mysqld
设置开机启动
shell> systemctl enable mysqld
# 重载所有修改过的配置文件
shell> systemctl daemon-reload
修改 root 本地账户密码
mysql 安装完成之后,生成的默认密码在 /var/log/mysqld.log 文件中。使用 grep 命令找到日志中的密码。
shell> grep 'temporary password' /var/log/mysqld.log
查看临时密码
首次通过初始密码登录后,使用以下命令修改密码
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
以后通过 update set 语句修改密码
mysql> use mysql;
mysql> update user set password=PASSWORD('MyNewPass5!') where user='root';
mysql> flush privileges;
注意:mysql 5.7 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 错误。查看 MySQL官网密码详细策略
添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须添加一个允许远程连接的帐户。或者修改 root 为允许远程连接(不推荐)
添加一个允许远程连接的帐户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhangsan'@'%' IDENTIFIED BY 'Zhangsan2018!' WITH GRANT OPTION;
修改 root 为允许远程连接(不推荐)
mysql> use mysql;
mysql> UPDATE user SET Host='%' WHERE User='root';
mysql> flush privileges;
设置默认编码为 utf8
mysql 安装后默认不支持中文,需要修改编码。
修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
重启mysql服务,查询编码。可以看到已经改过来了
shell> systemctl restart mysqld
shell> mysql -uroot -p
mysql> show variables like 'character%';