2019-08-10

搭建 teamtalk 服务器

(一)配置lnmp环境
环境:硬件:Mac 电脑 系统:虚拟机安装的Linux系统: CentOS-7
资源: 虚拟机 VirtualBox VBoxGuestAdditions_5.1.12.iso CentOS-7-x86_64-DVD-1810.iso

centos 7 我这里选的是最小安装 需要设置网卡参数

设置固定IP

vi  /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE="Ethernet"

BOOTPROTO="static"

NETMASK=255.255.255.0

IPADDR=192.168.2.158

GATEWAY=0.0.0.0

DNS1=8.8.8.8

DNS2=8.8.4.4

PROXY_METHOD="none"

BROWSER_ONLY="no"

DEFROUTE="yes"

IPV4_FAILURE_FATAL="no"

IPV6INIT="yes"

IPV6_AUTOCONF="yes"

IPV6_DEFROUTE="yes"

IPV6_FAILURE_FATAL="no"

IPV6_ADDR_GEN_MODE="stable-privacy"

NAME="enp0s3"

UUID="5ca4556a-cf27-4010-aa4d-330f1fb4d588"

DEVICE="enp0s3"

ONBOOT="yes"

配置2

TYPE="Ethernet"
BOOTPROTO="static"
PEERDNS=yes
PEEROUTES=yes
DEFROUTE="yes"
BROWSER_ONLY="no"
PROXY_METHOD="none"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_PEERDNS=yes
PV6_PEEROUTES=yes
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="enp0s3"
UUID="5ca4556a-cf27-4010-aa4d-330f1fb4d588"
DEVICE="enp0s3"
ONBOOT="yes"
NETMASK=255.255.255.0
IPADDR=192.168.1.128
GATEWAY=192.168.1.1
BROADCAST=192.168.1.255

推荐dns配置
推荐DNS
Google Public DNS: 8.8.8.8; 8.8.4.4.
Norton DNS: 198.153.192.1; 198.153.194.1.
OpenDNS: 208.67.222.222; 208.67.220.220.
也可以在 resolv.conf 配置

vim /etc/resolv.conf 

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 198.153.192.1
nameserver 198.153.194.1
nameserver 208.67.222.222
nameserver 208.67.220.220
重启 
restart network.service  或者  service network restart

重启服务器
测试网络 ping www.baidu.com
如果能ping 通 就用 ifconfig 查看 IP
如果ifconfig 命令报错 需要安装net-tools

yum install net-tools

然后就可以在mac 控制台连服务器了 如果不行

设置防火墙 (22为端口)

firewall-cmd --zone=public --add-port=22/tcp --permanent

重启防火墙

 service firewalld restart 或者 /bin/systemctl restart firewalld.service

注:防火墙配置目录 /etc/firewalld/ 可以参考设置centos 防火墙

安装 wget

vim wget:yum install vim wget

下载 php :网站 https://www.php.net/downloads.php

wget https://www.php.net/distributions/php-7.3.8.tar.gz
tar -zxvf php-7.3.8.tar.gz

安装gcc gcc++ libxml2-devel :

yum install gcc gcc++ libxml2-devel

编译php

进入 php目录

cd php-7.3.8
./configure --prefix=/usr/local/php-7.3.8 --enable-fpm  
make
make install

注:1编译 PHP 时需要 --enable-fpm 配置选项来激活 FPM 支持。以下为 FPM 编译的具体配置参数(全部为可选参数):--with-fpm-user - 设置 FPM 运行的用户身份(默认 - nobody)--with-fpm-group - 设置 FPM 运行时的用户组(默认 - nobody)--with-fpm-systemd - 启用 systemd 集成 (默认 - no)--with-fpm-acl - 使用POSIX 访问控制列表 (默认 - no) 5.6.5版本起有效
2.prefix 安装路径

编译完成后 cd ~ 
创建测试例子 vim test.php

保存退出

/usr/local/php-7.3.8/bin/php test.php

安装 mysql 官网 https://dev.mysql.com/downloads/mysql/8.0.html

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17.tar.gz

tar -zxvf mysql-8.0.17.tar.gz

安装一些工具 这里一键检查安装 命令:

yum -y install wget vim git texinfo patch make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils perl-Data-Dumper boost boost-doc boost-devel

编译 mysql 注意 \

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1  \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_CONLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_BOOST=/root/mysql \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \

连按两次回车 如果报错 看下面的注释 很多坑
注:参考资料 Cmake编译安装MySQL完整版
如果cmake 版本版本过低 可以安装更高版本 Centos7安装高版本Cmake
如果需要gcc 5.3 CentOS7.X更新gcc到5.3.0 这个很慢
参考centos安装mysql 8
编译这里很多坑,缺啥补啥 -DWITH_BOOST=/root/mysql \ 这个是boost的路径
如果没有安装boost 或者版本较低 按提示添加自动下载配置

我安装的mysql-boost-8.0.16.tar.gz 解压后,boost目录有好几个层级,需要把最后一个boost文件夹拷贝到/root/mysql
注:我是把 mysql-8.0.16 解压到 /root/ 根目录下

mv /root/mysql-8.0.16/boost/boost_1_69_0/boost /root
rm -rf /root/mysql-8.0.16/boost
mv /root/boost /root/mysql-8.0.16
mv /root/mysql-8.0.16 /root/mysql

cmake 命令结束后

make
make install

修改配置,注释默认数据目录
mysql 数据库my.cnf配置详解
创建mysql用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown -Rf mysql:mysql /usr/local/mysql

执行初始化脚本:

/usr/local/mysql/bin/mysqld --initialize \

启动:

/usr/local/mysql/bin/mysqld_safe --user=mysql &

安装apache http://httpd.apache.org/

wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.39.tar.gz
tar -zxvf  httpd-2.4.39.tar.gz
cd  httpd-2.4.39
./configure --prefix=/usr/local/apache  

安装结果提示 configure: error: APR not found. Please read the documentation.

cd ..
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
tar -zxvf apr-1.4.5.tar.gz
tar -zxvf apr-util-1.3.12.tar.gz
mv apr-1.4.5 apr
mv apr-util-1.3.12 apr-util
mv apr apr-util httpd-2.4.39/srclib/

安装pcre

wget  https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz

tar -zxvf pcre-8.40.tar.gz

cd  pcre-8.40

./configure --prefix=/usr/local/pcre

make
make install
cd ~
cd httpd-2.4.39

./configure --prefix=/usr/local/apache -with-pcre=/usr/local/prce/bin/prce-config -with-included-apr

make
make install
cd /usr/local/apache/bin/

启动 apache

./apachectl -k start

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx. Set the 'ServerName' directive globally to suppress this message
参考 解决apache启动错误"httpd:Could not reliably determine..."

cd /usr/local/apache/conf

vim httpd.conf

添加 ServerName localhost:80


image.png

重启 apache

/usr/local/apache/bin/apachectl restart

开启80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
/bin/systemctl restart firewalld.service

测试apache 在浏览器输入服务器ip+端口

显示
image.png

安装成功

安装 nginx http://nginx.org/en/download.html
ls -alh | grep nginx 查看目录文件大小

wget http://nginx.org/download/nginx-1.16.0.tar.gz

tar -zxvf nginx-1.16.0.tar.gz

cd nginx-1.16.0

./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.40/

make
make install

cd /usr/local/nginx/

启动nginx 前先查看下apache

cd sbin/

ps aux | grep httpd
image.png

需要干掉 httpd

kill -9 16737 16835 16836 16837 17135
ps aux | grep httpd

image.png

启动nginx

./nginx
ps aux | grep nginx
image.png

切换到浏览器 输入 ip+端口


image.png

配置php

cd /usr/local/php-7.3.8/sbin/
./php-fpm

提示
[12-Aug-2019 15:23:54] ERROR: failed to open configuration file '/usr/local/php-7.3.8/etc/php-fpm.conf': No such file or directory (2)
[12-Aug-2019 15:23:54] ERROR: failed to load configuration file '/usr/local/php-7.3.8/etc/php-fpm.conf'
[12-Aug-2019 15:23:54] ERROR: FPM initialization failed

可以去php的etc文件夹下面找默认配置文件 然后重命名 然后重启动nginx

cd /usr/local/php-7.3.8/etc
mv php-fpm.conf.default php-fpm.conf
../sbin/php-fpm

提示
WARNING: Nothing matches the include pattern '/usr/local/php-7.3.8/etc/php-fpm.d/*.conf' from /usr/local/php-7.3.8/etc/php-fpm.conf at line 143.
[12-Aug-2019 15:30:54] ERROR: No pool defined. at least one pool section must be specified in config file
[12-Aug-2019 15:30:54] ERROR: failed to post process the configuration
[12-Aug-2019 15:30:54] ERROR: FPM initialization failed

143行 有问题
vim /usr/local/php-7.3.8/etc/php-fpm.conf
shift + :143 + 回车


image.png

进入 /usr/local/php-7.3.8/etc/php-fpm.d 查看conf文件 拷贝一份并且重新命名为 www.conf

cd  /usr/local/php-7.3.8/etc/php-fpm.d
cp www.conf.default www.conf

启动php-fpm
cd /usr/local/php-7.3.8/sbin
./php-fpm

查看
ps aux | grep php-fpm
image.png

配置nginx

cd /usr/local/nginx/

cd conf/

vim nginx.conf

粘贴 覆盖 
       location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include /usr/local/nginx/conf/fastgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

写一个测试例子test.php
网页输入 ip:端口/test.php

cd /usr/local/nginx/html
vim test.php

查看 配置文件php-fpm

cd /usr/local/php-7.3.8/etc
vim php-fpm.conf

查找 include 字段 
/include 回车

找到 include=/usr/local/php-7.3.8/etc/php-fpm.d/*.conf
/q
cd /usr/local/php-7.3.8/etc/php-fpm.d
ll
查看php-fpm 配置
vim www.conf

查找user字段 
/user 

查找max_children 
/max_children
n N 上下跳转查找相关字段

pm.max_children = 5 最大可启动子线程
pm.start_servers = 2 启动的时候 开启多少个子线程
static - a fixed number (pm.max_children) of child processes 如果是静态的 以pm.max_children 为准 始终都是这个最大线程数
dynamic the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children. 如果是动态的 影响的参数有
pm.max_children pm.start_servers pm.min_spare_servers pm.max_spare_servers

根据需要修改 这几个参数
退出
查看现在的 php-fpm 线程数

ps aux  | grep php-fpm

image.png
1624 为主进程  干掉并重启
kill -USR2 1624
image.png

�配置 nginx

cd /usr/local/nginx/conf
vim nginx.conf

worker_processes = 10; nginx 启动多少个子线程

重启 nginx

../sbin/nginx -s reload
ps aux | grep nginx
image.png

listen 80; 监听80端口
server_name localhost; 配置域名 ,如果访问localhost(域名) 就会进入 server 这个模块。
配置目录
location / {
root html;
index index.html index.htm;
}

你可能感兴趣的:(2019-08-10)