树莓派raspberry 安装CentOS+PHP+MariaDB+Redis+Memecache

前言

入手了一个树莓派,想做个自动喂鱼器。但是看了GPIO后,感觉没啥难度,就是放弃了。
然后顺便想自己搭个产品运行环境算了,以前用Vagrant 在本机太吃性能了。

本文应该是国内最全文档,不接受反驳。

设备

RaspBerry Pi 3B+

安装 CentOS

下载CentOS Armhfp 镜像

镜像列表
http://isoredirect.centos.org/altarch/7/isos/armhfp/

wget https://mirror.xtom.com.hk/centos-altarch/7.6.1810/isos/armhfp/CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-1810-sda.raw.xz

重要: Armhfp 是32位的,所以有些64位特性会有细节差别,比如bigint

安装镜像

下面只列出在MacOS下的方法
其他操作系统可以参考Ubuntu 镜像的安装方法
https://www.ubuntu.com/download/iot/installation-media

  1. 列出设备
$diskutil list

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         121.1 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +121.1 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            74.0 GB    disk1s1
   2:                APFS Volume Preboot                 45.0 MB    disk1s2
   3:                APFS Volume Recovery                517.0 MB   disk1s3
   4:                APFS Volume VM                      3.2 GB     disk1s4
 /dev/disk2
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:     FDisk_partition_scheme                        *7.9 GB     disk3
1:                 DOS_FAT_32 NO NAME                 7.9 GB     disk3s1
  1. 找到插入的SD卡 /dev/disk2 (因人而异),然后卸载设备
$diskutil unmountDisk  /dev/disk2
  1. 将镜像拷贝到SD卡里,注意需要 sudo 权限,xz 命令需要单独安装( $brew install dx )
$sudo sh -c 'xzcat ~/Downloads/CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-1810-sda.raw.xz | sudo dd of=/dev/disk2 bs=32m'

  1. 一直等到出现
3719+1 records in
3719+1 records out
3899999744 bytes transferred in 642.512167 secs (6069924 bytes/sec)

这样的提示出现,具体数据可能不一样。

  1. 然后将CeotOS SD卡插入树莓派,插入键盘、显示器,启动树莓派。
    登录名:root
    登录密码:centos

扩展磁盘空间

如果不扩展,默认的使用容量很小,大概只有几百兆
参考:https://blog.csdn.net/qq_36731677/article/details/78764941

使用fdisk命令格式化剩余磁盘。

fdisk /dev/mmcblk0
1. 输入 d , 删除分期,使用默认的第三分区即可
2. 输入 n,添加分区,使用默认 第三 primary主分区即可
3.  输入 w,写入修改。如果推出不写入,则修改无效

reboot 重启系统后,执行

resize2fs /dev/mmcblk0p3

重置磁盘空间后,执行 df -h 查看空间大小即可

连接Wifi

使用CentOS自带的图形管理软件

 nmtui

选择 Activate a connection (第二个)

然后进入二级页面后,选择要连接的wifi、输入密码,退出即可。

关闭防火墙

systemctl stop firewalld.service

Yum命令修复

如果直接使用Yum命令,是不能用的,会提示缺少armhfp 。因为epel里的源没有arm源。解决方案就是删除epel,或者修改epel文件。

如果要换国内源,参考 https://blog.csdn.net/lhj_168/article/details/85805799

  1. 将epel源修改为armhfp支持
cat > /etc/yum.repos.d/epel.repo << EOF
[epel]
name=Epel rebuild for armhfp
baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/
enabled=1
gpgcheck=0
EOF
  1. 同时加入php7.2源
cat > /etc/yum.repos.d/php72-testing.repo << EOF
[php72-testing]
name=Remi php72 rebuild for armhfp
baseurl=https://armv7.dev.centos.org/repodir/community-php72-testing/
enabled=1
gpgcheck=0
EOF
  1. 清除yum缓存 重要,不执行的话,yum修改不生效
yum clean up
yum makecache

节后阅读: 此阶段参考:https://seven.centos.org/2018/01/php-7-2-for-centos-7-armhfp/

安装一些常用的命令

  1. 自由发挥
yum install wget git vim  -y

  1. 安装一些前置依赖
yum install libevent-devel openssl openssl-devel telnet gcc+ gcc-c++  cmake ncurses-devel libaio -y

  1. 安装php
yum install  php-devel php-mysql php-pecl-redis php-fpm php-opcache php-bcmath php-pecl-memcached

  1. 查看php
$php -v

PHP 7.2.16 (cli) (built: Mar 20 2019 00:26:28) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.16, Copyright (c) 1999-2018, by Zend Technologies
  1. 运行PHP
sudo mkdir -p /run/php-fpm
sudo php-fpm
  1. 修改一些小配置
php.ini 里的 timezone 默认改为 PRC

php-fpm.d/www.conf 里面的user和group改为运行时用户

安装 Nginx

  1. 下载 nginx
$wget http://nginx.org/download/nginx-1.12.2.tar.gz
$tar -zxf nginx-1.12.2.tar.gz
$cd nginx-1.12.2

  1. 编译
    下面的{path}为nginx放置的目录
$./configure   --prefix={path}/nginx   --pid-path={path}/nginx/nginx.pid    --lock-path={path}/nginx/nginx.lock   --user=work   --group=work   --with-http_ssl_module   --with-http_flv_module   --with-http_stub_status_module   --with-http_gzip_static_module   --with-pcre

$make && make install
  1. 测试
 ./sbin/nginx  -t

如果出现

nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
nginx: configuration file /home/work/nginx/conf/nginx.conf test failed

nginx.conf的http里面加入 server_names_hash_bucket_size 512;即可

  1. 启动
sudo ./sbin/nginx

安装 Redis

  1. 下载 Redis 稳定版(截至发稿前 5.0)
wget http://download.redis.io/releases/redis-stable.tar.gz
tar -zxf redis-stable.tar.gz
cd redis-stable
make
mkdir logs

#编译后redis不需要install
cd ..
mv redis-stable redis

  1. 配置到个人小癖好 redis.conf

配置对应的log和 bind ip

daemonize yes
pidfile {path}/redis/redis_6379.pid
logfile " {path}/redis/logs/redis.log"
bind xxx.xxx.xxx

#后台运行
daemonize yes
# 如果Log配置了目录,要创建一下
mkdir logs

启动

./src/redis-server redis.conf

安装 MariaDB (MySQL)

  1. 安装
sudo yum install mariadb-server
  1. 启动
#启动
systemctl start mariadb.service

#简单快速配置
mysql_secure_installation

#登录
mysql -u root -p

#设置root 可以从任何地方登录
use mysql;
update user set host = '%' where user = 'root' and host='localhost';
flush privileges;

安装 Memcache

  1. 下载编译
wget http://memcached.org/files/memcached-1.5.7.tar.gz
tar zxf memcached-1.5.7.tar.gz
cd memcached-1.5.7
./configure --prefix={path}/memcached
 make && make install
  1. 启动

./bin/memcached &

Last. Enjoy yourself. 树莓派。。。真的没什么用啊

参考

https://www.ubuntu.com/download/iot/installation-media
https://blog.csdn.net/qq_36731677/article/details/78764941
https://seven.centos.org/2018/01/php-7-2-for-centos-7-armhfp/
https://blog.csdn.net/lhj_168/article/details/85805799

发布了128 篇原创文章 · 获赞 108 · 访问量 172万+

猜你喜欢

转载自blog.csdn.net/EI__Nino/article/details/88869902