centos7.6编译安装mysql5.7.28+nginx1.16.1+php7.3.10,和之前的教程大体一样,只是有一些微改变,编译安装顺序最好按此文的顺序mysql->nginx->php这样
可以看看我之前centos6编译的教程,https://sulao.cn/post/111.html
下面我们来看看centos7上编译的过程
首先关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
关闭防火墙并停用开机启动
systemctl stop firewalld.service systemctl disable firewalld.service
更换阿里云yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
更新yum缓存
yum makecache
安装依赖包
yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel libjpeg-devel libpng-devel zlib-devel libXpm* freetype php-common ncurses* libtool* libxml2 libxml2-devel patch freetype-devel cmake pcre
安装mysql5.7
groupadd mysql #添加mysql组 useradd -g mysql mysql -s /sbin/nologin #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统 mkdir -p /data/mysql #创建MySQL数据库存放目录 chown -R mysql:mysql /data/mysql #设置MySQL数据库目录权限 mkdir -p /usr/local/mysql #创建MySQL安装目录 cd /usr/local/src tar zxvf mysql-5.7.28.tar.gz #解压 cd mysql-mysql-5.7.28 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_BOOST=boost #配置 make #编译 make install #安装
添加my.cnf配置文件,如果/etc下没有就新增,有就清空内容添加以下内容
#vi /etc/my.cnf [client] port = 3306 socket = /data/mysql/mysql.sock default-character-set = utf8mb4 [mysql] prompt="MySQL [\d]> " no-auto-rehash [mysqld] port = 3306 socket = /data/mysql/mysql.sock basedir = /usr/local/mysql datadir = /data/mysql pid-file = /data/mysql/mysql.pid user = mysql bind-address = 0.0.0.0 server-id = 1 init-connect = 'SET NAMES utf8mb4' character-set-server = utf8mb4 skip-name-resolve #skip-networking back_log = 300 max_connections = 1000 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 128 max_allowed_packet = 500M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 16M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 4M thread_cache_size = 8 query_cache_type = 1 query_cache_size = 8M query_cache_limit = 2M ft_min_word_len = 4 log_bin = mysql-bin binlog_format = mixed expire_logs_days = 7 log_error = /data/mysql/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/mysql-slow.log performance_schema = 0 #lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [mysqldump] quick max_allowed_packet = 500M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M
:wq! #保存退出
初始化mysql5.7数据库的方式跟mysql5.6和5.5不一样了,这里要注意
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql cp ./support-files/mysql.server /usr/local/mysql/bin/mysql.server #把Mysql启停脚本放置到bin目录下,方便后续编写系统服务 #vi /usr/local/mysql/bin/mysql.server #编辑 basedir = /usr/local/mysql #MySQL程序安装路径 datadir = /data/mysql #MySQl数据库存放目录
:wq! 保存退出
chmod +x /usr/local/mysql/bin/mysql.server
mysql开机启动配置
#vi /usr/lib/systemd/system/mysqld.service [Unit] Description=mysql project After=mysqld.service [Service] Type=forking User=mysql Group=mysql PIDFile=/data/mysql/mysql.pid ExecStart=/usr/local/mysql/bin/mysql.server start ExecReload=/usr/local/mysql/bin/mysql.server restart ExecStop=/usr/local/mysql/bin/mysql.server stop PrivateTmp=true [Install] WantedBy=multi-user.target
给启动服务脚本754权限
chmod 754 /usr/lib/systemd/system/mysqld.service # systemctl start mysqld.service #启动mysql #如果启动报错重新加载下daemon systemctl daemon-reload systemctl enable mysqld.service #添加到开机启动
把mysql服务加入系统环境变量:在最后添加下面这一行
#vi /etc/profile export PATH=$PATH:/usr/local/mysql/bin
:wq! #保存退出
使其生效
source /etc/profile
修改mysql密码,默认密码为空
mysql -u root -p #直接回车登陆 SET PASSWORD=PASSWORD("admin")
nginx安装和之前一样,主要也是开机启动服务需要自己编写
groupadd www #添加www组 useradd -g www www -s /sbin/nologin #创建nginx运行账户www并加入到www组,不允许www用户直接登录系统 tar -zxvf nginx-1.16.1.tar.gz cd nginx-1.16.1 ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_realip_module --with-pcre make #编译 make install #安装
nginx开机启动
#vi /usr/lib/systemd/system/nginxd.service [Unit] Description=nginx project After=nginxd.service [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
给开机服务脚本754权限
chmod 754 /usr/lib/systemd/system/nginxd.service systemctl start nginxd.service #如果启动报错重新加载下daemon systemctl daemon-reload systemctl enable nginxd.service
安装libmcrypt
cd /usr/local/src tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make make install
编译安装php7.3的时候会报错,我踩过坑了
configure: error: Please reinstall the libzip distribution
需要安装高版本的lizip,如果安装1.5的版本会提示cmake版本低,我这里方便还是使用的1.2.0的版本
yum remove libzip wget https://libzip.org/download/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install
再次编译php7.3依然报错
/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
尝试手工复制一个过去
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
再次编译php7.3
mkdir -p /usr/local/php7 ln -s /usr/lib64/liblber* /usr/lib/ #ldap模块需要的库 tar -zxvf php-7.3.10.tar.gz cd php-7.3.10 ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --enable-mysqlnd --with-gd --with-iconv --with-ldap=shared --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-png-dir --enable-opcache make #编译 make install #安装
如果内存小于1G会报错:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
在./configure添加:--disable-fileinfo 即可
cp php.ini-production /usr/local/php7/etc/php.ini #复制php配置文件到安装目录 rm -rf /etc/php.ini #删除系统自带配置文件 ln -s /usr/local/php7/etc/php.ini /etc/php.ini #添加软链接 cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件 cd /usr/local/php7/etc/php-fpm.d/ cp www.conf.default www.conf vi www.conf user = www #设置php-fpm运行账号为www group = www #设置php-fpm运行组为www wq! #保存退出 vi /usr/local/php7/etc/php-fpm.conf #编辑 pid = run/php-fpm.pid #取消前面的分号 wq! #保存退出 cp /usr/local/src/php-7.3.10/sapi/fpm/init.d.php-fpm /usr/local/php7/bin/php-fpm #编写php开机启动需要的文件 chmod +x /usr/local/php7/bin/php-fpm #添加执行权限
php开机启动配置
#vi /usr/lib/systemd/system/phpd.service [Unit] Description=php project After=phpd.service [Service] Type=forking PIDFile=/usr/local/php7/var/run/php-fpm.pid ExecStart=/usr/local/php7/bin/php-fpm start ExecReload=/usr/local/php7/bin/php-fpm restart ExecStop=/usr/local/php7/bin/php-fpm stop PrivateTmp=true [Install] WantedBy=multi-user.target
给开机启动服务脚本添加754权限
chmod 754 /usr/lib/systemd/system/phpd.service systemctl start phpd.service #如果启动报错重新加载下daemon systemctl daemon-reload systemctl enable phpd.service
我们也把php执行文件加到环境变量吧
vi /etc/profile export PATH=$PATH:/usr/local/php7/bin
:wq! #保存退出
使环境变量生效
source /etc/profile
这样所有需要的软件都已经编译完,我们可以重新启动下服务器看看nginx,php,mysql服务是不是自动启动,他们分别对应的监听端口是
php -> 9000 mysql -> 3306 nginx -> 80
我要评论