centos7 安装 nginx 1.20 php 8.0 mysql 8.0 redis 5.0 脚本

代码内容:

centos7 安装 nginx  php mysql redis
nginx 1.20
php 8.0 
mysql 8.0
redis 5.0
安装到指定目录/usr/local/下,修改成指定用户www

软件下载链接
mysql 8.0.26 glibc2
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

nginx 1.20
http://nginx.org/download/nginx-1.20.1.tar.gz

redis 5.0.5
http://download.redis.io/releases/redis-5.0.5.tar.gz

php 8.0.11
https://www.php.net/distributions/php-8.0.11.tar.gz

===========分割线======
1、安装redis
yum install gcc -y
cd /app/software/
tar -zxvf redis-5.0.5.tar.gz
cd redis-5.0.5/
make
make install PREFIX=/usr/local/redis
setsid /usr/local/redis/bin/redis-server  redis.conf &

echo 'export PATH=$PATH:/usr/local/redis/bin/' >> /etc/profile
source /etc/profile
cp /app/software/redis-5.0.5/redis.conf /usr/local/redis/bin/redis.conf

cat>/etc/systemd/system/redis.service<<EOF
[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

#注意要将 redis.conf 里面的改成  daemonize yes ,否则会一直卡住
systemctl daemon-reload
systemctl stop redis.service
systemctl start redis.service
systemctl enable redis.service






参考:https://www.cnblogs.com/heqiuyong/p/10463334.html
#未做:加入systemd,开机自启



2、安装nginx
yum -y install gc gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum -y install libxslt-devel GeoIP-devel perl-ExtUtils-Embed

useradd -r -s /sbin/nologin www
cd /app/software/
tar -zxf nginx-1.20.1.tar.gz
cd nginx-1.20.1/

./configure --prefix=/usr/local/nginx --user=www --group=www \
--with-file-aio --with-http_auth_request_module --with-http_ssl_module \
--with-http_v2_module --with-http_realip_module --with-http_addition_module \
--with-http_xslt_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module \
--with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module \
--with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module \
--with-http_degradation_module --with-http_slice_module --with-http_stub_status_module \
--with-http_perl_module=dynamic --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module

make && make install
/usr/local/nginx/sbin/nginx
echo 'export PATH=$PATH:/usr/local/nginx/sbin/' >> /etc/profile
source /etc/profile

cat>/usr/lib/systemd/system/nginx.service<<EOF
[Unit]
Description=Nginx Web Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF



参考:https://www.zsythink.net/archives/3091
#未做:#nginx.conf配置与php-fpm




3、安装mysql
#systemctl stop mariadb.service
#yum remove mariadb -y
#yum remove mariadb-libs -y
yum -y install libaio
cd /app/software/
tar -vxJf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql
useradd -r -s /sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql

echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
mkdir /usr/local/mysql/{log,data}



/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
#chkconfig --list mysqld
service mysqld start

#edit my.cnf
cat>/etc/my.cnf<<EOF
[mysql]
 
#mysql客户端默认字符集
default-character-set=utf8
 
[mysqld]
 
#设置3306端口
port = 3306
socket=/var/lib/mysql/mysql.sock
 
#设置mysql的安装目录 
basedir=/usr/local/mysql
 
#设置mysql数据库的数据的存放目录 
datadir=/usr/local/mysql/data

 
#允许最大连接数 
max_connections=200
 
#最大等待时间
wait_timeout=3153600
 
#服务端使用的字符集
character-set-server=utf8
 
#创建新表时将使用的默认存储引擎 
default-storage-engine = InnoDB
 
#日志
log-error=/usr/local/mysql/log/error.log

 
#允许做大数据包
max_allowed_packet=16M
EOF

cat > /usr/lib/systemd/system/mysqld.service << EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF


参考:https://blog.csdn.net/qq_29077619/article/details/89415446


4、安装php
yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
yum -y install libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel sqlite-devel oniguruma-devel

cd /app/software
tar -zxf php-8.0.11.tar.gz
cd php-8.0.11/
./configure \
--prefix=/usr/local/php8 --exec-prefix=/usr/local/php8 --bindir=/usr/local/php8/bin --sbindir=/usr/local/php8/sbin \
--includedir=/usr/local/php8/include --libdir=/usr/local/php8/lib/php --mandir=/usr/local/php8/php/man \
--with-config-file-path=/usr/local/php8/etc \
--with-mysql-sock=/dev/shm/mysql.sock --with-mysqli=shared,mysqlnd --with-mhash \
--with-openssl=/usr/local/openssl --with-curl=/usr/local/curl \
--with-pdo-mysql=shared,mysqlnd --with-iconv --with-zlib \
--enable-inline-optimization \
--disable-debug --disable-rpath --enable-shared \
--enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp \
--enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session \
--enable-opcache --enable-fpm --without-gdbm --disable-fileinfo --with-fpm-user=www --with-fpm-group=www
make && make install

cp php.ini-development /usr/local/php8/etc/php.ini
cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf

cp /app/software/php-8.0.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp /app/software/php-8.0.11/sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service
service php-fpm start

echo 'export PATH=$PATH:/usr/local/php8/bin/' >> /etc/profile
source /etc/profile

其他,报错排查过程

最初参考文章https://blog.csdn.net/qq_29077619/article/details/89415446 来部署的,但是mysql启动报错。
在这里插入图片描述
在这里插入图片描述
有带哥指出,这是初始化没成功。理论上来说执行mysqld --initialize 会出现一些信息,包括最后面有个随机密码。
最终处理方法,将 /etc/my.cnf移走,进行mysqld --initialize 初始化。
猜想:可能是那篇文章的my.cnf有误。再者就是执行mysqld --initialize的顺序。 可以先mysqld --initialize ,之后再对my.cnf做操作。
mysql起不来基本上两个问题,my.cnf没写好,service文件没写好。
(最初的时候这台机器有个mariadb 5.5)

参考
https://blog.csdn.net/Nightwish5/article/details/110872876
https://blog.csdn.net/tcliuwenwen/article/details/108654877 《CentOS 7二进制安装MySQL 8.0脚本》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值