windows下使用vagrantfile+install.sh快速搭建lnmp
前提:本机已安装vagrant,virtualbox
参考:https://www.jb51.net/article/136839.htm
CentOS-7, php7.1, mysql5.7, nginx
新建目录
C:\Users\Administrator\lnmp
cmd进入lnmp目录
cd lnmp
下载box
https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
vagrantbox官网地址:http://www.vagrantbox.es/
命令
vagrant box add lnmp centos-7.0-x86_64.box
vagrant box list
vagrant init lnmp
配置Vagrantfile文件
config.vm.box = "lnmp"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.ssh.insert_key = false
config.vm.network "private_network", ip: "192.168.10.12"
config.vm.synced_folder "D:/phpStudy/PHPTutorial/WWW/lnmp", "/mydata/data/api"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
启动虚拟机
vagrant up
连接虚拟机
xshell
127.0.0.1:2222 vagrant / vagrant
关于root账号
只使用 vagrant / vagrant 来登录显示权限不够。
但实际上我们并不知道root的密码,
修改密码:
sudo passwd root
输两遍
raoxiaoya
切换至root用户
su root
vi /etc/ssh/sshd_config
设置 PermitRootLogin yes
重启服务器。
使用root账号登录
root / raoxiaoya
以下为虚拟机中的操作,后续做成脚本一键安装
mkdir -m 777 /mydata/file -p
系统设置
1、系统语言
查看系统拥有语言包 locale -a
zh_CN.utf8是简体中文,如果没有zh_CN.utf8,就安装语言包,如果存在可以直接设置
vi /etc/locale.conf
LANG="zh_CN.utf8"
或者
localectl set-locale LANG=zh_CN.utf8
需要重启,可以放到最后再重启。
2、时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
查看时间 date
安装php7.1
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
检查源是否安装成功
yum repolist enabled | grep "webtatic*"
安装php扩展源
yum install -y php71w php71w-fpm php71w-mbstring php71w-common php71w-gd php71w-mcrypt php71w-mysqlnd php71w-xml php71w-cli php71w-devel php71w-pecl-memcached php71w-pecl-redis php71w-opcache php71w-curl php71w-json
注:rpm命令下载指定rpm包到本地yum仓库,可以使用yum安装的
校验是否安装成功
php -m 查看安装的扩展模块
php -v 查看版本
启动
service php-fpm start
netstat -lntp 或者 ps -ef | grep php-fpm
开机自启动
systemctl enable php-fpm.service
检查开机自启动是否设置成功
systemctl list-dependencies | grep php-fpm
安装mysql5.7
安装mysql源
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
安装mysql
yum -y install mysql-community-server install mysql-community-devel
启动mysql
service mysqld start
检查mysql启动是否正常
ps -ef | grep mysql
设置mysqld服务开机自启动
systemctl enable mysqld.service
检查mysqld开机自启动是否设置成功
systemctl list-dependencies | grep mysqld
mysql5.7以后的争强了安全机制, 所以使用yum安装,启动会系统会自动生成一个随机的密码,修改mysql密码
查看mysql的随机密码
grep 'temporary password' /var/log/mysqld.log
使用查询得到的随机密码在终端登录
mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Rxy123**';
exit
mysql -u root -p
Rxy123**
进入之后
use mysql;
update user set Host = '%' where User = 'root';
flush privileges;
使用mysql客户端才能连接
192.168.10.12
3306
root
Rxy123**
安装nginx
CentOS7 yum 安装 Nginx最新版本
下载对应当前系统版本的nginx包(package),建立nginx的yum仓库
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
或者
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
下载并安装nginx
yum install -y nginx
启动nginx服务
systemctl start nginx
默认的配置文件在 /etc/nginx 路径下
设置nginx跟目录
开机自启动
systemctl enable nginx.service
systemctl list-dependencies | grep nginx
关闭防火墙
firewall-cmd --state 查看防火墙状态
systemctl stop firewalld.service 停止firewall
systemctl disable firewalld.service 禁止firewall开机启动
访问
http://192.168.10.12
如果出现403,基本上是SElinux
查看状态
getenforce
修改状态
vi /etc/selinux/config
设置为disabled
安装redis服务
其他常用的
yum install -y lrzsz
总结
1、vagrant up 启动虚拟机
2、登录虚拟机,修改root密码,设置简体中文
3、vagrant reload 重启虚拟机
4、登录虚拟机,切换到root,进入/mydata/data/api/
install.sh文件在 D:/phpStudy/PHPTutorial/WWW/lnmp
5、sed -i 's/\r$//' install.sh
将windows平台的\n\r换成Linux下的\n,否则会报错:install.sh /bin/sh^M: 坏的解释器:没有那个文件或目录
6、./install.sh
7、mysql密码设置
脚本install.sh
#!/bin/sh
# 注:shell中的空行也要注释掉
# other
yum install -y lrzsz
mkdir -m 777 /mydata/file -p
#
# 设置时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#
# [ nginx ]
#
# 建立nginx的yum仓库
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# 安装nginx
yum install -y nginx
# 启动nginx服务
systemctl start nginx
# 开机自启动
systemctl start nginx
systemctl enable nginx.service
# 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
#
# [ php7.1 ]
#
# 建立yum仓库
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#
# 安装php及扩展
yum install -y php71w php71w-fpm php71w-mbstring php71w-common php71w-gd php71w-mcrypt php71w-mysqlnd php71w-xml php71w-cli php71w-devel php71w-pecl-memcached php71w-pecl-redis php71w-opcache php71w-curl php71w-json
# 启动
service php-fpm start
# 开机自启动
systemctl enable php-fpm.service
#
# [ mysql5.7 ]
#
# 安装mysql源
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
# yum -y localinstall /mydata/data/api/mysql57-community-release-el7-7.noarch.rpm
#
yum repolist enabled | grep "mysql.*-community.*"
# 安装mysql
yum -y install mysql-community-server install mysql-community-devel
# 启动mysql
service mysqld start
# 设置mysqld服务开机自启动
systemctl enable mysqld.service
windows下使用vagrantfile+install.sh快速搭建lnmp
最新推荐文章于 2023-12-12 20:04:31 发布