捡便宜买了一台新机器,需要配置一下环境。
虽然现在都用docker了,阿里云的k8s可以直接用,但是自己的单台服务器除了docker,php和niginx还是缺少不了。所以安装的是nginx+php+docker(mysql不装了,现在用云数据库,程序和数据彻底分开放了)
(除了php7.3 nginx docker,还有些必备的git,composer,docker-compose,node)
1准备
// 看下系统
# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
# yum remove httpd* php*
已加载插件:fastestmirror, langpacks
参数 httpd* 没有匹配
参数 php* 没有匹配
不删除任何软件包
2更新yum源
# cd /etc/yum.repos.d/
// 查看当前的repo有哪些
# ls -al
// 删除所有源
# rm -rf /etc/yum.repos.d/*.repo
// 下载阿里云源
# wget http://mirrors.aliyun.com/repo/Centos-7.repo
// 安装epel(epel才有nginx)
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
// 安装remi才有php7
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
// 清理yum缓存
# yum clean all
已加载插件:langpacks, versionlock
正在清理软件源: base extras updates
Cleaning up everything
//makecache建立一个缓存,以后用install时就在缓存中搜索,提高了速度。
# yum makecache
已加载插件:langpacks, versionlock
.....
元数据缓存已建立
// 再次查看所有repo
# ls -al
# yum repolist
// 升级一下吧
# yum update
// 省略一万字 大概300多个更新,阿里云源下载每秒3m左右 很快
3安装nginx
# yum install nginx
// 输出省略一万字
========================================================================================================
Package 架构 版本 源 大小
========================================================================================================
正在安装:
nginx x86_64 1:1.16.1-1.el7 epel 562 k
为依赖而安装:
dejavu-fonts-common noarch 2.33-6.el7 os 64 k
dejavu-sans-fonts noarch 2.33-6.el7 os 1.4 M
fontconfig x86_64 2.13.0-4.3.el7 os 254 k
fontpackages-filesystem noarch 1.44-8.el7 os 9.9 k
gd x86_64 2.0.35-26.el7 os 146 k
gperftools-libs x86_64 2.6.1-1.el7 os 272 k
libX11 x86_64 1.6.7-2.el7 os 607 k
libX11-common noarch 1.6.7-2.el7 os 164 k
libXau x86_64 1.0.8-2.1.el7 os 29 k
libXpm x86_64 3.5.12-1.el7 os 55 k
libxcb x86_64 1.13-1.el7 os 214 k
libxslt x86_64 1.1.28-5.el7 os 242 k
nginx-all-modules noarch 1:1.16.1-1.el7 epel 19 k
nginx-filesystem noarch 1:1.16.1-1.el7 epel 21 k
nginx-mod-http-image-filter x86_64 1:1.16.1-1.el7 epel 30 k
nginx-mod-http-perl x86_64 1:1.16.1-1.el7 epel 39 k
nginx-mod-http-xslt-filter x86_64 1:1.16.1-1.el7 epel 29 k
nginx-mod-mail x86_64 1:1.16.1-1.el7 epel 57 k
nginx-mod-stream x86_64 1:1.16.1-1.el7 epel 84 k
事务概要
========================================================================================================
安装 1 软件包 (+19 依赖软件包)
总下载量:4.2 M
安装大小:14 M
# systemctl enable nginx.service // 设置开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
systemctl start nginx.service // 启动ngixn
此时打开你的ip,应该能看到wellcome to centos,如果没有,那就炸了,去看下安全组的端口是不是开了,
同时也看下其他端口,和安全组设置
4安装php
// 全家桶 装全,因为这台机器不存数据,数据用云数据库和oss,所以这里随便装
# yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll
已安装:
php73-php-bcmath.x86_64 0:7.3.15-1.el7.remi php73-php-cli.x86_64 0:7.3.15-1.el7.remi
php73-php-fpm.x86_64 0:7.3.15-1.el7.remi php73-php-gd.x86_64 0:7.3.15-1.el7.remi
php73-php-json.x86_64 0:7.3.15-1.el7.remi php73-php-mbstring.x86_64 0:7.3.15-1.el7.remi
php73-php-mysqlnd.x86_64 0:7.3.15-1.el7.remi php73-php-opcache.x86_64 0:7.3.15-1.el7.remi
php73-php-pdo.x86_64 0:7.3.15-1.el7.remi php73-php-pecl-crypto.x86_64 0:0.3.1-5.el7.remi
php73-php-pecl-geoip.x86_64 0:1.1.1-6.el7.remi php73-php-pecl-mcrypt.x86_64 0:1.0.3-1.el7.remi
php73-php-recode.x86_64 0:7.3.15-1.el7.remi php73-php-snmp.x86_64 0:7.3.15-1.el7.remi
php73-php-soap.x86_64 0:7.3.15-1.el7.remi
作为依赖被安装:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7
environment-modules.x86_64 0:3.2.10-10.el7 gd-last.x86_64 0:2.2.5-10.el7.remi
libargon2.x86_64 0:20161029-3.el7 libcgroup.x86_64 0:0.41-21.el7
libmcrypt.x86_64 0:2.5.8-13.el7 libsemanage-python.x86_64 0:2.5-14.el7
libwebp7.x86_64 0:1.0.3-1.el7.remi lm_sensors-libs.x86_64 0:3.4.0-8.20160601gitf9185e5.el7
net-snmp.x86_64 1:5.7.2-43.el7_7.3 net-snmp-agent-libs.x86_64 1:5.7.2-43.el7_7.3
net-snmp-libs.x86_64 1:5.7.2-43.el7_7.3 oniguruma5.x86_64 0:6.9.4-1.el7.remi
perl-Data-Dumper.x86_64 0:2.145-3.el7 php73-php-common.x86_64 0:7.3.15-1.el7.remi
php73-runtime.x86_64 0:2.0-1.el7.remi policycoreutils-python.x86_64 0:2.5-33.el7
python-IPy.noarch 0:0.75-6.el7 recode.x86_64 0:3.6-38.el7
setools-libs.x86_64 0:3.3.8-4.el7 tcl.x86_64 1:8.5.13-8.el7
完毕!
// 开机启动
# systemctl enable php-fpm.service
// 启动
# systemctl start php-fpm.service
# php73 -v
PHP 7.3.15 (cli) (built: Feb 18 2020 09:25:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.15, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.15, Copyright (c) 1999-2018, by Zend Technologies
此时php已经安装完毕,建议建一个nginx conf和index.php,输出phpinfo();测试下是否ok
参考
5安装docker
docker官方文档上安装步骤写的很清楚,复制粘贴命令就行
// 卸载 预防有残留
# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
....
// 这几个是依赖
# yum install -y yum-utils \
> device-mapper-persistent-data \
> lvm2
已加载插件:fastestmirror, langpacks
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* remi-safe: mirrors.mediatemple.net
软件包 yum-utils-1.1.31-52.el7.noarch 已安装并且是最新版本
软件包 device-mapper-persistent-data-0.8.5-1.el7.x86_64 已安装并且是最新版本
软件包 7:lvm2-2.02.185-2.el7_7.2.x86_64 已安装并且是最新版本
无须任何处理
// 设置docker源
# yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
...
// 安装docker ce
# yum install docker-ce docker-ce-cli containerd.io
....
========================================================================================================
Package 架构 版本 源 大小
========================================================================================================
正在安装:
containerd.io x86_64 1.2.10-3.2.el7 docker-ce-stable 23 M
docker-ce x86_64 3:19.03.6-3.el7 docker-ce-stable 24 M
docker-ce-cli x86_64 1:19.03.6-3.el7 docker-ce-stable 40 M
为依赖而安装:
container-selinux noarch 2:2.107-3.el7 extras 39 k
事务概要
========================================================================================================
安装 3 软件包 (+1 依赖软件包)
总下载量:87 M
安装大小:363 M
....
已安装:
containerd.io.x86_64 0:1.2.10-3.2.el7 docker-ce.x86_64 3:19.03.6-3.el7
docker-ce-cli.x86_64 1:19.03.6-3.el7
作为依赖被安装:
container-selinux.noarch 2:2.107-3.el7
完毕!
//启动
# systemctl start docker
# docker -v
Docker version 19.03.6, build 369ce74a3c
要好一会儿,装好后顺便装下docker-compose,也有非常清楚的安装文档,无脑粘贴命令就行
// 就是一个可执行文件 然后放在/usr/local/bin就能全局可用了
# curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
// 如果太慢 试试 curl -L "https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
// 添加执行权限
# chmod +x /usr/local/bin/docker-compose
# docker-compose --version
docker-compose version 1.25.4, build 8d51620a
6安装其他常用软件
6.1git
# yum install git
....
======================================================================================================
Package 架构 版本 源 大小
======================================================================================================
正在安装:
git x86_64 1.8.3.1-21.el7_7 updates 4.4 M
为依赖而安装:
perl-Error noarch 1:0.17020-2.el7 base 32 k
perl-Git noarch 1.8.3.1-21.el7_7 updates 55 k
perl-TermReadKey x86_64 2.30-20.el7 base 31 k
事务概要
======================================================================================================
安装 1 软件包 (+3 依赖软件包)
总下载量:4.5 M
安装大小:22 M
Is this ok [y/d/N]: y
....
已安装:
git.x86_64 0:1.8.3.1-21.el7_7
作为依赖被安装:
perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-21.el7_7
perl-TermReadKey.x86_64 0:2.30-20.el7
完毕!
# git --version
git version 1.8.3.1
// 顺手配置下
# git config --global user.name "dragonfly429"
# git config --global user.email "[email protected]"
# git config --list
user.name=dragonfly429
[email protected]
// 做事做到位,顺手吧sshkey生成并添加到git,拉一个项目测试
ssh-keygen -t rsa -C "[email protected]"
6.2 composer
也有安装文档
// 因为我安装的php73 所以弄一个软连接 不然一会儿报错
# whereis php73
php73: /usr/bin/php73
# ln -s /usr/bin/php73 /usr/local/bin/php
# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/local/bin/composer
# composer -v
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.9.3 2020-02-04 12:58:49
6.3 nodejs
// 下载最新可执行文件
# wget http://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.gz
// 解压
# tar -zxvf node-v12.16.1-linux-x64.tar.gz
# mv node-v12.16.1-linux-x64 /usr/local/lib64/node-v12.16.1-linux-x64
# vim /etc/profile
// 在最下面添加
NODEJS_HOME=/usr/local/lib64/node-v12.16.1-linux-x64
export PATH=$NODEJS_HOME/bin:$PATH
// 刷新
# source /etc/profile
# node -v
v12.16.1
// 更新设置淘宝源
# npm config set registry=https://registry.npm.taobao.org
# npm install -g cnpm --registry=https://registry.npm.taobao.org
/usr/local/lib64/node-v12.16.1-linux-x64/bin/cnpm -> /usr/local/lib64/node-v12.16.1-linux-x64/lib/node_modules/cnpm/bin/cnpm
+ [email protected]
added 685 packages from 944 contributors in 17.666s
# cnpm -v
[email protected] (/usr/local/lib64/node-v12.16.1-linux-x64/lib/node_modules/cnpm/lib/parse_argv.js)
[email protected] (/usr/local/lib64/node-v12.16.1-linux-x64/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
[email protected] (/usr/local/lib64/node-v12.16.1-linux-x64/bin/node)
[email protected] (/usr/local/lib64/node-v12.16.1-linux-x64/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/usr/local/lib64/node-v12.16.1-linux-x64
linux x64 3.10.0-693.el7.x86_64
registry=https://r.npm.taobao.org