- yum安装基础包
- yum -y install vim gcc gcc-c++ bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl openssl-devel libxml2-devel libcurl-devel bzip2 bzip2-devel readline-devel libedit-devel sqlite-devel libpng-devel libjpeg-devel freetype freetype-devel cyrus-sasl-md5 iptables-services git glibc-headers build-essentia autoconf
- 防火墙问题
- getenforce 查看SELinux的当前状态
setenforce 0 临时关闭SELinux
vim /etc/selinux/config SELINUX=enforcing 改成 SELINUX=disabled 重启服务器生效 - centos默认使用firewalld所以要先关闭
systemctl stop firewalld 停止
systemctl mask firewalld 禁用
systemctl disable firewalld 禁止开机启动 - iptables相关(云服务器要先设置好安全组)
iptables -L -n 查看防火墙规则
service iptables status 或者 systemctl start iptables 查看防火墙状态
service iptables start 或者 systemctl start iptables 开启
services iptables stop 或者 /etc/init.d/iptables stop 或者 systemctl stop iptables 关闭防火墙
systemctl restart iptables 重启
systemctl reload iptables 重载
systemctl enable iptables 设置开机启动 - 配置端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT 向规则链中添加80端口
iptables -D INPUT -p tcp --dport 80 -j ACCEPT 向规则链中删除80端口
service iptables save 保存上面的端口修改到规则链
service iptables restart 生效
或者vim /etc/sysconfig/iptables打开规则链直接写入-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT - 可能报错
Job for iptables.service failed because the control process exited with error code. See "systemctl status iptables.service" and "journalctl -xe" for details.
添加433端口:
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
service iptables save
systemctl restart iptables.service
- getenforce 查看SELinux的当前状态
- 安装软件
本文所有源码包都下载到/usr/local/src/文件下了,也统一使用tar -zxvf解压在该文件夹下
例:
cd /usr/local/src 进入目录
ls 查看文件,返回nginx-1.17.0.tar.gz
tar -zxvf nginx-1.17.0.tar.gz 解压
ls 查看,返回nginx-1.17.0.tar.gz,nginx-1.17.0
cd nginx-1.17.0 进入文件
软件都安装在/usr/local/下,nginx就在/usrlocal/nginx里,安装目录名一般不加版本号
- nginx
- cd nginx-1.17.0
- ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=root --group=root --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
- make && make install
- vim /usr/local/nginx/conf/nginx.conf
去掉一下#号
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
location / {
root html;
index index.php index.html index.htm;
}
顺便配好php的项目位置
location ~ \.php$ {
root /home/www/; #php项目都放这里
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
项目重定向问题
例www.test.com/about/index.php $uri=/about
location / {
# 重新向所有非真实存在的请求到index.php
try_files $uri $uri/ /$uri/index.php$args; 配多个项目
#try_files $uri $uri/ /index.php$args; 配单个项目
} - 设置nginx
cd /usr/local/nginx/sbin
./nginx 开启nginx
./nginx -s reload 重新载入配置文件
./nginx -s reopen 重启
./nginx -s stop 关闭
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -t 查看配置是否正确
netstat -apn|grep 80 查看80端口进程
netstat -ntpl 查看端口
netstat -lntup 查看所有tcp端口监听
ps aux|grep nginx
ps -A 查看所有进程
ps -ef|grep nginx 列出进程列表
kill -9 10790 //进程号(杀死占用80端口的进程)
设置开机启动
vim /etc/rc.local
加一行 /usr/local/nginx/sbin/nginx
//加一行 /usr/local/sbin/php-fpm
chmod 755 /etc/rc.local
- cmake(安装cmake.x.x用来编译mysql8.x.x)
- cd cmake-3.15.0-rc1
- ./configure --prefix=/usr/local/cmake
- gmake && make install
- 加环境变量
vim /etc/profile 修改用户环境变量
export PATH=$PATH:/usr/local/cmake/bin $PATH是原有变量,新的加在后面就行
source /etc/profile 执行后生效
或者
vim /etc/environment 修改系统环境变量
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/cmake/bin"
重启系统生效(cmake加在后面即可)
- gcc最高版本(yum安装的版本太低编译不了mysql8.x.x)(gcc要编译很久,大概1~2小时吧,出去放松一下吧)
- http://ftp.gnu.org/gnu/gcc/gcc-9.1.0/ 首先下载高版本的gcc源码包
- cd gcc-9.1.0
- ./contrib/download_prerequisites 安装四个必要文件(我这里没成功,去步骤4手动下载安装了)
要是成功了就cd gcc-9.1.0
mkdir build
cd build
../configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++
make && make install - ftp://gcc.gnu.org/pub/gcc/infrastructure/ 手动下载安装四个必要文件
gmp-6.1.0.tar.bz2
mpfr-3.1.4.tar.bz2
mpc-1.0.3.tar.gz
isl-0.18.tar.bz2 (没用到呢) - 进行安装(按顺序)
tar -jxvf gmp-6.1.0.tar.bz2
./configure --prefix=/usr/local/gmp
make && make install
tar -jxvf mpfr-3.1.4.tar.bz2
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make && make install
tar -zxvf mpc-1.0.3.tar.gz
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr
make && make install
tar -zxvf gcc-9.1.0.tar.gz
./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc
make && make install - 配置环境变量
which gcc 或者 gcc -v 查看gcc位置和版本,如果不是最新版就设置环境变量顺序
vim /etc/environment 修改环境变量
把/usr/local/gcc/bin加在/usr/bin前面
重启系统生效
或者
vim /etc/profile
export PATH=/usr/local/gcc/bin:$PATH
source /etc/profile
which gcc 查看结果
- mysql(坑最多,编译时间也很长,大概4~5小时吧可能)
- cd mysql-8.0.16
- mkdir build
- cd build 需要在这里进行编译安装操作
- cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=system \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DCOMPILATION_COMMENT="zsd edition" \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/src/mysql \
-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock \
-DSYSCONFDIR=/data/mysqldata/3306 - cmake会报错WARNING "Could not find devtoolset gcc" GCC 5.3 or newer is required (-dumpversion says 4.8.5)
他是默认使用devtoolset工具来管理gcc版本的,我们是自己安装的新版本,所以要改源码包里的CMakeLists.txt文件,全文搜索devtoolset,把他默认的PATHS "/opt/rh/devtoolset-8/root/usr/bin")改成PATHS "/usr/local/gcc/bin")也就是我们新安装的gcc路径,然后
cd build
rm -rf CMakeCache.txt
重新cmake编译应该就没其他错误了 - cd build
- make && make install 会很久,会有很多错
- 可能报错
1.
/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ../runtime_output_directory/uca9dump)
gcc使用最新版本后,动态库没有跟着更新导致
#strings /usr/lib64/libstdc++.so.6 | grep CXXABI 查看动态库会发现没有CXXABI_1.3.9
#ls -l /usr/lib64/libstdc++.so.6 发现是个软连接
#find / -name "libstdc++.so.*" 查找动态库
#cp /usr/local/src/gcc-9.1.0/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.26 /usr/lib64/
#cd /usr/lib64
#rm -rf libstdc++.so.6
#ln -s libstdc++.so.6.0.26 libstdc++.so.6 设置软连接
#strings /usr/lib64/libstdc++.so.6 | grep 'CXXABI' 搞定
2.
error: ‘SYS_gettid’ was not declared in this scope
找到报错给出的文件,修改报错行
setpriority(PRIO_PROCESS, (pid_t)syscall(SYS_gettid), -20);
改成
setpriority(PRIO_PROCESS, (pid_t)getgid(), -20);
3.
error: ‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_lint’?
因为编译版本问题,会有新旧函数名等问题,他会帮忙纠错的,按照他说的改就行,最好是把你要改的文件备份,防止改坏了
4.
g++g++: fatal error: Killed signal terminated program cc1plus 内存不够了 free -h 看内存
dd if=/dev/zero of=/swapfile bs=8M count=512 count的大小就是增加的swap空间的大小,64M是块大小,所以空间大小是bs*count=1024MB
mkswap /swapfile 把刚才空间格式化成swap格式
swapon /swapfile 使用刚才创建的swap空间
使用后记得删除
swapoff /swapfile 关闭交换分区
rm /swapfile 删除交换分区 - 安装完毕
groupadd mysql 创建mysql用户组
useradd -g mysql mysql 创建mysql用户
mkdir /usr/local/mysql/data/mysql 创建数据文件
chown -R mysql:mysql /usr/local/mysql/ 给权限
chmod -R 755 /usr/local/mysql/ - vim /etc/profile 环境变量
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile - 设置mysqld文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
vim /etc/init.d/mysqld
basedir=/usr/local/mysql MySQL安装目录
datadir= /usr/local/mysql/data/mysql 数据存放目录
mysqld_pid_file_path=/usr/local/mysql/data/mysql/snow.pid pid文件位置(hostname.pid根据自己的来设置) - 设置my.cnf文件
vim /etc/my.cnf[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql/
socket=/usr/local/mysql/data/mysqldata/3306/mysql.sock
user = mysql
tmpdir = /tmp
character-set-server=utf8mb4
mysqlx_port = 33060
user = mysql
socket = /usr/local/mysql/data/mysqldata/3306/mysql.sock
mysqlx_socket=/usr/local/mysql/data/mysqldata/3306/mysqlx.sock#skip-grant-tables 忘记密码时候打开注释,重启mysql服务生效
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql/snow.pid
mysqlx_socket=/app/mysql/mysqldata/3306/mysqlx.sock[client]
port = 3306
socket = /usr/local/mysql/data/mysqldata/3306/mysql.sock -
mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/mysql --user=mysql --pid-file=/usr/local/mysql/data/mysql/snow.pid 初始化数据库,会返回一个密码(h#*VbYmkK9=v),要自己记下来 - 开启mysql服务
service mysqld start 或 safe_mysqld --user=mysql & 或 /etc/init.d/mysqld start 开启
service mysqld stop 或 /etc/init.d/mysqld stop 或 mysqladmin shutdown 停止
service mysqld restart 或 /etc/init.d/mysqld restart 重启 - 可能的报错
1.
/etc/init.d/mysqld: line 246: @HOSTNAME@: command not found
把@HOSTNAME@ 改成 hostname
2.
log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
没有文件就手动帮创建(只能百度到这种方法感觉好蠢!) // 提前给/var/log文件读写权限应该就可以
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
3.
mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
mkdir /var/lib/mysql
4.
The server quit without updating PID file 这是一个常见问题,可能的原因大概率是路径和权限,剩下的自己百度把
vim /etc/init.d/mysqld
basedir=/usr/local/mysql MySQL安装目录
datadir= /usr/local/mysql/data/mysql 数据存放目录
mysqld_pid_file_path=/usr/local/mysql/data/mysql/snow.pid pid文件位置
5.
mysqld_safe Directory '/data/mysqldata/3306' for UNIX socket file don't exists.
mkdir -p /usr/local/mysql/data/mysqldata/3306
- 修改mysql密码
MySQL> ALTER USER "root"@"localhost" IDENTIFIED BY "123456";
忘记密码就把my.cnf文件的注释打开,就可以不用密码登录 - 连接navicat
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '';
mysql>FLUSH PRIVILEGES;
- libzip
- wget https://libzip.org/download/libzip-1.5.0.tar.gz
tar -zxvf libzip-1.5.0.tar.gz
cd libzip-1.5.0
mkdir build
cd build
cmake ..
make && make install
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf 添加搜索路径到配置文件
ldconfig -v 更新配置
- wget https://libzip.org/download/libzip-1.5.0.tar.gz
- php
- ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl
- make && make install
- 配置
cp php.ini-production /usr/local/php/php.ini
vim /usr/local/php/php.ini
display_errors = On 错误信息打印在页面上
cp ./sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
去掉 pid = run/php-fpm.pid 前面的分号
find / -name php-fpm.d
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
(vim www.conf)
vim /etc/profile.d/php.sh
export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/
source /etc/profile.d/php.sh
service php-fpm start
vim /etc/init.d/php-fpm
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
/etc/init.d/php-fpm start php-fpm启动命令
/etc/init.d/php-fpm stop php-fpm停止命令
/etc/init.d/php-fpm restart php-fpm重启命令
ps -ef | grep php 或者 ps -A | grep -i php 查看是否已经成功启动PHP
chmod +x /etc/init.d/php-fpm 修改系统配置目录下的 php-fpm 文件可执行权限
chkconfig --add php-fpm 将系统配置目录下的 `php-fpm` 添加到 `系统服务`
chkconfig php-fpm on 设置 `php-fpm` `系统服务` 为开机启动
搭建lnmp--201906
最新推荐文章于 2022-08-18 15:42:39 发布